Skip to main content

More powerful configs for flake8.

Project description

flake8-ruler

CLI tool to generate a flake8 (setup.cfg) from a nicer, modern, more powerful, flakehell-inspired (and 100% compatible) config (pyproject.toml).

Features:

  • TOML: type-safe, syntax-highlighted, well standartized config format.
  • Powerful per-plugin codes configuration.
  • Glob patterns.
  • Extending and merging multiple configs, shared configurations.
  • Remote configs.
  • Predefined configs for bugs, security, styleguides.

Getting started

Install:

python3 -m pip install flake8-ruler

Create pyproject.toml:

# you can add in this section any options supported by flake8
[tool.flake8_ruler]
max_line_length = 90

[tool.flake8_ruler.plugins]
# include everything in pyflakes except F401
pyflakes = ["+*", "-F401"]
# enable only codes from S100 to S199
flake8-bandit = ["-*", "+S1??"]
# enable everything that starts from `flake8-`
"flake8-*" = ["+*"]
# explicitly disable a plugin
flake8-docstrings = ["-*"]

Convert pyproject.toml into setup.cfg:

python3 -m flake8_ruler

Done! Now, you can just run flake8 and it will automatically use the newly generated config.

Plugins

In pyproject.toml you can specify [tool.flake8_ruler.plugins] table. It's a key-value of flake8 plugins and associated to them rules.

Key can be exact plugin name or wildcard template. For example "flake8-commas" or "flake8-*". The tool will choose the longest match for every plugin if possible. In the previous example, flake8-commas will match to the first pattern, flake8-bandit and flake8-bugbear to the second, and pycodestyle will not match to any pattern.

Value is a list of templates for error codes for this plugin. First symbol in every template must be + (include) or - (exclude). The latest matched pattern wins. For example, ["+*", "-F*", "-E30?", "-E401"] means "Include everything except all checks that starts with F, check from E301 to E310, and E401".

Codes

An error code is added into the generated setup.cfg only if the following conditions match:

  1. The plugin is installed in the same environment as flake8-ruler.
  2. The code is detected by flake8-codes. If not, please, contribute.
  3. The code is enabled in [tool.flake8_ruler.plugins].

Use flake8-codes to find out the supported error codes for a plugin:

python3 -m pip install flake8-codes
python3 -m flake8_codes

Inheritance

Option base allows to specify base config from which you want to inherit this one. It can be path to local config or remote URL. You can specify one path or list of paths as well. For example:

base = [
    "https://raw.githubusercontent.com/orsinium-labs/flake8-ruler/master/pyproject.toml",
    ".flake8-ruler.toml",
]
max_line_length = 90

In this example, flake8-ruler will read remote config, local config (.flake8-ruler.toml), and then current config. So, even if max_line_length is specified in some of base configs, it will be overwritten by max_line_length = 90 from the current config.

You can find some predefined configs in ./configs/ directory.

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_ruler-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

flake8_ruler-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file flake8_ruler-0.1.0.tar.gz.

File metadata

  • Download URL: flake8_ruler-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for flake8_ruler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3cd0698ffc16eb61a4bef5c3c96277032170ce71d67368297c23ff1b0b80728
MD5 4c76883395b187f4df39591b25bc5212
BLAKE2b-256 2cb4052ef23e560df60f45a917de01e69c4c3ee2aed7728e9f8885c2022c6679

See more details on using hashes here.

File details

Details for the file flake8_ruler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_ruler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcff2ed873dcb5a35c661c2fb1068ceca0ef75b7d5b5d3cf4073db2ad6c43263
MD5 ae33a3613d5128e528378019710d24b1
BLAKE2b-256 6d950ce49a81f9363025c2f03827304f03c5605d506af49eca9c56a0e9bee866

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page