Violations¶
Contains detailed information about violation and how to use them.
Writing new violation¶
First of all, you have to select the correct base class for new violation. The main criteria is what logic will be used to find the flaw in your code.
Available base classes¶
ASTViolation |
Violation for ast based style visitors. |
TokenizeViolation |
Violation for tokenize based visitors. |
SimpleViolation |
Violation for cases where there’s no associated nodes. |
Violation can not have more than one base class. Since it does not make sense to have two different node types at the same time.
Violations API¶
-
ErrorNode
= typing.Union[_ast.AST, tokenize.TokenInfo, NoneType]¶ General type for all possible nodes where error happens.
-
class
BaseStyleViolation
(node, text=None)[source]¶ Bases:
object
Abstract base class for all style violations.
It basically just defines how to create any error and how to format this error later on.
Each subclass must define
error_template
andcode
fields.-
error_template
¶ message that will be shown to user after formatting.
-
code
¶ violation unique number. Used to identify the violation.
-
should_use_text
¶ formatting option. Some do not require extra text.
-
-
class
ASTViolation
(node, text=None)[source]¶ Bases:
wemake_python_styleguide.violations.base.BaseStyleViolation
Violation for
ast
based style visitors.
-
class
TokenizeViolation
(node, text=None)[source]¶ Bases:
wemake_python_styleguide.violations.base.BaseStyleViolation
Violation for
tokenize
based visitors.
-
class
SimpleViolation
(node=None, text=None)[source]¶ Bases:
wemake_python_styleguide.violations.base.BaseStyleViolation
Violation for cases where there’s no associated nodes.