Config¶
-
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 2i-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-offset-blocks
- maximum number of block to nest expressions, defaults to 5max-elifs
- maximum number ofelif
blocks, defaults to 3max-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-conditions
- maximum number of boolean conditions in a singleif
orwhile
node, defaults to 4max-base-classes
- maximum number of parent classes inside a class definition, defaults to 3
All options are configurable via
flake8
CLI:Example:
flake8 --max-returns=2 --max-elifs=2
Or you can provide options in
tox.ini
orsetup.cfg
:Example:
[flake8] max-returns = 2 max-elifs = 2
We use
setup.cfg
as a default way to provide configuration.
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:
-
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 method, self is not counted:
-
MAX_OFFSET_BLOCKS
= 5¶ Maximum number of blocks to nest different structures:
-
MAX_ELIFS
= 3¶ Maximum number of elif blocks in a single if condition:
-
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_CONDITIONS
= 4¶ Maximum number of conditions in a single
if
orwhile
statement:
-
MAX_BASE_CLASSES
= 3¶ Maximum number of base classes:
Plugins¶
It is also important to configure different plugins that we ship with this module.
[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:
[isort]
multi_line_output = 3
include_trailing_comma = true
default_section = FIRSTPARTY
line_length = 80
Otherwise, your isort
will complain about your imports.
We are working hard to remove any kind of configuration from this tool. Please, be calm!