LinuxCommandLibrary

flake8

Tool to check the style and quality of Python code.

TLDR

Lint a file or directory recursively

$ flake8 [path/to/file_or_directory]
copy


Lint a file or directory recursively and show the line on which each error occurred
$ flake8 --show-source [path/to/file_or_directory]
copy


Lint a file or directory recursively and ignore a list of rules. (All available rules can be found at flake8rules.com)
$ flake8 --ignore [rule1,rule2] [path/to/file_or_directory]
copy


Lint a file or directory recursively but exclude files matching the given globs or substrings
$ flake8 --exclude [substring1,glob2] [path/to/file_or_directory]
copy

SYNOPSIS

flake8 [options] input ...

DESCRIPTION

flake8 is a command-line utility for enforcing style consistency across Python projects. By default it includes lint checks provided by the PyFlakes project, PEP-0008 inspired style checks provided by the PyCodeStyle project, and McCabe complexity checking provided by the McCabe project. It will also run third-party extensions if they are found and installed.

OPTIONS

--version

show program's version number and exit

-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.

-q, --quiet

report only file names, or nothing. This option is repeatable.

--count

print total number of errors and warnings to standard error and set the exit code to 1 if total is not empty.

--diff

report changes only within line number ranges in the unified diff provided on standard in by the user.

--exclude=patterns

comma-separated list of files or directories to exclude. (Default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg)

--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.

--hang-closing

hang closing bracket instead of matching indentation of opening bracket's line.

--ignore=errors

comma-separated list of errors and warnings to ignore (or skip). For example, --ignore=E4,E51,W234. (Default: E121,E123,E126,E226,E24,E704,W503,W504)

--max-line-length=n

maximum allowed line length for the entirety of this run. (Default: 79)

--select=errors

comma-separated list of errors and warnings to enable. For example, --select=E4,E51,W234. (Default: E,F,W,C90)

--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.

--statistics

count errors and warnings.

--enable-extensions=ENABLE_EXTENSIONS

enable plugins and extensions that are otherwise disabled by default

--exit-zero

exit with status code "0" even if there are errors.

--install-hook=INSTALL_HOOK

install a hook that is run prior to a commit for the supported version control system.

-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)

--output-file=OUTPUT_FILE

redirect report to a file.

--tee

write to stdout and output-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 found configuration files.

--benchmark

print benchmark information about this run of Flake8

--max-complexity=MAX_COMPLEXITY

McCabe complexity threshold

--bug-report

print information necessary when preparing a bug report

--builtins=BUILTINS

define more built-ins, comma separated

--doctests

check syntax of the doctests

--include-in-doctest=INCLUDE_IN_DOCTEST

run doctests only on these files

--exclude-from-doctest=EXCLUDE_FROM_DOCTEST

skip these files when running doctests

CONFIGURATION

The project options are read from the [flake8] section of the tox.ini file or the setup.cfg file located in any parent folder of the path(s) being processed. Allowed options are: exclude, filename, select, ignore, max-line-length, hang-closing, count, format, quiet, showpep8, show-source, statistics, verbose, max-complexity, builtins.

Copied to clipboard