Commands¶
$ rattle COMMAND [OPTIONS] ...
The following runtime options are available on commands that lint code, autofix code, or materialize lint configuration.
--debug, --quiet / -q¶
Raise or lower the level of output and logging.
--config-file / -c PATH¶
Override the normal hierarchical configuration and use the configuration from the specified path, ignoring all other configuration files entirely.
--exclude PATTERN¶
Override configured file exclusions with a glob pattern. This option may be
passed more than once. Like Ruff’s --exclude, direct path arguments are also
excluded when they match the pattern.
$ rattle lint . --exclude "generated/**"
--extend-exclude PATTERN¶
Add a glob pattern to the configured file exclusions. This option may be passed
more than once. Direct path arguments are still checked unless they are excluded
by configuration with force-exclude.
$ rattle lint . --extend-exclude "docs/_build/**"
--rules / -r RULES¶
Override the configured set of lint rules entirely.
This takes a comma-separated list of rule selectors, with the same accepted
forms as enable and
disable:
import selectors such as
rattle.rules.fixit_extra:use-f-stringbuilt-in rule collections such as
blank-lines,fixit, orfixit-extraexact built-in rule names such as
use-f-string
For example:
$ rattle lint --rules "use-f-string" path/to/file.py
$ rattle lint --rules "fixit,fixit-extra" path/to/file.py
--output-format / -o FORMAT_TYPE¶
Override how Rattle prints violations to the terminal.
See output-format for available formats.
--output-template TEMPLATE¶
Override the Python formatting template used with output-format = "custom".
lint¶
Lint one or more paths and print a list of lint errors. If - is given as the
first path, then the second path is used for configuration lookup and error
messages, and the input is read from standard input.
$ rattle lint [OPTIONS] [--brief] [--diff] [--stats] [PATH ...]
--brief / -b¶
Print each diagnostic on one line, without source snippets or help text.
--diff / -d¶
Show suggested fixes, in unified diff format, when available.
--stats¶
Print violation counts grouped by containing directory.
fix¶
Lint one or more paths and apply suggested fixes. If - is given as the first
path, then the second path is used for configuration lookup, the input is read
from standard input, and the fixed output is printed to standard output,
ignoring --interactive.
$ rattle fix [OPTIONS] [--interactive | --automatic] [--brief] [--diff] [PATH ...]
--interactive / -i¶
Interactively prompt the user to apply or decline each available autofix.
Press y to apply, n to skip, or q to stop prompting and leave the
remaining fixes unapplied.
--automatic / -a¶
Automatically apply suggested fixes for all lint errors when available. This is the default behavior.
--brief / -b¶
Print each diagnostic on one line, without source snippets or help text.
--diff / -d¶
Show applied fixes in unified diff format when applied automatically.
lsp¶
Start the language server providing IDE features over
LSP.
This command is only available if Rattle is installed with the lsp extras,
for example pip install "rattle-lint[lsp]". See IDE for more
details.
$ rattle lsp [--no-stdio] [--tcp PORT | --ws PORT]
--no-stdio / -n¶
Disable the default stdio transport when serving over TCP or WebSocket.
--tcp¶
Serve LSP over TCP on PORT.
--ws / -w¶
Serve LSP over WebSocket on PORT.
--debounce-interval / -d¶
Delay in seconds for server-side debounce. Default: 0.5.
rules¶
Display the lint rules enabled for the current configuration. Pass paths to see the rules resolved for those files or directories.
$ rattle rules [PATH ...]
--test¶
Test enabled lint rules using their VALID and
INVALID test cases. Use --rules to select the rules
to test.
Rule selectors use the same forms as
enable and
disable.
Example:
$ rattle rules --test -r .examples.teambread.rules
test_INVALID_0 (rattle.testing.hollywood-name-rule) ... ok
test_INVALID_1 (rattle.testing.hollywood-name-rule) ... ok
test_VALID_0 (rattle.testing.hollywood-name-rule) ... ok
test_VALID_1 (rattle.testing.hollywood-name-rule) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.024s
OK
$ rattle rules --test -r use-f-string
validate¶
Validate config. When no path is provided, Rattle validates pyproject.toml
from the current directory.
$ rattle validate
$ rattle validate pyproject.toml