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.

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 valid

    variable and module name, defaults to 2

  • max-name-length - maximum number of chars to define a valid

    variable and module name, defaults to 45

  • nested-classes-whitelist - list of nested classes’ names we allow to use,

    defaults to (‘Meta’, ‘Params’, ‘Config’)

  • max-noqa-comments - maximum number of noqa allowed in a module,

    defaults to 10

  • allowed-domain-names - list of allowed domain names, defaults to

    ()

  • forbidden-domain-names - list of forbidden domain names, defaults to

    ()

  • allowed-module-metadata - list of allowed module metadata, defaults to

    ()

  • forbidden-module-metadata - list of forbidden module metadata, defaults to

    ()

  • forbidden-inline-ignore - list of codes of violations or

    class of violations that are forbidden to ignore inline, defaults to ()

  • exps-for-one-empty-line - number of expressions in

    function or method body for available empty line (without code) 2

  • known-enum-bases - list of additional enum-like base class names that

    should be treated as enums, defaults to ()

Complexity options

  • max-returns - maximum allowed number of return

    statements in one function, defaults to 5

  • max-local-variables - maximum allowed number of local

    variables in one function, defaults to 5

  • max-expressions - maximum allowed number of expressions

    in 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 functions

    in 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 of

    ast nodes per line, defaults to 14

  • max-jones-score - maximum Jones score for a module, which is equal

    to 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 names

    in a single module, defaults to 50

  • max-base-classes - maximum number of parent classes inside a class

    definition, defaults to 3

  • max-decorators - maximum number of decorators for single function

    or class definition, defaults to 5

  • max-string-usages - maximum number of repeated String constants

    in your modules, defaults to 3

  • max-awaits - maximum allowed number of await

    expressions in one function, defaults to 5

  • max-try-body-length - maximum amount of try node body length,

    defaults to 1

  • max-module-expressions - maximum number of expression

    usages in a module, defaults to 7

  • max-function-expressions - maximum number of expression

    usages in a function or method, defaults to 4

  • max-asserts - maximum number of assert 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

  • max-raises - maximum number of raises in a function,

    defaults to 3

  • max-except-exceptions - maximum number of exceptions in except,

    defaults to 3

  • max-cognitive-score - maximum amount of cognitive complexity

    per function, defaults to 12

  • max-cognitive-average - maximum amount of cognitive complexity

    per module, defaults to 8 (‘Meta’, ‘Params’, ‘Config’)

  • max-call-level - maximum number of call chains, defaults to

    3

  • max-annotation-complexity - maximum number of nested annotations,

    defaults to 3

  • max-import-from-members - maximum number of names that can be imported

    from module, defaults to 8

  • max-tuple-unpack-length - maximum number of variables in tuple unpacking,

    defaults to 4

  • max-type-params - maximum number of PEP695 type parameters,

    defaults to 6

  • max-match-subjects - maximum number of subjects in a match statement,

    defaults to 7

  • max-match-cases - maximum number of cases in a match block of code,

    defaults to 7

  • max-lines-in-finally - maximum amount of finally block body length.

    Lines equal to statements. defaults to 2

  • max-conditions - Maximum number of conditions in a single boolop

    expression. defaults to 4

Formatter options

  • show-violation-links - whether to show violation shortlinks in the

    formatter output False

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:

  1. Inline ignore with # noqa: comment and comma separated violation codes

  2. Command line argument --ignore with comma separated violation codes

  3. Configuration line inside setup.cfg, example

You can ignore:

  1. Whole WPS letters, this will completely turn off all our custom checks

  2. Some specific group (naming, complexity, consistency, best practices, etc) with WPS and the first number of this group

  3. Some 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.