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 |
|---|---|---|---|
Add a blank line after this multiline control-flow block. |
Any |
Yes |
|
Add a blank line after this early-exit control-flow block. |
Any |
Yes |
|
Add a blank line before this branch statement in a larger code block. |
Any |
Yes |
|
Add a blank line before this block; the preceding statements do not prepare values used by it. |
Any |
Yes |
|
Remove blank lines at the beginning or end of a code block. |
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 |
|
Use a fixed message when translating an exception, and preserve the cause with |
Any |
No |
|
Class names must not start with an underscore prefix. |
Any |
No |
|
Define public methods before underscore-prefixed helper methods. |
Any |
No |
Typing¶
Rules for type annotations and modern typing syntax.
Enable with:
enable = ["typing"]
Rule |
Message |
Python |
Autofix |
|---|---|---|---|
Replace this bare |
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 |
|
NamedTuple can often be replaced with @dataclass, but dataclasses are not tuple-compatible; check callers before converting. |
Any |
No |
|
This |
Any |
No |
|
Class assignments under @sorted-attributes are not sorted; sorting them can change right-hand-side side-effect order. |
Any |
Yes |
|
Use Callable[…, T] instead of Callable[[…], T]. |
Any |
Yes |
|
Use |
Any |
No |
|
Python 3.8 does not support |
|
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 |
No |
|
|
Any |
Yes |
|
Remove the redundant |
Any |
Yes |
|
Use |
Any |
No |
|
Call |
Any |
No |
|
Remove the |
Any |
Yes |
|
The lambda that wraps {function} is redundant and can be replaced by the callable. |
Any |
No |
|
Unnecessary list comprehension inside {func}(). Use a generator expression instead. |
Any |
No |
|
Remove the quotes from this annotation; postponed evaluation is already enabled. |
Any |
Yes |
|
|
Any |
No |
|
Use |
Any |
Yes |
|
Use |
Any |
Yes |
|
Use |
Any |
Yes |
|
Do not call blocking time.sleep inside async functions; use asyncio.sleep or an async runtime sleep. |
Any |
No |
|
When using @classmethod, the first argument must be |
Any |
Yes |
|
Import abstract base classes from |
|
Yes |
|
Replace this {func}() call with the equivalent comprehension. |
Any |
No |
|
Use |
Any |
Yes |
|
Use an f-string instead of |
Any |
Yes |
|
Compare |
Any |
Yes |
|
Replace this {func}() call with the equivalent collection literal. |
Any |
Yes |