Built-in Rules¶
Rude ships with 104 built-in rules (pyflakes, pycodestyle, McCabe). Additional
rules can be added via third-party plugins or local rules. Example rules
(templates, patterns, hygiene) are available in examples/rules/ for use as
local rules.
All rules can be selected individually by code (e.g. --select F401) or by prefix
(e.g. --select PAT to enable all pattern rules). Rules marked with autofix support
can be applied automatically with rude check --fix. Configurable rules accept
per-rule options in [tool.rude.rules.<CODE>] sections of your pyproject.toml.
Pyflakes (F) – Logical errors¶
Pyflakes rules detect programming errors such as unused imports, undefined names, and incorrect use of language features. These rules catch bugs that would otherwise only surface at runtime.
Code |
Name |
Description |
Autofix |
|---|---|---|---|
F401 |
UnusedImport |
Module imported but unused |
|
F402 |
ImportShadowedByLoopVar |
Import name shadowed by a loop variable |
|
F403 |
ImportStarUsed |
|
|
F404 |
LateFutureImport |
|
|
F406 |
ImportStarNotPermitted |
|
|
F407 |
FutureFeatureNotDefined |
Future feature not recognized by the Python interpreter |
|
F541 |
FStringMissingPlaceholders |
f-string without any placeholders |
yes |
F542 |
TStringMissingPlaceholders |
t-string without any placeholders |
yes |
F601 |
MultiValueRepeatedKeyLiteral |
Dictionary key literal repeated |
|
F602 |
MultiValueRepeatedKeyVariable |
Dictionary key variable repeated |
|
F621 |
TooManyExpressionsInStarredAssignment |
Too many expressions in starred assignment |
|
F622 |
TwoStarredExpressions |
More than one starred expression in an assignment |
|
F631 |
AssertTuple |
|
|
F632 |
IsLiteral |
Use |
yes |
F634 |
IfTuple |
|
|
F701 |
BreakOutsideLoop |
|
|
F702 |
ContinueOutsideLoop |
|
|
F704 |
YieldOutsideFunction |
|
|
F706 |
ReturnOutsideFunction |
|
|
F707 |
DefaultExceptNotLast |
|
|
F811 |
RedefinedWhileUnused |
Name redefined from an unused import |
|
F821 |
UndefinedName |
Undefined name |
|
F822 |
UndefinedExport |
Name listed in |
|
F823 |
UndefinedLocal |
Local variable referenced before assignment |
|
F831 |
DuplicateArgument |
Duplicate argument in function definition |
|
F841 |
UnusedVariable |
Local variable assigned but never used |
yes |
F842 |
UnusedAnnotation |
Local variable annotated but never used |
|
F901 |
RaiseNotImplemented |
|
yes |
Plus format string rules (F5xx) and annotation/docstring checks.
Pycodestyle (E/W) – Style¶
Pycodestyle rules enforce the PEP 8 style guide. They cover indentation, whitespace, blank lines, imports, line length, and statement structure.
Indentation (E1xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E101 |
IndentationContainsMixedSpacesAndTabs |
Indentation contains mixed spaces and tabs |
|
E111 |
IndentationNotMultipleOfFour |
Indentation is not a multiple of four spaces |
|
E117 |
OverIndented |
Over-indented code block |
|
W191 |
IndentationContainsTabs |
Indentation contains tabs |
Whitespace (E2xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E201 |
WhitespaceAfterOpenBracket |
Whitespace after |
|
E202 |
WhitespaceBeforeCloseBracket |
Whitespace before |
|
E203 |
WhitespaceBeforeColon |
Whitespace before |
|
E211 |
WhitespaceBeforeParameters |
Whitespace before |
|
E221 |
MultipleSpacesBeforeOperator |
Multiple spaces before operator |
yes |
E222 |
MultipleSpacesAfterOperator |
Multiple spaces after operator |
yes |
E223 |
TabBeforeOperator |
Tab before operator |
yes |
E224 |
TabAfterOperator |
Tab after operator |
yes |
E225 |
MissingWhitespaceAroundOperator |
Missing whitespace around operator |
|
E226 |
MissingWhitespaceAroundArithmeticOperator |
Missing whitespace around arithmetic operator |
|
E227 |
MissingWhitespaceAroundBitwiseOperator |
Missing whitespace around bitwise or shift operator |
|
E228 |
MissingWhitespaceAroundModuloOperator |
Missing whitespace around modulo operator |
|
E231 |
MissingWhitespaceAfterComma |
Missing whitespace after |
|
E241 |
MultipleSpacesAfterComma |
Multiple spaces after comma |
yes |
E242 |
TabAfterComma |
Tab after comma |
yes |
E251 |
UnexpectedSpacesAroundKeywordEquals |
Unexpected spaces around keyword / parameter default |
|
E261 |
LeastTwoSpacesBeforeInlineComment |
At least two spaces before inline comment |
yes |
E262 |
InlineCommentShouldStartWithHash |
Inline comment should start with |
yes |
E265 |
BlockCommentShouldStartWithHash |
Block comment should start with |
yes |
E266 |
TooManyLeadingHashesForBlockComment |
Too many leading |
yes |
E271 |
MultipleSpacesAfterKeyword |
Multiple spaces after keyword |
yes |
E272 |
MultipleSpacesBeforeKeyword |
Multiple spaces before keyword |
yes |
E273 |
TabAfterKeyword |
Tab after keyword |
yes |
E274 |
TabBeforeKeyword |
Tab before keyword |
yes |
E275 |
MissingWhitespaceAfterKeyword |
Missing whitespace after keyword |
yes |
Blank lines (E3xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E301 |
ExpectedOneBlankLine |
Expected 1 blank line before a nested definition |
|
E302 |
ExpectedTwoBlankLines |
Expected 2 blank lines before a function or class definition |
|
E303 |
TooManyBlankLines |
Too many blank lines |
|
E304 |
BlankLinesAfterDecorator |
Unexpected blank lines after decorator |
|
E305 |
ExpectedTwoBlankLinesAfterClassOrFunction |
Expected 2 blank lines after end of function or class |
|
E306 |
ExpectedOneBlankLineBeforeNestedDef |
Expected 1 blank line before a nested definition |
Imports (E4xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E401 |
MultipleImportsOnOneLine |
Multiple imports on one line |
|
E402 |
ModuleLevelImportNotAtTop |
Module-level import not at top of file |
Line length (E5xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E501 |
LineTooLong |
Line too long (default: 79 characters) |
Statements (E7xx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
E701 |
MultipleStatementsOnOneLineColon |
Multiple statements on one line (colon) |
|
E702 |
MultipleStatementsOnOneLineSemicolon |
Multiple statements on one line (semicolon) |
|
E703 |
StatementEndsWithSemicolon |
Statement ends with a semicolon |
yes |
E704 |
MultipleStatementsOnOneLineDef |
Statement on same line as |
|
E711 |
ComparisonToNone |
Comparison to |
yes |
E712 |
ComparisonToTrueFalse |
Comparison to |
|
E713 |
NotInTest |
Test for membership should be |
yes |
E714 |
NotIsTest |
Test for object identity should be |
yes |
E721 |
TypeComparison |
Do not compare types, use |
|
E722 |
BareExcept |
Do not use bare |
yes |
E731 |
LambdaAssignment |
Do not assign a |
|
E741 |
AmbiguousVariableName |
Ambiguous variable name (e.g. |
|
E742 |
AmbiguousClassName |
Ambiguous class name |
|
E743 |
AmbiguousFunctionName |
Ambiguous function name |
Warnings (Wxxx)¶
Code |
Name |
Description |
Autofix |
|---|---|---|---|
W291 |
TrailingWhitespace |
Trailing whitespace |
|
W292 |
NoNewlineAtEndOfFile |
No newline at end of file |
|
W293 |
BlankLineContainsWhitespace |
Blank line contains whitespace |
|
W391 |
BlankLineAtEndOfFile |
Blank line at end of file |
|
W605 |
InvalidEscapeSequence |
Invalid escape sequence |
McCabe (C) – Complexity¶
McCabe rules measure cyclomatic complexity of functions and methods. High complexity indicates code that is harder to understand and test.
Code |
Name |
Description |
Default |
Autofix |
|---|---|---|---|---|
C901 |
FunctionTooComplex |
Function has too high cyclomatic complexity |
threshold: 10 |
Patterns (PAT) – Code smells¶
Pattern rules detect structural code smells such as overly long functions, deeply
nested code, and dangerous built-in calls. Thresholds are configurable via
[tool.rude.rules.<CODE>] in your pyproject.toml.
Code |
Name |
Description |
Default |
Autofix |
|---|---|---|---|---|
PAT001 |
TooManyParameters |
Function has too many parameters |
max: 5 |
|
PAT002 |
TooManyBranches |
Function has too many branches (cyclomatic complexity) |
max: 12 |
|
PAT003 |
DeepNesting |
Code block is nested too deeply |
max: 4 |
|
PAT004 |
LongFunction |
Function body is too long |
max: 50 lines |
|
PAT005 |
GodClass |
Class has too many methods |
max: 20 |
|
PAT006 |
NoPassInExcept |
Bare |
||
PAT007 |
BareExcept |
Use |
yes |
|
PAT008 |
NoEval |
|
yes |
|
PAT009 |
NoExec |
|
||
PAT010 |
NoAssertInProduction |
|
Hygiene (META) – Code hygiene¶
Hygiene rules enforce documentation and annotation discipline. They help teams
maintain consistent code review practices by requiring ticket references in TODOs
and specific suppression codes in noqa and type: ignore comments.
Code |
Name |
Description |
Configurable |
Autofix |
|---|---|---|---|---|
META001 |
TodoWithoutTicket |
TODO/FIXME comments must include a ticket reference |
|
|
META002 |
BlanketNoqa |
|
||
META003 |
TypeIgnoreWithoutCode |
|
Example Rules¶
Templates (EX001-EX004), patterns (PAT001-PAT010), and hygiene (META001-META003)
are available in examples/rules/. Load them via local rules:
[tool.rude]
local-rules = ["examples/rules/templates", "examples/rules/patterns"]
See examples/rules/README.md for details.