Flake8
Flake8 is a modular source code checker that wraps PyFlakes, pycodestyle, and Ned Batchelder's McCabe script. It runs all these tools with a single command, displaying a merged output of warnings. As of version 7.3.0, it is actively maintained with releases as necessary, often driven by bug fixes and new features.
Warnings
- breaking Flake8 7.0.0 removed the `--include-in-doctest` and `--exclude-from-doctest` options.
- breaking Flake8 6.0.0 removed the `--diff` option. It also became stricter, producing errors for invalid codes specified in configuration files or if the file specified in `--extend-config` does not exist. Additionally, Python 3.8.1 or newer is now required.
- breaking Major releases (e.g., 3.0, 4.0, 5.0, 6.0, 7.0) historically include large-scale refactoring, 'subtly breaking CLI changes,' and breaking changes to its plugin interface. Always review release notes for new major versions.
- gotcha Flake8's ability to correctly parse Python code is dependent on the Python version it's installed and run with. If you are checking code written with newer Python language features (e.g., Python 3.10's structural pattern matching), Flake8 needs to be installed on a Python 3.10 interpreter to understand those features.
- gotcha Flake8 options can be specified on the command-line, or in configuration files (`.flake8`, `setup.cfg`, `tox.ini`). Command-line options always take precedence over configuration file settings. This can lead to unexpected behavior if not understood.
- gotcha Using `# noqa` comments to ignore errors on a line or file (`# flake8: noqa`) can be convenient but may hide legitimate bugs or style violations, degrading code quality over time if overused.
Install
-
pip install flake8
Quickstart
flake8 .