## Summary
Today, if a CI job exports `FORCE_COLOR=1`, running `NO_COLOR=1 ruff
check .` still prints colored diagnostics. The same happens with `ty
check`. Giving a non-empty `NO_COLOR` priority lets users request plain
output without having to unset a variable inherited from their
environment. This matches how uv and the Python interpreter resolve that
conflict. Users who want color for one command can still pass
`--color=always`. [uv’s
resolver](https://github.com/astral-sh/uv/blob/39a02a0d9085f14dc3d5aa8655ac010a1fd377f8/crates/uv-cli/src/settings.rs#L172-L197)
· [Python’s color
precedence](https://docs.python.org/3/using/cmdline.html#controlling-color)
Previously, the shared resolver turned `FORCE_COLOR` into an override
before `colored` could honor `NO_COLOR`. The resolver now handles the
color environment for both tools, and `colored` styles diagnostics on
stdout according to that decision. The first matching rule wins.
1. Use an explicit `--color=always` or `--color=never`.
2. A non-empty `NO_COLOR` disables color.
3. A non-empty `FORCE_COLOR` or `CLICOLOR_FORCE` enables color,
including in a pipe.
4. If stdout is a pipe or file, disable color.
5. On a terminal, enable color if `CLICOLOR` is non-empty or `TERM` is
anything other than `dumb` (including unset).
All four color variables treat `0` as non-empty and an empty string as
unset. In particular, `FORCE_COLOR=""` previously disabled color. It now
lets the remaining settings and terminal detection decide.
## Comparison with the upstream conventions
- The [`NO_COLOR` convention](https://no-color.org/) specifies that a
non-empty value disables color by default and that command-line options
can override it. It gives no rule for a conflict with `FORCE_COLOR`. Its
FAQ also limits the convention to color, while Ruff and ty suppress
other diagnostic styling, such as bold text, when color is disabled.
- The [`FORCE_COLOR` convention](https://force-color.org/) specifies
that any non-empty value enables color, even in a pipe. Its example
applies `FORCE_COLOR` last, so the example produces colored output when
both variables are set. Here we follow uv and CPython in giving
`NO_COLOR` priority.
- The [CLICOLORS specification](https://bixense.com/clicolors/) gives
`NO_COLOR` priority over `CLICOLOR_FORCE` and makes `CLICOLOR` a
terminal-only request. We follow those rules, add `FORCE_COLOR` as an
alias for `CLICOLOR_FORCE`, and use `TERM=dumb` for the default the spec
leaves to applications.
## Comparison with uv
When `--color` is omitted, uv also checks non-empty `NO_COLOR` before
either force variable. In Ruff and ty, passing `--color=auto` has the
same effect as omitting it. In uv, passing it delegates the decision to
`anstream`, which recognizes `CLICOLOR_FORCE` but ignores `FORCE_COLOR`.
The terminal heuristics also differ: uv delegates to anstream, which
handles `TERM=dumb` differently depending on which platform uv is being
run on, and also honours the `CI` variable. I'd prefer not to have
platform-dependent behaviour or to have behaviour automatically be
different in CI; that feels too confusing/magical to me. [uv’s
resolver](https://github.com/astral-sh/uv/blob/39a02a0d9085f14dc3d5aa8655ac010a1fd377f8/crates/uv-cli/src/settings.rs#L172-L197)
· [`anstream`
detection](https://docs.rs/anstream/1.0.0/src/anstream/auto.rs.html#198-219)
· [`anstyle-query` environment
checks](https://docs.rs/anstyle-query/1.1.5/src/anstyle_query/lib.rs.html#23-82)
Each example assumes other color settings are unset.
| Case | Ruff and ty with this change | uv |
| --- | --- | --- |
| `FORCE_COLOR=1` with `--color=auto`, output piped | Colored, as when
the flag is omitted | Plain |
| `CLICOLOR=0 TERM=xterm`, on a terminal | Colored | Plain |
| `CLICOLOR="" TERM=dumb`, on a terminal | Plain | Colored |
| `CI=1 TERM=dumb`, on a terminal | Plain | Colored |
| `TERM` unset, on a terminal | Colored on all platforms | Plain on
non-Windows platforms, colored on Windows |
An empty `TERM` allows color on a terminal in both implementations.
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>
## Summary
Improves discoverability of `pydocstyle` convention-based rule filtering
by moving the authoritative documentation from the FAQ into the
`lint.pydocstyle.convention` settings reference, per #15217.
Closes#15217.
## Test Plan
Documentation-only change no functional code modifications.
Verification steps:
1. Ran `cargo dev generate-docs` to regenerate `docs/settings.md` and
`ruff.schema.json` from updated docstrings
2. Ran `cargo fmt --all` to ensure Rust formatting compliance
3. Ran `cargo clippy --workspace --all-targets --all-features -- -D
warnings` - no new warnings
4. Served docs locally with `uvx --with-requirements
docs/requirements.txt -- mkdocs serve -f mkdocs.yml` and verified:
- The `lint.pydocstyle.convention` section renders with the new content
- The FAQ back-reference links to the settings section as intended
## Screenshots
### `/ruff/settings/#lint.pydocstyle`
<img width="1920" height="957" alt="image"
src="https://github.com/user-attachments/assets/d35e94a0-0968-43fb-bfe5-dd2821655716"
/>
### `/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings`
<img width="1920" height="952" alt="image"
src="https://github.com/user-attachments/assets/b8904757-f7c9-43c7-ac20-e0fbdb713acd"
/>
---------
Signed-off-by: RafaelJohn9 <rafaeljohb@gmail.com>
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
This stabilizes the behavior introduced in #16565 which (roughly) tries
to match an import like `import a.b.c` to an actual directory path
`a/b/c` in order to label it as first-party, rather than simply looking
for a directory `a`.
Mainly this affects the sorting of imports in the presence of namespace
packages, but a few other rules are affected as well.
## Summary
D413 in this section was incorrectly linking to D410.
I haven't checked if this issue happens anywhere else in the docs.
## Test Plan
Look at docs
When attempting to determine whether `import foo.bar.baz` is a known
first-party import relative to [user-provided source
paths](https://docs.astral.sh/ruff/settings/#src), when `preview` is
enabled we now check that `SRC/foo/bar/baz` is a directory or
`SRC/foo/bar/baz.py` or `SRC/foo/bar/baz.pyi` exist.
Previously, we just checked the analogous thing for `SRC/foo`, but this
can be misleading in situations with disjoint namespace packages that
share a common base name (e.g. we may be working inside the namespace
package `foo.buzz` and importing `foo.bar` from elsewhere).
Supersedes #12987Closes#12984
## Summary
Occasionally, we receive bug reports that imports in `src` directories
aren't correctly detected. The root of the problem is that we default to
`src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR
extends the default to cover _both_ of them: `src = [".", "src"]`.
Closes https://github.com/astral-sh/ruff/issues/12454.
## Test Plan
I replicated the structure described in
https://github.com/astral-sh/ruff/issues/12453, and verified that the
imports were considered sorted, but that adding `src = ["."]` showed an
error.
Fixes#5499
## Summary
Add support for `FORCE_COLOR` env var, as specified at
https://force-color.org/
## Test Plan
I wrote an integration test for this, and then realized that can't work,
since we use a dev-dependency on `colored` with the `no-color` feature
to avoid ANSI color codes in test snapshots.
So this is just tested manually.
`cargo run --features test-rules -- check --no-cache --isolated -
--select RUF901 --diff < /dev/null` shows a colored diff.
`cargo run --features test-rules -- check --no-cache --isolated -
--select RUF901 --diff < /dev/null | less` does not have color, since we
pipe it to `less`.
`FORCE_COLOR=1 cargo run --features test-rules -- check --no-cache
--isolated - --select RUF901 --diff < /dev/null | less` does have color
(after this diff), even though we pipe it to `less`.
Section about comparing Ruff to PyLint now is more precise about the
following two points:
- Ruff do count branches different and there for earlier give
too-many-branches warning.
- Activating all Pylint rules in Ruff also activates pylint rules that
are not active by default in Pylint itself because they are implemented
via pylint plugins.
This ensures the python label is used for all python code blocks for
consistency.
## Test Plan
Visual inspection of all changes via git client ensuring no other
changes were made in error.
## Summary
This PR updates our documentation for the upcoming formatter release.
Broadly, the documentation is now structured as follows:
- Overview
- Tutorial
- Installing Ruff
- The Ruff Linter
- Overview
- `ruff check`
- Rule selection
- Error suppression
- Exit codes
- The Ruff Formatter
- Overview
- `ruff format`
- Philosophy
- Configuration
- Format suppression
- Exit codes
- Black compatibility
- Known deviations
- Configuring Ruff
- pyproject.toml
- File discovery
- Configuration discovery
- CLI
- Shell autocompletion
- Preview
- Rules
- Settings
- Integrations
- `pre-commit`
- VS Code
- LSP
- PyCharm
- GitHub Actions
- FAQ
- Contributing
The major changes include:
- Removing the "Usage" section from the docs, and instead folding that
information into "Integrations" and the new Linter and Formatter
sections.
- Breaking up "Configuration" into "Configuring Ruff" (for generic
configuration), and new Linter- and Formatter-specific sections.
- Updating all example configurations to use `[tool.ruff.lint]` and
`[tool.ruff.format]`.
My suggestion is to pull and build the docs locally, and review by
reading them in the browser rather than trying to parse all the code
changes.
Closes https://github.com/astral-sh/ruff/issues/7235.
Closes https://github.com/astral-sh/ruff/issues/7647.
Closes https://github.com/astral-sh/ruff/issues/7572
Drops formatting specific rules from the default rule set as they
conflict with formatters in general (and in particular, conflict with
our formatter). Most of these rules are in preview, but the removal of
`line-too-long` and `mixed-spaces-and-tabs` is a change to the stable
rule set.
## Example
The following no longer raises `E501`
```
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1" | ruff check -
```
## Summary
We're planning to move the documentation from
[https://beta.ruff.rs/docs](https://beta.ruff.rs/docs) to
[https://docs.astral.sh/ruff](https://docs.astral.sh/ruff), for a few
reasons:
1. We want to remove the `beta` from the domain, as Ruff is no longer
considered beta software.
2. We want to migrate to a structure that could accommodate multiple
future tools living under one domain.
The docs are actually already live at
[https://docs.astral.sh/ruff](https://docs.astral.sh/ruff), but later
today, I'll add a permanent redirect from the previous to the new
domain. **All existing links will continue to work, now and in
perpetuity.**
This PR contains the code changes necessary for the updated
documentation. As part of this effort, I moved the playground and
documentation from my personal Cloudflare account to our team Cloudflare
account (hence the new `--project-name` references). After merging, I'll
also update the secrets on this repo.