Skip to content

Alpine-based Docker image to perform generic file checks on your source code in order to improve consistency within your repository (e.g. for easy usage in CI).

License

Notifications You must be signed in to change notification settings

cytopia/docker-file-lint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Docker image for file-lint

Tag License

lint build nightly

All #awesome-ci Docker images

ansible-lint β€’ ansible β€’ awesome-ci β€’ bandit β€’ black β€’ checkmake β€’ eslint β€’ file-lint β€’ gofmt β€’ goimports β€’ golint β€’ jsonlint β€’ kubeval β€’ linkcheck β€’ mypy β€’ php-cs-fixer β€’ phpcbf β€’ phpcs β€’ phplint β€’ pycodestyle β€’ pydocstyle β€’ pylint β€’ terraform-docs β€’ terragrunt-fmt β€’ terragrunt β€’ yamlfmt β€’ yamllint

View Dockerfiles on GitHub.

Available Architectures: amd64, i386, arm64, arm/v7, arm/v6

Tiny Alpine-based Docker image for the very basics of CI against your code files based one awesome-ci[1].

[1] Original project: https://github.com/topics/awesome-ci

🐳 Available Docker image versions

Docker

Rolling releaess

The following Docker image tags are rolling releases and are built and updated every night.

nightly

Docker Tag Git Ref file-lint Flavour Available Architectures
latest master latest default amd64, i386, arm64, arm/v7, arm/v6
alpine master latest Alpine amd64, i386, arm64, arm/v7, arm/v6

Point in time releases

The following Docker image tags are built once and can be used for reproducible builds. Its version never changes so you will have to update tags in your pipelines from time to time in order to stay up-to-date.

build

Docker Tag Git Ref file-lint Flavour Available Architectures
latest-<tag> tag: <tag> latest default amd64, i386, arm64, arm/v7, arm/v6
alpine-latest-<tag> tag: <tag> latest Alpine amd64, i386, arm64, arm/v7, arm/v6

Where <tag> refers to the chosen git tag from this repository.

⭐ Features

  • dry run (which shows all piped unix command voodoo for learning)
  • project based configuration file (awesome-ci.conf)
  • check for empty files
  • check for files with carriage returns (\r)
  • check for files with windows newlines (\r\n)
  • check for files with nullbyte characters (\x00)
  • check for trailing newlines at eof (exactly one or multiple)
  • check for trailing white space
  • ensure files are utf8 encoded
  • ensure files do not contain utf8 bom (byte order mark: U+FEFF)
  • allows for automatic fixing (most commands)
  • allows for find-grained control
    • check files by specific extension(s) only
    • check files by specific shebang only
    • check binary or text-files only

πŸ”§ Tools

Type Tool Fixable Description
File file-cr βœ“ Scan files and check if they contain CR (Carriage Return only).
File file-crlf βœ“ Scan files and check if they contain CRLF (Windows Line Feeds).
File file-empty Scan files and check if they are empty (0 bytes).
File file-nullbyte βœ“ Scan files and check if they contain a null-byte character (\x00).
File file-trailing-newline βœ“ Scan files and check if they contain a trailing newline.
File file-trailing-single-newline βœ“ Scan files and check if they contain exactly one trailing newline.
File file-trailing-space βœ“ Scan files and check if they contain trailing whitespaces.
File file-utf8 βœ“ Scan files and check if they have a non UTF-8 encoding.
File file-utf8-bom βœ“ Scan files and check if they contain BOM (Byte Order Mark): U+FEFF.
Git git-conflicts Scan files and check if they contain git conflicts.

Tools extracted from https://github.com/cytopia/awesome-ci

πŸ“‚ Docker mounts

The working directory inside the Docker container is /data/ and should be mounted locally.

πŸ’» Usage

General

$ docker run --rm -v $(pwd):/data cytopia/file-lint

################################################################################
#                              cytopia/file-lint                               #
#                                 (awesome-ci)                                 #
################################################################################
#                                                                              #
#                                                                              #
# Usage:                                                                       #
# -----------------------------------------------------------------------------#
# docker run --rm cytopia/file-lint --help                                     #
# docker run --rm cytopia/file-lint <tool> --help                              #
# docker run --rm cytopia/file-lint <tool> --info                              #
# docker run --rm cytopia/file-lint <tool> --version                           #
#                                                                              #
#                                                                              #
# Available tools:                                                             #
# -----------------------------------------------------------------------------#
# file-empty                    Scans if files are empty                       #
# file-cr                       Scans if files contain carriage returns (\r)   #
# file-crlf                     Scans if files contain win line feeds (\r\n)   #
# file-nullbyte                 Scans if files contain nullbyte chars (\x00)   #
# file-trailing-newline         Scans if files contain trailing newline(s)     #
# file-trailing-single-newline  Scans if files contain single trailing newline #
# file-trailing-space           Scans if files contain trailing whitespace     #
# file-utf8                     Scans if files are utf8 encoded                #
# file-utf8-bom                 Scans if files contain byte order mark         #
# git-conflicts                 Scans if files contain git conflicts           #
#                                                                              #
#                                                                              #
# Example:                                                                     #
# -----------------------------------------------------------------------------#
# docker run --rm -v $(pwd):/data cytopia/file-lint \                          #
#     lf-crlf --ignore ".git/,.github/" --path .                               #
#                                                                              #
################################################################################

Tool usage

The following help screen is taken from file-crlf. All other tools have the exact same functionality.

$ docker run --rm cytopia/file-lint file-crlf --help

Usage: file-crlf [--text] [--size] [--shebang <ARG>] [--extension "tpl,htm,html,php,..."] [--ignore "dir1,dir2"] [--config "conf"] [--confpre "FILE_CRLF_"] [--fix] [--verbose] [--debug] [--dry] [--list] --path <DIR>
       file-crlf --info
       file-crlf --help
       file-crlf --version

Scans recursively for files containing CRLF (Windows Line Feeds).
Will return 1 on occurance, otherwise 0.

Required arguments:

  --path <ARG>       Specify directory where to scan.


Optional run arguments:
  --fix              Fixable :-)
                     Fix the problems for the specified files.
                     Note, all other options below also apply

  --text             Limit search to text files only (non-binary).
                     Can be narrowed further with '--extension'

  --size             Limit search to files which are not empty (bigger than 0 bytes).

  --shebang <ARG>    Only find files (shell scripts) with this specific shebang.
                     It is useful to combine this with --text and --size for faster searches.
                     Use with --dry to see how this search command is generated.
                     Example:
                         --shebang bash
                         --shebang php
                         --shebang sh

  --extension <ARG>  Only find files matching those extensions.
                     Comma separated list of file extensions.
                     Only find files matching those extensions.
                     Defaults to all files if not specified or empty.
                     Example:
                         --extension "html,php,inc"
                         --extension php

  --ignore <ARG>     Comma separated list of ignore paths.
                     Directories must be specified from the starting location of --path.
                     Example:
                          ignore 'foor/bar' folder inside '/var/www' path:
                         --path /var/www --ignore foo/bar

  --config <ARG>     Load configuration file.
                     File must contain the following directives:
                         FILE_CRLF_EXTENSION="" # comma separated
                         FILE_CRLF_IGNORE=""    # comma separated
                         FILE_CRLF_TEXT=0|1     # 0 or 1
                     Note that cmd arguments take precedence over
                     config file settings.

  --confpre <ARG>    Set custom configuration directive prefix.
                     Current default ist: 'FILE_CRLF_'.
                     This is useful, when you want to define different defaults
                     per check via configuration file.

  --verbose          Be verbose and print commands and files being checked.


  --debug            Print system messages.


Optional training arguments:
  --dry              Don't do anything, just display the commands.

  --list             Instead of searching inside the files, just display the filenames
                     that would be found by --path, --extension and --ignore


System arguments:
  --info             Show versions of required commands (useful for bugreports).
  --help             Show help screen.
  --version          Show version information.


file-crlf is part of the awesome-ci collection.
https://github.com/cytopia/awesome-ci

Configuration file

You can also add a configuration file named awesome-ci.conf to your project to configure it to your likings.

#
# Awesome-ci configuration file
#
# Each tool will have its own config section
# which all behave in the same way:
#
#
# 1. File extensions
# ------------------
# Comma separated list of file extensions
# to narrow down the files to check.
#     <TOOL_NAME>_EXTENSION=""
#     <TOOL_NAME>_EXTENSION="tpl,html"
#
# 2. Ignored paths
# ----------------
# Comma separated list of file paths
# to narrow down the files to check.
# Note that those paths must start at the
# path where --path starts.
#     <TOOL_NAME>_IGNORE=""
#     <TOOL_NAME>_IGNORE="tmp/log,tmp/run"
#
# 3. Text files
# -------------
# 0 or 1 to specify whether to work on text files
# only.
#     <TOOL_NAME>_TEXT=0
#     <TOOL_NAME>_TEXT=1




#
# File checkers
#
# file-cr
FILE_CR_EXTENSION=""
FILE_CR_IGNORE=".git,*.svn"
FILE_CR_TEXT=1
FILE_CR_SIZE=1

# file-crlf
FILE_CRLF_EXTENSION=""
FILE_CRLF_IGNORE=".git,*.svn"
FILE_CRLF_TEXT=1
FILE_CRLF_SIZE=1

# file-empty
FILE_EMPTY_EXTENSION=""
FILE_EMPTY_IGNORE=".git,*.svn"
FILE_EMPTY_TEXT=0
FILE_EMPTY_SIZE=0

# file-nullbyte
FILE_NULLBYTE_EXTENSION=""
FILE_NULLBYTE_IGNORE=".git,*.svn,*.pyc"
FILE_NULLBYTE_TEXT=1
FILE_NULLBYTE_SIZE=1

# file-trailing-newline
FILE_TRAILING_NEWLINE_EXTENSION=""
FILE_TRAILING_NEWLINE_IGNORE=".git,*.svn"
FILE_TRAILING_NEWLINE_TEXT=1
FILE_TRAILING_NEWLINE_SIZE=1

# file-trailing-single-newline
FILE_TRAILING_SINGLE_NEWLINE_EXTENSION=""
FILE_TRAILING_SINGLE_NEWLINE_IGNORE=".git,*.svn"
FILE_TRAILING_SINGLE_NEWLINE_TEXT=1
FILE_TRAILING_SINGLE_NEWLINE_SIZE=1

# file-trailing-space
FILE_TRAILING_SPACE_EXTENSION=""
FILE_TRAILING_SPACE_IGNORE=".git,*.svn"
FILE_TRAILING_SPACE_TEXT=1
FILE_TRAILING_SPACE_SIZE=1

# file-utf8
FILE_UTF8_EXTENSION=""
FILE_UTF8_IGNORE=".git,*.svn"
FILE_UTF8_TEXT=1
FILE_UTF8_SIZE=1

# file-utf8-bom
FILE_UTF8_BOM_EXTENSION=""
FILE_UTF8_BOM_IGNORE=".git,*.svn"
FILE_UTF8_BOM_TEXT=1
FILE_UTF8_BOM_SIZE=1

# git-conflicts
GIT_CONFLICTS_EXTENSION=""
GIT_CONFLICTS_IGNORE=".git,*.svn"
GIT_CONFLICTS_TEXT=1
GIT_CONFLICTS_SIZE=1

Example Makefile

ifneq (,)
.error This Makefile requires GNU Make.
endif

.PHONY: lint _lint-cr _lint-crlf _lint-trailing-single-newline _lint-trailing-space _lint-utf8 _lint-utf8-bom _lint-git-conflicts

FL_VERSION      = latest
FL_IGNORE_PATHS = .git/,.github/

lint:
	@$(MAKE) --no-print-directory _lint-cr
	@$(MAKE) --no-print-directory _lint-crlf
	@$(MAKE) --no-print-directory _lint-trailing-single-newline
	@$(MAKE) --no-print-directory _lint-trailing-space
	@$(MAKE) --no-print-directory _lint-utf8
	@$(MAKE) --no-print-directory _lint-utf8-bom
    @$(MAKE) --no-print-directory _lint-git-conflicts

_lint-cr:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-crlf:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-trailing-single-newline:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-trailing-single-newline --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-trailing-space:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-trailing-space --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-utf8:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-utf8-bom:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-utf8-bom --text --ignore '$(FL_IGNORE_PATHS)' --path .

_lint-git-conflicts:
	@docker run --rm -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) git-conflicts --text --ignore '$(FL_IGNORE_PATHS)' --path .

πŸ”„ Related #awesome-ci projects

Docker images

Save yourself from installing lot's of dependencies and pick a dockerized version of your favourite linter below for reproducible local or remote CI tests:

GitHub DockerHub Type Description
awesome-ci aci-hub-img Basic Tools for git, file and static source code analysis
file-lint flint-hub-img Basic Baisc source code analysis
linkcheck linkcheck-hub-img Basic Search for URLs in files and validate their HTTP status code
ansible ansible-hub-img Ansible Multiple versions and flavours of Ansible
ansible-lint alint-hub-img Ansible Lint Ansible
gofmt gfmt-hub-img Go Format Go source code [1]
goimports gimp-hub-img Go Format Go source code [1]
golint glint-hub-img Go Lint Go code
eslint elint-hub-img Javascript Lint Javascript code
jsonlint jlint-hub-img JSON Lint JSON files [1]
kubeval kubeval-hub-img K8s Lint Kubernetes files
checkmake cm-hub-img Make Lint Makefiles
phpcbf pcbf-hub-img PHP PHP Code Beautifier and Fixer
phpcs pcs-hub-img PHP PHP Code Sniffer
phplint plint-hub-img PHP PHP Code Linter [1]
php-cs-fixer pcsf-hub-img PHP PHP Coding Standards Fixer
bandit bandit-hub-img Python A security linter from PyCQA
black black-hub-img Python The uncompromising Python code formatter
mypy mypy-hub-img Python Static source code analysis
pycodestyle pycs-hub-img Python Python style guide checker
pydocstyle pyds-hub-img Python Python docstyle checker
pylint pylint-hub-img Python Python source code, bug and quality checker
terraform-docs tfdocs-hub-img Terraform Terraform doc generator (TF 0.12 ready) [1]
terragrunt tg-hub-img Terraform Terragrunt and Terraform
terragrunt-fmt tgfmt-hub-img Terraform terraform fmt for Terragrunt files [1]
yamlfmt yfmt-hub-img Yaml Format Yaml files [1]
yamllint ylint-hub-img Yaml Lint Yaml files

[1] Uses a shell wrapper to add enhanced functionality not available by original project.

Makefiles

Visit cytopia/makefiles for dependency-less, seamless project integration and minimum required best-practice code linting for CI. The provided Makefiles will only require GNU Make and Docker itself removing the need to install anything else.

πŸ“„ License

MIT License

Copyright (c) 2019 cytopia