flake8-black is an MIT licensed Flake8 plugin designed to integrate Black, the uncompromising code formatter, into the Flake8 ecosystem. It allows developers to validate their Python code style against Black's rules as part of their linting process, typically used in continuous integration or pre-commit hooks. The current version is 0.4.0, and it generally follows Black's release cadence for compatibility updates.
pip install flake8-blackNo compatibility data collected yet for this library.
Install flake8-black along with flake8 and black. Create a .flake8 configuration file in your project root to align Flake8's settings with Black's, particularly the `max-line-length` to 88 and ignoring conflicting style checks like `E203` (whitespace before ':'), `W503` (line break before binary operator), and `E701` (multiple statements on one line, for empty classes). Then, simply run `flake8` as usual.
Add `extend-ignore = E203` to your `[flake8]` section in `.flake8`, `setup.cfg`, or `tox.ini`.
Ensure `W503` is not enabled in your `flake8` configuration. You may consider using `W504` (`line break after binary operator`) instead if you need a similar check that is compatible with Black. If Black produces empty classes as `class Foo: ...`, it can trigger `E701`. You might need to ignore `E701` as well.
Upgrade `flake8-black` to the latest version and ensure `black` is at version `19.3b0` or newer. It is recommended to pin `black`'s version in your project to avoid unexpected formatting changes from future `black` updates.
Duplicate `black`'s `include` and `exclude` patterns in your `flake8` configuration file (`.flake8`, `setup.cfg`, or `tox.ini`).
Ensure `flake8` configurations are in one of the supported dedicated `flake8` configuration files.
Run `black <file_or_directory>` to reformat the code. Avoid using `# noqa: BLK100` and instead use `black`'s native pragmas like `# fmt: off`, `# fmt: on`, or `# fmt: skip` to disable formatting for specific sections or lines if absolutely necessary.
Run `black .` in your project's root directory or `black your_file.py` on the specific file to automatically reformat your code to Black's style.
Configure Flake8 to ignore the E203 error by adding `extend-ignore = E203` to your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).
Align Flake8's line length with Black's by setting `max-line-length = 88` in your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).
Configure Flake8 to ignore the E701 error by adding `extend-ignore = E701` to your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).