Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
run: uv run --group dev ruff format --check src/rattle scripts examples docs/conf.py
- name: Run Ruff lint
run: uv run --group dev ruff check src/rattle scripts examples docs/conf.py
- name: Run Rattle lint
run: uv run --group dev python -m rattle lint src/rattle
- name: Run Rattle check
run: uv run --group dev python -m rattle check src/rattle
8 changes: 4 additions & 4 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- id: rattle-lint
name: Rattle - lint
name: Rattle - check
description: This hook shows Rattle lints and suggested changes without applying autofixes.
entry: rattle lint --diff
entry: rattle check --diff
language: python
types: [python]
- id: rattle-fix
name: Rattle - lint and apply autofixes
name: Rattle - check and apply autofixes
description: This hook shows Rattle lints and applies suggested changes.
entry: rattle fix
entry: rattle check --fix
language: python
types: [python]
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ venv: install
lint: _require-uv
uv run --group dev ruff check src/rattle scripts examples docs/conf.py
uv run --group dev ruff format --check src/rattle scripts examples docs/conf.py
uv run --group dev python -m rattle lint src/rattle
uv run --group dev python -m rattle check src/rattle

# Format code
format: _require-uv
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ forbidden_calls = ["typing.cast"]
Adjust the list to match the project, then lint the repository:

```bash
rattle lint .
rattle check .
```

Apply available autofixes:

```bash
rattle fix .
rattle check --fix .
```

Explain rule metadata, examples, and settings:
Expand Down
41 changes: 21 additions & 20 deletions docs/guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ $ rattle COMMAND [OPTIONS] ...

Use `--help` on any command to print its supported options.

## Shared lint/fix options
## Check options

The following options are available on commands that check or fix code.
The following options are available on `check`, with or without `--fix`.

### `--config / -c CONFIG`

Expand All @@ -23,7 +23,7 @@ Like Ruff's `--exclude`, direct path arguments are also excluded when they match
the pattern.

```console
$ rattle lint . --exclude "generated/**"
$ rattle check . --exclude "generated/**"
```

### `--extend-exclude PATTERN`
Expand All @@ -33,7 +33,7 @@ arguments are still checked unless they are excluded by configuration with
`force-exclude`.

```console
$ rattle lint . --extend-exclude "docs/_build/**"
$ rattle check . --extend-exclude "docs/_build/**"
```

### `--rules / -r RULES`
Expand All @@ -55,9 +55,9 @@ A selector that does not resolve to a rule is an error.
For example:

```console
$ rattle lint --rules "use-f-string" path/to/file.py
$ rattle lint --rules "my-custom-rule" path/to/file.py
$ rattle lint --rules "fixit,legacy" path/to/file.py
$ rattle check --rules "use-f-string" path/to/file.py
$ rattle check --rules "my-custom-rule" path/to/file.py
$ rattle check --rules "fixit,legacy" path/to/file.py
```

### `--jobs / -j JOBS`
Expand All @@ -71,11 +71,11 @@ Print compact diagnostics.
### `--quiet / -q`

Print only the final summary. `--quiet` cannot be used with `--diff`, `--stats`,
or `fix --interactive`.
or `--interactive`.

### `--diff / -d`

Show fixes as unified diffs.
Show available fixes as unified diffs, or applied changes with `--fix`.

### `--stats / -s`

Expand All @@ -89,25 +89,26 @@ Override the configured `output-format`: `rattle`, `vscode`, or `custom`.

Override the configured `output-template` used by the `custom` output format.

## `lint`
## `check`

Check files for Rattle violations. Use `- PATH` to check code from standard
input as `PATH`.
Check files for Rattle violations without modifying source files. With no paths,
check the current directory. Use `- PATH` to check standard input as `PATH`.

```console
$ rattle lint [OPTIONS] [PATH ...]
$ rattle check [OPTIONS] [PATH ...]
```

### `--json`

Print diagnostics as a JSON array on standard output. The summary still goes to
standard error. Cannot be combined with `--quiet`, `--diff`, `--compact`,
`--output-format`, or `--output-template`.
`--output-format`, `--output-template`, or `--fix`.

## `fix`
### `--fix`

Apply available autofixes to files. Use `- PATH` to fix code from standard
input as `PATH` and write the fixed code to standard output.
Apply available autofixes, then report remaining violations. Use `- PATH` to fix
standard input as `PATH` and write fixed code to standard output; diagnostics
and the summary go to standard error.

By default, automatic fixing runs available autofixes until the file stops
changing or no more autofixes are found. Diagnostics shown after fixing are
Expand All @@ -116,14 +117,14 @@ applied changes, or `--interactive` to review one initial pass of fixes before
verification.

```console
$ rattle fix [OPTIONS] [--interactive] [PATH ...]
$ rattle check --fix [OPTIONS] [PATH ...]
```

### `--interactive / -i`

Prompt before applying each autofix. Answer `y` to apply, `n` or Enter to skip,
or `q` to stop prompting and leave the remaining fixes unapplied. This option
requires a terminal on standard input and cannot be used with `- PATH`.
requires `--fix` and a terminal on standard input, and cannot be used with `- PATH`.

(lsp_command)=

Expand Down Expand Up @@ -222,4 +223,4 @@ Enable debug logging.

### `RATTLE_METRICS=1`

Print internal run metrics for `lint` and `fix`.
Print internal run metrics for `check`, with or without `--fix`.
20 changes: 10 additions & 10 deletions docs/guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Rattle also supports editor integrations, LSP, and pre-commit. See the
See lints and suggested changes for a set of source files:

```console
$ rattle lint <path>
$ rattle check <path>
```

Apply suggested changes on those same files automatically:

```console
$ rattle fix <path>
$ rattle check --fix <path>
```

If given directories, Rattle will recurse them automatically, finding `.py`
Expand All @@ -59,7 +59,7 @@ handler: Callable[[...], int]
With `modernization` enabled, running Rattle shows the rule violation:

```console
$ rattle lint handlers.py
$ rattle check handlers.py
use-callable-ellipsis [*] Use Callable[..., T] instead of Callable[[...], T].
--> handlers.py:4:10
|
Expand All @@ -73,7 +73,7 @@ help: Apply the available autofix
You can also see suggested changes by passing `--diff`:

```console
$ rattle lint --diff handlers.py
$ rattle check --diff handlers.py
use-callable-ellipsis [*] Use Callable[..., T] instead of Callable[[...], T].
--> handlers.py:4:10
|
Expand Down Expand Up @@ -255,7 +255,7 @@ def main():
```

```console
$ rattle lint --diff sourdough/baker.py
$ rattle check --diff sourdough/baker.py
hollywood-name-rule [*] It's underproved!
--> sourdough/baker.py:2:12
|
Expand All @@ -274,19 +274,19 @@ help: Apply the available autofix
print(f"hello {name}")
```

Note that the `lint` command only shows lint errors and suggested changes.
The `fix` command applies those changes to the codebase:
The `check` command only shows lint errors and suggested changes.
Pass `--fix` to apply those changes to the codebase:

```console
$ rattle fix sourdough/baker.py
$ rattle check --fix sourdough/baker.py
1 file checked, 1 fix applied
```

Pass `--interactive` to confirm each available autofix one at a time.
Pass `--fix --interactive` to confirm each available autofix one at a time.

Now that the suggested changes have been applied, the codebase is clean:

```console
$ rattle lint sourdough/baker.py
$ rattle check sourdough/baker.py
1 file clean
```
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ forbidden_calls = ["typing.cast"]
Adjust the list to match the project, then lint the repository:

```bash
rattle lint .
rattle check .
```

Apply available autofixes:

```bash
rattle fix .
rattle check --fix .
```

Explain rule metadata, examples, and settings:
Expand Down
4 changes: 2 additions & 2 deletions src/rattle/.agents/skills/create-rattle-lint-rules/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ Use the repository's command runner and configuration context. At minimum run:
```bash
rattle validate pyproject.toml
rattle rules --test --config pyproject.toml .
rattle lint --diff .
rattle check --diff .
```

Run focused project tests for affected code. Apply `rattle fix` across the
Run focused project tests for affected code. Apply `rattle check --fix` across the
repository only when the user requests it.

If the rule is noisy, add valid cases before changing the implementation. Test
Expand Down
13 changes: 4 additions & 9 deletions src/rattle/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from interfacy.naming import NoAbbreviations
from interfacy.plugins import ExecuteContext, InterfacyPlugin

from rattle.cli.commands.check import check
from rattle.cli.commands.explain import explain_command
from rattle.cli.commands.fix import fix
from rattle.cli.commands.lint import lint
from rattle.cli.commands.lsp import lsp
from rattle.cli.commands.rules import rules_command
from rattle.cli.commands.validate import validate_command
Expand All @@ -23,9 +22,10 @@
from rattle.config import CollectionError, ConfigError

CONFIG_PARAM = Param(short="c", metavar="<path>")
LINT_PARAMS = {
CHECK_PARAMS = {
"config": CONFIG_PARAM,
"diff": Param(short="d"),
"interactive": Param(short="i"),
"exclude": Param(short="e", metavar="<pattern>"),
"extend_exclude": Param(metavar="<pattern>"),
"jobs": Param(short="j", metavar="<n>"),
Expand All @@ -35,10 +35,6 @@
"output_format": Param(metavar="<rattle|vscode|custom>"),
"output_template": Param(metavar="<template>"),
}
FIX_PARAMS = {
**LINT_PARAMS,
"interactive": Param(short="i"),
}
SIGPIPE_EXIT_CODE = 141
DOCS_URL = "https://rattle.readthedocs.io/en/latest"

Expand Down Expand Up @@ -74,8 +70,7 @@ def build_app() -> Interfacy:
],
plugins=[CommandErrorPlugin()],
)
app.add_command(lint, params=LINT_PARAMS)
app.add_command(fix, params=FIX_PARAMS)
app.add_command(check, params=CHECK_PARAMS)
app.add_command(
lsp,
params={
Expand Down
Loading
Loading