GithubHelp home page GithubHelp logo

orsinium-labs / flake8-ruler Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 0.0 174 KB

More powerful configs for flake8

License: MIT License

Python 100.00%
python python3 flake8 pyproject-toml linter flake8-extensions flake8-plugins

flake8-ruler's Introduction

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.

example of the command output

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

flake8-ruler's People

Contributors

orsinium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.