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.
-
class
Configuration
[source]¶ Bases:
object
Provides configuration options for our plugin.
We do not like our linter to be 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 yet. We are still researching them, and providing a way for developers to help us out is a good thing at the moment.
Options for general checks:
min-name-length
- minimum number of chars to define a valid variable and module name, defaults to 2max-name-length
- maximum number of chars to define a valid variable and module name, defaults to 45i-control-code
- whether you control ones who use your code, more rules are enforced when you do control it, defaults to True
Options for complexity related checks:
max-returns
- maximum allowed number ofreturn
statements in one function, defaults to 5max-local-variables
- maximum allowed number of local variables in one function, defaults to 5max-expressions
- maximum allowed number of expressions in one function, defaults to 9max-arguments
- maximum allowed number of arguments in one function, defaults to 5max-module-members
- maximum number of classes and functions in a single module, defaults to 7max-methods
- maximum number of methods in a single class, defaults to 7max-line-complexity
- maximum line complexity measured in number ofast
nodes per line, defaults to 14max-jones-score
- maximum Jones score for a module, which is equal to the median of all lines complexity sum, defaults to 12max-imports
- maximum number of imports in a single module, defaults to 12max-imported-names
- maximum number of imported names in a single module, defaults to 50max-base-classes
- maximum number of parent classes inside a class definition, defaults to 3max-decorators
- maximum number of decorators for single function or class definition, defaults to 5max-string-usages
- maximum number of repeated string constants in your modules, defaults to 5max-awaits
- maximum allowed number ofawait
expressions in one function, defaults to 5max-try-body-length
- maximum amount oftry
node body length, defaults to 1max-module-expressions
- maximum number of expression usages in a module, defaults to 7max-function-expressions
- maximum number of expression usages in a function or method, defaults to 4max-asserts
- maximum number ofassert
statements in a function, default to 5max-access-level
- maximum number of access level in an expression, defaults to 4max-attributes
- maximum number of public instance attributes, defaults to 6
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
Defaults
Constants with default values for plugin’s configuration.
We try to stick to “the magical 7 ± 2 number”. https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two
What does it mean? It means that we choose these values based on our mind capacity. And it is really hard to keep in mind more that 9 objects at the same time.
These values can be changed in the setup.cfg
file on a per-project bases,
if you find them too strict or too permissive.
-
MIN_NAME_LENGTH
= 2¶ Minimum variable’s name length.
-
MAX_NAME_LENGTH
= 45¶ Maximum variable and module name length:
-
I_CONTROL_CODE
= True¶ Whether you control ones who use your code.
-
MAX_RETURNS
= 5¶ Maximum number of return statements allowed in a single function.
-
MAX_LOCAL_VARIABLES
= 5¶ Maximum number of local variables in a function.
-
MAX_EXPRESSIONS
= 9¶ Maximum number of expressions in a single function.
-
MAX_ARGUMENTS
= 5¶ Maximum number of arguments for functions or methods.
-
MAX_MODULE_MEMBERS
= 7¶ Maximum number of classes and functions in a single module.
-
MAX_METHODS
= 7¶ Maximum number of methods in a single class.
-
MAX_LINE_COMPLEXITY
= 14¶ Maximum line complexity.
-
MAX_JONES_SCORE
= 12¶ Maximum median module Jones complexity.
-
MAX_IMPORTS
= 12¶ Maximum number of imports in a single module.
-
MAX_IMPORTED_NAMES
= 50¶ Maximum number of imported names in a single module.
-
MAX_BASE_CLASSES
= 3¶ Maximum number of base classes.
-
MAX_DECORATORS
= 5¶ Maximum number of decorators.
-
MAX_STRING_USAGES
= 3¶ Maximum number of same string usage in code.
-
MAX_AWAITS
= 5¶ Maximum number of
await
expressions for functions or methods.
-
MAX_TRY_BODY_LENGTH
= 1¶ Maximum amount of
try
node body length.
-
MAX_MODULE_EXPRESSIONS
= 7¶ Maximum amount of same expressions per module.
-
MAX_FUNCTION_EXPRESSIONS
= 4¶ Maximum amount of same expressions per function.
-
MAX_ASSERTS
= 5¶ Maximum number of
assert
statements in a function.
-
MAX_ACCESS_LEVEL
= 4¶ Maximum number of access level in an expression.
-
MAX_ATTRIBUTES
= 6¶ Maximum number of public attributes in a single class.
Plugins
It is also important to configure different plugins that we ship with this module.
# Inside `setup.cfg`:
[flake8]
max-complexity = 6
max-line-length = 80
enable-extensions = G
Place this configuration inside setup.cfg
file.
Our repository contains
the fully working example.
We also use flake8-isort
to style our imports.
You will need to update your configuration with the following lines:
# Inside `setup.cfg`:
[isort]
multi_line_output = 3
include_trailing_comma = true
default_section = FIRSTPARTY
# Is the same as 80 in flake8:
line_length = 79
Otherwise, your isort
will complain about your imports.
We are working hard to remove any kind of configuration from this tool. Please, be calm!