The documentation has stale configuration guidance and a few examples
that do not work as written. Clarify the prose and correct editor
configuration precedence, user-level configuration discovery, rule
descriptions, and the tutorial and configuration examples.
---------
Co-authored-by: Zanie Blue <zanie@openai.com>
Summary
--
This is the CLI accompaniment to #27807. The main change here is showing
display-only fix diffs in
the CLI. However, display-only fixes don't have a corresponding flag
like `--unsafe-fixes`, and I
thought it would be weird to show them unconditionally when we don't do
the same for unsafe fixes,
so this PR also unconditionally renders unsafe fix diffs, even when that
flag isn't passed. We
already emit a note about the fix being unsafe, so I think it makes
sense always to show you the
fix, and make `--unsafe-fixes` enable actually applying the fix. We also
don't want to apply
display-only fixes, so enabling rendering of the fixes with
`--display-only-fixes` or similar would
also disagree with the semantics of the unsafe flag. I'm open to other
ideas here, though.
The sub-diagnostic for display-only fixes uses a higher severity than
the note for unsafe fixes and
renders in red, as shown below.
The change here also affects ty, which now has both unsafe and
display-only fixes.
I again checked what clippy and rustc do in these cases, and they don't
include any additional note or warning about the fix being unsafe:
<details><summary>Rust diagnostics</summary>
<p>
Here's a
[`clippy::needless_pass_by_value`](https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#needless_pass_by_value)
diagnostic, which is `MaybeIncorrect` ( similar to our `Unsafe`):
```
warning: this argument is passed by value, but not consumed in the function body
--> src/main.rs:3:15
|
3 | fn size(data: Data) -> usize {
| ^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.97.0/index.html#needless_pass_by_value
= note: requested on the command line with `-W clippy::needless-pass-by-value`
help: consider taking a reference instead
|
3 | fn size(data: &Data) -> usize {
| +
```
and here's a rustc
[`LetLike`](https://github.com/rust-lang/rust/blob/8bab26f4f68e0e26f0bb7960be334d5b520ea452/compiler/rustc_trait_selection/src/errors.rs#L268-L288)
diagnostic, which is `has-placeholders` (similar to our `DisplayOnly`
but definitely produces invalid code in this case):
```
error[E0282]: type annotations needed for `Vec<_>`
--> placeholder.rs:2:9
|
2 | let values = Vec::new();
| ^^^^^^ ---------- type must be known at this point
|
help: consider giving `values` an explicit type, where the type for type parameter `T` is specified
|
2 | let values: Vec<T> = Vec::new();
| ++++++++
```
</p>
</details>
Fixes https://github.com/astral-sh/ty/issues/1679
Test Plan
--
Updated existing snapshots, and some manual testing in the CLI:
<img width="965" height="400" alt="image"
src="https://github.com/user-attachments/assets/888ad79a-6853-48d4-8344-48da4af47d74"
/>
---------
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This PR stabilizes the expanded default rule set currently in preview
and adds a new generated `Default Rules` page to the docs to avoid
needing to include a lengthy selector block in multiple places.
Summary
--
This PR adds the new `--add-ignore` flag. In preview, this adds
`ruff:ignore` comments with human-readable names instead of `noqa`
comments with codes. Without preview enabled, using the flag emits an
error. `--add-noqa` itself is still available in both preview and stable
mode.
In cases where an existing `noqa` or `ruff:ignore` comment is present, I
opted to preserve the
existing comment and to append the new comment. So something like this:
```py
import math # noqa: RUF100
```
becomes:
```py
import math # noqa: RUF100 # ruff:ignore[unused-import]
```
instead of also converting the existing `noqa` comment. I think we can
defer to one of our planned
lint rules for the conversion (and joining) instead.
As also shown in this example, the flag adds human-readable names rather
than rule codes and prefers
the same placement as a `noqa` comment, at the end of the line. The one
exception to this is an
existing `ruff:ignore` comment on its own line. In that case, we will
reuse and extend the existing
comment instead of adding an additional trailing comment, which I think
is a pretty nice balance.
Test Plan
--
Many new tests exercising the various cases Codex and I could come up
with. As the server test
shows, this actually applies to the LSP as well, where the `Disable for
this line` action now also
inserts a `ruff:ignore` comment with a rule name instead of a `noqa`
comment.
Ecosystem check
--
I also ran some tests against ecosystem projects as described in my
[comment](https://github.com/astral-sh/ruff/pull/26346#issuecomment-4801988686)
below. These revealed some additional discrepancies between
`ruff:ignore` and `noqa` (and some bugs in `noqa`/`--add-noqa` itself),
but I think it makes sense to leave these as follow-ups. I've already
opened (rough) drafts of them in:
- https://github.com/astral-sh/ruff/pull/26373
- https://github.com/astral-sh/ruff/pull/26409
- https://github.com/astral-sh/ruff/pull/26412
We could land the shebang fixes separately, but the other two are
stacked on this PR. With all three of these applied, the ecosystem check
showed parity with `--add-noqa`.
This also seems like an interesting check to add to our ecosystem
analysis in general.
## Summary
Fixes a one-character typo in (line 61).
The Linux/macOS virtual environment activation command was written as:
```
source .venv/bin/active
```
but should be:
```
source .venv/bin/activate
```
The Windows command on the same line () was already correct, making the
discrepancy easy to spot.
## How verified
The fix was verified by reading the file directly — is not a valid shell
script; the correct file installed by Python’s `venv` module is always .
Co-authored-by: Claude <noreply@anthropic.com>
Just to be sure, I ran the example from #23587 again on this branch:
```console
~/astral/ruff on brent/0.15.4 [$] is 📦 v0.15.4 via 🐍 v3.14.2 via 🦀 v1.93.0
❯ echo 'x = id' | uvx ruff@latest --isolated check - --preview --select ANN003,PLR1712
error: Ruff crashed. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BPanic%5D
...quoting the executed command, along with the relevant file contents and `pyproject.toml` settings, we'd be very appreciative!
thread 'main' (1681253) panicked at crates/ruff_python_semantic/src/definition.rs:285:26:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
~/astral/ruff on brent/0.15.4 [$] is 📦 v0.15.4 via 🐍 v3.14.2 via 🦀 v1.93.0
❯ echo 'x = id' | just run --isolated check - --preview --select ANN003,PLR1712
cargo run -p ruff -- --isolated check - --preview --select ANN003,PLR1712
Compiling ruff_python_semantic v0.0.0 (/home/brent/astral/ruff/crates/ruff_python_semantic)
Compiling ruff v0.15.4 (/home/brent/astral/ruff/crates/ruff)
Compiling ruff_linter v0.15.4 (/home/brent/astral/ruff/crates/ruff_linter)
Compiling ruff_graph v0.1.0 (/home/brent/astral/ruff/crates/ruff_graph)
Compiling ruff_workspace v0.0.0 (/home/brent/astral/ruff/crates/ruff_workspace)
Compiling ruff_markdown v0.0.0 (/home/brent/astral/ruff/crates/ruff_markdown)
Compiling ruff_server v0.2.2 (/home/brent/astral/ruff/crates/ruff_server)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 23.14s
Running `target/debug/ruff --isolated check - --preview --select ANN003,PLR1712`
warning: Detected debug build without --no-cache.
All checks passed!
```