Flake8 Python linter
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
flake8flake8 <file.py>
flake8 --show-source
flake8 --select=E,F
flake8 --extend-ignore=<code>
flake8 --max-line-length=100
flake8 --statistics -qq
flake8 --version
Concepts
- Python files found by path
- Plugins E W F C90 + extras
- select / ignore config + CLI + noqa
- Output exit 1 if any
Run
flake8flake8 <path> ...
flake8 -flake8 --stdin-display-name <name> -
flake8 --version
flake8 --countflake8 -qflake8 -qqflake8 --exit-zero
flake8 -j <n>
flake8 --color never
Output
flake8 --show-source
flake8 --statistics
flake8 --format=pylint
flake8 --format='%(path)s:%(row)d %(code)s'
flake8 --output-file <file>
flake8 --tee --output-file <file>
flake8 --benchmark
flake8 --bug-report
Select and ignore
flake8 --select=<codes>
flake8 --extend-select=<codes>
flake8 --ignore=<codes>
flake8 --extend-ignore=<codes>
flake8
--per-file-ignores='<glob>:<codes>'
flake8 --disable-noqa
flake8 --max-complexity=<n>
flake8 --max-line-length=<n>
flake8 --max-doc-length=<n>
flake8 --indent-size=<n>
flake8 --hang-closing
flake8 --doctests
flake8 --builtins=<names>
Files
flake8 --exclude=<patterns>
flake8 --extend-exclude=<patterns>
flake8 --filename=<patterns>
git diff --name-only -- '*.py' | xargs flake8
Inline control
# noqa# noqa: <code>[, <code>]
# flake8: noqaConfig
flake8 --config <file>
flake8 --append-config <file>
flake8 --isolated
flake8 --require-plugins=<names>
flake8 --enable-extensions=<codes>
flake8 -vCommon codes
| Code | Meaning |
|---|---|
E501 |
line too long |
E302 |
expected 2 blank lines |
E231 |
missing whitespace after ',' |
E203 |
whitespace before ':' |
W291 |
trailing whitespace |
W605 |
invalid escape sequence |
F401 |
imported but unused |
F841 |
local variable assigned, never used |
F821 |
undefined name |
E722 |
bare except |
E741 |
ambiguous variable name |
C901 |
function too complex |
| Prefix | Source |
|---|---|
E1-E7 |
pycodestyle errors |
W |
pycodestyle warnings |
F |
pyflakes |
C90 |
mccabe |
Recipes
[flake8]max-line-length = 100extend-ignore = E203per-file-ignores = __init__.py: F401 tests/*: S101exclude = .git,build,.venv
# Black-compatible settings[flake8]max-line-length = 88extend-ignore = E203,E701
flake8 --count --select=E9,F63,F7,F82 --show-source --statisticsflake8 --count --exit-zero --max-complexity=10 --statistics
# .pre-commit-config.yamlrepos: - repo: https://github.com/PyCQA/flake8 rev: 7.4.1 hooks: - id: flake8



