Skip to content

flake8

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

flake8 documentation

flake8 - GitHub

Configuration in MegaLinter

Variable Description Default value
PYTHON_FLAKE8_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
PYTHON_FLAKE8_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
PYTHON_FLAKE8_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
PYTHON_FLAKE8_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
PYTHON_FLAKE8_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
list_of_files
PYTHON_FLAKE8_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".py"]
PYTHON_FLAKE8_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
PYTHON_FLAKE8_PRE_COMMANDS List of bash commands to run before the linter None
PYTHON_FLAKE8_POST_COMMANDS List of bash commands to run after the linter None
PYTHON_FLAKE8_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling PYTHON_FLAKE8 and its pre/post commands None
PYTHON_FLAKE8_CONFIG_FILE flake8 configuration file nameUse LINTER_DEFAULT to let the linter find it .flake8
PYTHON_FLAKE8_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
PYTHON_FLAKE8_DISABLE_ERRORS Run linter but consider errors as warnings false
PYTHON_FLAKE8_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
PYTHON_FLAKE8_CLI_EXECUTABLE Override CLI executable ['flake8']

IDE Integration

Use flake8 in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Atom linter-flake8 Visit Web Site
IDEA flake8-support
Visual Studio Code Native Support Visit Web Site

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 125 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 84 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 64 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .py

How the linting is performed

  • flake8 is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

flake8 myfile.py
flake8 --config .flake8 myfile.py

Help content

usage: flake8 [options] file file ...

positional arguments:
  filename

options:
  -h, --help            show this help message and exit
  -v, --verbose         Print more information about what is happening in
                        flake8. This option is repeatable and will increase
                        verbosity each time it is repeated.
  --output-file OUTPUT_FILE
                        Redirect report to a file.
  --append-config APPEND_CONFIG
                        Provide extra config files to parse in addition to the
                        files found by Flake8 by default. These files are the
                        last ones read and so they take the highest precedence
                        when multiple files provide the same option.
  --config CONFIG       Path to the config file that will be the authoritative
                        config source. This will cause Flake8 to ignore all
                        other configuration files.
  --isolated            Ignore all configuration files.
  --enable-extensions ENABLE_EXTENSIONS
                        Enable plugins and extensions that are otherwise
                        disabled by default
  --require-plugins REQUIRE_PLUGINS
                        Require specific plugins to be installed before
                        running
  --version             show program's version number and exit
  -q, --quiet           Report only file names, or nothing. This option is
                        repeatable.
  --color {auto,always,never}
                        Whether to use color in output. Defaults to `auto`.
  --count               Print total number of errors to standard output after
                        all other output.
  --exclude patterns    Comma-separated list of files or directories to
                        exclude. (Default: ['.svn', 'CVS', '.bzr', '.hg',
                        '.git', '__pycache__', '.tox', '.nox', '.eggs',
                        '*.egg'])
  --extend-exclude patterns
                        Comma-separated list of files or directories to add to
                        the list of excluded ones.
  --filename patterns   Only check for filenames matching the patterns in this
                        comma-separated list. (Default: ['*.py'])
  --stdin-display-name STDIN_DISPLAY_NAME
                        The name used when reporting errors from code passed
                        via stdin. This is useful for editors piping the file
                        contents to flake8. (Default: stdin)
  --format format       Format errors according to the chosen formatter
                        (default, pylint, quiet-filename, quiet-nothing) or a
                        format string containing %-style mapping keys (code,
                        col, path, row, text). For example,
                        ``--format=pylint`` or ``--format='%(path)s
                        %(code)s'``. (Default: default)
  --hang-closing        Hang closing bracket instead of matching indentation
                        of opening bracket's line.
  --ignore errors       Comma-separated list of error codes to ignore (or
                        skip). For example, ``--ignore=E4,E51,W234``.
                        (Default: E121,E123,E126,E226,E24,E704,W503,W504)
  --extend-ignore errors
                        Comma-separated list of error codes to add to the list
                        of ignored ones. For example, ``--extend-
                        ignore=E4,E51,W234``.
  --per-file-ignores PER_FILE_IGNORES
                        A pairing of filenames and violation codes that
                        defines which violations to ignore in a particular
                        file. The filenames can be specified in a manner
                        similar to the ``--exclude`` option and the violations
                        work similarly to the ``--ignore`` and ``--select``
                        options.
  --max-line-length n   Maximum allowed line length for the entirety of this
                        run. (Default: 79)
  --max-doc-length n    Maximum allowed doc line length for the entirety of
                        this run. (Default: None)
  --indent-size n       Number of spaces used for indentation (Default: 4)
  --select errors       Limit the reported error codes to codes prefix-matched
                        by this list. You usually do not need to specify this
                        option as the default includes all installed plugin
                        codes. For example, ``--select=E4,E51,W234``.
  --extend-select errors
                        Add additional error codes to the default
                        ``--select``. You usually do not need to specify this
                        option as the default includes all installed plugin
                        codes. For example, ``--extend-select=E4,E51,W234``.
  --disable-noqa        Disable the effect of "# noqa". This will report
                        errors on lines with "# noqa" at the end.
  --show-source         Show the source generate each error or warning.
  --no-show-source      Negate --show-source
  --statistics          Count errors.
  --exit-zero           Exit with status code "0" even if there are errors.
  -j JOBS, --jobs JOBS  Number of subprocesses to use to run checks in
                        parallel. This is ignored on Windows. The default,
                        "auto", will auto-detect the number of processors
                        available to use. (Default: auto)
  --tee                 Write to stdout and output-file.
  --benchmark           Print benchmark information about this run of Flake8
  --bug-report          Print information necessary when preparing a bug
                        report

mccabe:
  --max-complexity MAX_COMPLEXITY
                        McCabe complexity threshold

pyflakes:
  --builtins BUILTINS   define more built-ins, comma separated
  --doctests            also check syntax of the doctests

Installed plugins: mccabe: 0.7.0, pycodestyle: 2.12.0, pyflakes: 3.2.0

Installation on mega-linter Docker image

  • PIP packages (Python):