ConfigurationΒΆ
Before going any further, make sure
that you are familiar with flake8
configuration process.
By default we encourage everyone to use setup.cfg
to store all
the configuration to all python
projects.
Sharable configurations
If you need to make sure that all projects share the same configuration
you might be interested in nitpick tool to lint your config.
We highly recommend to use nitpick
together
with wemake-python-styleguide
.
Configuring
Provides configuration options for wemake-python-styleguide
.
We do not like our linter to be highly configurable. Since, people may take the wrong path or make wrong decisions. We try to make all defaults as reasonable as possible.
However, you can currently adjust some complexity options. Why? Because we are not quite sure about the ideal values.
All options are configurable via flake8
CLI.
flake8 --max-returns=2 --max-arguments=4
Or you can provide options in setup.cfg
or similar supported files.
[flake8]
max-returns = 2
max-arguments = 4
We use setup.cfg
as a default way to provide configuration.
You can also show all options that flake8
supports by running:
flake8 --help
General options
min-name-length
- minimum number of chars to define a validvariable and module name, defaults to 2
max-name-length
- maximum number of chars to define a validvariable and module name, defaults to 45
i-control-code
- whether you control ones who use your code,more rules are enforced when you do control it, defaults to True
Complexity options
max-returns
- maximum allowed number ofreturn
statements in one function, defaults to 5
max-local-variables
- maximum allowed number of localvariables in one function, defaults to 5
max-expressions
- maximum allowed number of expressionsin one function, defaults to 9
max-arguments
- maximum allowed number of arguments in one function,defaults to 5
max-module-members
- maximum number of classes and functionsin a single module, defaults to 7
max-methods
- maximum number of methods in a single class,defaults to 7
max-line-complexity
- maximum line complexity measured in number ofast
nodes per line, defaults to 14
max-jones-score
- maximum Jones score for a module, which is equalto the median of all lines complexity sum, defaults to 12
max-imports
- maximum number of imports in a single module,defaults to 12
max-imported-names
- maximum number of imported namesin a single module, defaults to 50
max-base-classes
- maximum number of parent classes inside a classdefinition, defaults to 3
max-decorators
- maximum number of decorators for single functionor class definition, defaults to 5
max-string-usages
- maximum number of repeated string constantsin your modules, defaults to 5
max-awaits
- maximum allowed number ofawait
expressions in one function, defaults to 5
max-try-body-length
- maximum amount oftry
node body length,defaults to 1
max-module-expressions
- maximum number of expressionusages in a module, defaults to 7
max-function-expressions
- maximum number of expressionusages in a function or method, defaults to 4
max-asserts
- maximum number ofassert
statements in a function,default to 5
max-access-level
- maximum number of access level in an expression,defaults to 4
max-attributes
- maximum number of public instance attributes,defaults to 6
Plugins
Note
Remember to check the configuration with nitpick.
It is also important to configure different plugins that we ship with this module.
You can basically configure them as you wish,
including stylistic (like --quotes
from flake8-quotes
)
and important things (like --max-complexity
from mccabe
).
Our flake8.toml
file is available with the core settings for flake8
.
We also use flake8-isort
to style our imports.
You will need to update your configuration with the following lines:
Otherwise, your isort
will complain about your imports.
Our isort.toml
file is available with the core settings for isort
.
All recommended settings can be found in our styleguide.toml.
Ignoring violations
We know that people might not agree with 100% of our rules. But we still want to provide the best experience for all users.
So, you can disable some checks, that you are not ok with. Note: you might accidentally break the consistency of this project, when you disable some checks. Report these cases.
There are three ways to ignore some specific violations:
Inline ignore with
# noqa:
comment and comma separated violation codesCommand line argument
--ignore
with comma separated violation codesConfiguration line inside
setup.cfg
, example
You can ignore:
Whole
WPS
letters, this will completely turn off all our custom checksSome specific group (naming, complexity, consistency, best practices, etc) with
WPS
and the first number of this groupSome specific violation with the full violation code
Use per-file-ignores option, so it is possible to ignore violations on a per-file bases. It means, that you can have different set of violations ignored for different files.
Example:
# Inside `setup.cfg`:
[flake8]
per-file-ignores =
# There are multiple `assert`s in tests, we allow them:
tests/*.py: S101
Further reading
Read more about ignoring violations
in the official flake8
docs.