cytopia/file-lint

By cytopia

Updated almost 3 years ago

Alpine-based image to perform generic checks on your code to improve consistency within your repo.

Image
2

500K+

cytopia/file-lint repository overview

Docker image for file-lint

Tag License

lint build nightly

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

:whale: Available Docker image versions

Docker

Rolling releaess

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

nightly

Docker TagGit Reffile-lintFlavourAvailable Architectures
latestmasterlatestdefaultamd64, i386, arm64, arm/v7, arm/v6
alpinemasterlatestAlpineamd64, 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 TagGit Reffile-lintFlavourAvailable Architectures
latest-<tag>tag: <tag>latestdefaultamd64, i386, arm64, arm/v7, arm/v6
alpine-latest-<tag>tag: <tag>latestAlpineamd64, i386, arm64, arm/v7, arm/v6

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

:star: 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

:wrench: Tools

TypeToolFixableDescription
Filefile-crScan files and check if they contain CR (Carriage Return only).
Filefile-crlfScan files and check if they contain CRLF (Windows Line Feeds).
Filefile-emptyScan files and check if they are empty (0 bytes).
Filefile-nullbyteScan files and check if they contain a null-byte character (\x00).
Filefile-trailing-newlineScan files and check if they contain a trailing newline.
Filefile-trailing-single-newlineScan files and check if they contain exactly one trailing newline.
Filefile-trailing-spaceScan files and check if they contain trailing whitespaces.
Filefile-utf8Scan files and check if they have a non UTF-8 encoding.
Filefile-utf8-bomScan files and check if they contain BOM (Byte Order Mark): U+FEFF.
Gitgit-conflictsScan files and check if they contain git conflicts.

:open_file_folder: Docker mounts

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

:computer: 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
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:

GitHubDockerHubTypeDescription
awesome-ciaci-hub-imgBasicTools for git, file and static source code analysis
file-lintflint-hub-imgBasicBaisc source code analysis
linkchecklinkcheck-hub-imgBasicSearch for URLs in files and validate their HTTP status code
ansibleansible-hub-imgAnsibleMultiple versions and flavours of Ansible
ansible-lintalint-hub-imgAnsibleLint Ansible
gofmtgfmt-hub-imgGoFormat Go source code [1]
goimportsgimp-hub-imgGoFormat Go source code [1]
golintglint-hub-imgGoLint Go code
eslintelint-hub-imgJavascriptLint Javascript code
jsonlintjlint-hub-imgJSONLint JSON files [1]
kubevalkubeval-hub-imgK8sLint Kubernetes files
checkmakecm-hub-imgMakeLint Makefiles
phpcbfpcbf-hub-imgPHPPHP Code Beautifier and Fixer
phpcspcs-hub-imgPHPPHP Code Sniffer
phplintplint-hub-imgPHPPHP Code Linter [1]
php-cs-fixerpcsf-hub-imgPHPPHP Coding Standards Fixer
banditbandit-hub-imgPythonA security linter from PyCQA
blackblack-hub-imgPythonThe uncompromising Python code formatter
mypymypy-hub-imgPythonStatic source code analysis
pycodestylepycs-hub-imgPythonPython style guide checker
pydocstylepyds-hub-imgPythonPython docstyle checker
pylintpylint-hub-imgPythonPython source code, bug and quality checker
terraform-docstfdocs-hub-imgTerraformTerraform doc generator (TF 0.12 ready) [1]
terragrunttg-hub-imgTerraformTerragrunt and Terraform
terragrunt-fmttgfmt-hub-imgTerraformterraform fmt for Terragrunt files [1]
yamlfmtyfmt-hub-imgYamlFormat Yaml files [1]
yamllintylint-hub-imgYamlLint 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.

:page_facing_up: License

MIT License

Copyright (c) 2019 cytopia

Tag summary

Content type

Image

Digest

sha256:c3a4de2e3

Size

4.8 MB

Last updated

almost 3 years ago

docker pull cytopia/file-lint