Rules¶
Rattle’s built-in rules are grouped by collection. Enable a collection by adding
its name to enable, or enable a single rule by its
kebab-case name.
Blank Lines¶
Whitespace and statement-separation rules.
Enable with:
enable = ["blank-lines"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Missing blank line after multiline control-flow block statement. |
Any |
Yes |
|
Missing blank line after terminal control-flow block. |
Any |
Yes |
|
Missing blank line before return/raise/break/continue in a large suite. |
Any |
Yes |
|
Illegal cuddle before block header. The preceding setup must directly feed the upcoming block. |
Any |
Yes |
|
Leading or trailing blank lines in a suite are not allowed. |
Any |
Yes |
Exports¶
Rules for explicit module export surfaces.
Enable with:
enable = ["exports"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Define module __all__ at the bottom of the file. |
Any |
Yes |
|
Do not export underscore-prefixed symbols in __all__. Either remove them from __all__ or rename them to be public. |
Any |
No |
Policy¶
Configurable policy rules for architecture and naming boundaries.
Enable with:
enable = ["policy"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Do not call forbidden callable ‘{symbol}’. |
Any |
No |
|
Do not import across forbidden boundary ‘{boundary}’. |
Any |
No |
|
Do not use forbidden {kind} name ‘{name}’. |
Any |
No |
|
{target} has {actual_lines} lines, exceeding the configured limit of {max_lines}. |
Any |
No |
|
Use absolute imports instead of relative imports. |
Any |
No |
|
Import aliases must not start with an underscore. |
Any |
No |
|
Use tempfile context managers instead of mkstemp or mkdtemp. |
Any |
No |
Style¶
Rules for code style and structure.
Enable with:
enable = ["style"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Do not annotate self in instance methods. |
Any |
Yes |
|
Inline exception message strings instead of assigning throwaway variables. |
Any |
Yes |
|
Do not translate exceptions by passing str(exc); use a stable message and chain the cause. |
Any |
No |
|
Class names must not start with an underscore prefix. |
Any |
No |
|
Define public methods before private helpers in behavior classes. |
Any |
No |
Typing¶
Rules for type annotations and modern typing syntax.
Enable with:
enable = ["typing"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Use a narrower type than bare object in annotations. |
Any |
No |
Fixit¶
Core lint rules inherited from Fixit.
Enable with:
enable = ["fixit"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Dataclass mutability must be explicit. Add |
Any |
No |
|
Instead of NamedTuple, consider using the @dataclass decorator from dataclasses instead for simplicity, efficiency and consistency. |
Any |
Yes |
|
Your if condition appears to evaluate to a static value (e.g. |
Any |
No |
|
It appears you are using the @sorted-attributes directive and the class variables are unsorted. See the lint autofix suggestion. |
Any |
Yes |
|
Use Callable[…, T] instead of Callable[[…], T]. |
Any |
Yes |
|
noqa is deprecated. Use |
Any |
No |
|
You are using builtins.{builtin_type} as a type annotation but the type system doesn’t recognize it as a valid type. Use typing.{correct_type} instead. |
|
Yes |
Fixit Extra¶
Additional Fixit-derived rules that can be enabled separately.
Enable with:
enable = ["fixit-extra"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. |
Any |
Yes |
|
{deprecated} is deprecated, use {replacement} instead |
Any |
Yes |
|
Inheriting from object is a no-op. ‘class Foo:’ is just fine =) |
Any |
Yes |
|
Avoid using ‘or’ in an except block. For example:’except ValueError or TypeError’ only catches ‘ValueError’. Instead, use parentheses, ‘except (ValueError, TypeError)’ |
Any |
No |
|
Do not use arguments when calling super for the parent class. |
Any |
Yes |
|
f-string doesn’t have placeholders, remove redundant f-string. |
Any |
Yes |
|
The lambda that is wrapping {function} is redundant. It can unwrapped safely and used purely. |
Any |
Yes |
|
Unnecessary list comprehension inside {func}(). Use a generator expression instead. |
Any |
Yes |
|
String type hints are no longer necessary in Python, use the type identifier directly. |
Any |
Yes |
|
|
Any |
Yes |
|
“assertTrue” does not compare its arguments, use “assertEqual” or other appropriate functions. |
Any |
Yes |
|
Use assertIn/assertNotIn instead of assertTrue/assertFalse for inclusion check. |
Any |
Yes |
|
“assertTrue” and “assertFalse” are deprecated. Use “assertIsNotNone” and “assertIsNone” instead. |
Any |
Yes |
|
Use asyncio.sleep in async function |
Any |
No |
|
When using @classmethod, the first argument must be |
Any |
Yes |
|
ABCs must be imported from collections.abc |
|
Yes |
|
It’s unnecessary to use {func} around a generator expression, since there are equivalent comprehensions for this type. |
Any |
Yes |
|
Don’t use |
Any |
Yes |
|
Do not use printf style formatting or .format(). Use f-string instead to be more readable and efficient. |
Any |
Yes |
|
Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identity. Use |
Any |
Yes |
|
It’s unnecessary to use a list or tuple within a call to {func} since there is literal syntax for this type |
Any |
Yes |