Promote lint. settings over top-level settings (#9476)

This commit is contained in:
Micha Reiser 2024-01-29 18:42:30 +01:00 committed by Zanie Blue
parent 6996ff7b1e
commit c3b33e9c4d
62 changed files with 389 additions and 310 deletions

View file

@ -321,16 +321,16 @@ leading to [`line-too-long`](rules/line-too-long.md) (`E501`) errors.
None of the above are included in Ruff's default configuration. However, if you've enabled
any of these rules or their parent categories (like `Q`), we recommend disabling them via the
linter's [`ignore`](settings.md#ignore) setting.
linter's [`lint.ignore`](settings.md#lint_ignore) setting.
Similarly, we recommend avoiding the following isort settings, which are incompatible with the
formatter's treatment of import statements when set to non-default values:
- [`force-single-line`](settings.md#isort-force-single-line)
- [`force-wrap-aliases`](settings.md#isort-force-wrap-aliases)
- [`lines-after-imports`](settings.md#isort-lines-after-imports)
- [`lines-between-types`](settings.md#isort-lines-between-types)
- [`split-on-trailing-comma`](settings.md#isort-split-on-trailing-comma)
- [`force-single-line`](settings.md#lint_isort_force-single-line)
- [`force-wrap-aliases`](settings.md#lint_isort_force-wrap-aliases)
- [`lines-after-imports`](settings.md#lint_isort_lines-after-imports)
- [`lines-between-types`](settings.md#lint_isort_lines-between-types)
- [`split-on-trailing-comma`](settings.md#lint_isort_split-on-trailing-comma)
If you've configured any of these settings to take on non-default values, we recommend removing
them from your Ruff configuration.

View file

@ -24,14 +24,14 @@ For the full list of supported options, run `ruff check --help`.
## Rule selection
The set of enabled rules is controlled via the [`select`](settings.md#select),
[`extend-select`](settings.md#extend-select), and [`ignore`](settings.md#ignore) settings.
The set of enabled rules is controlled via the [`lint.select`](settings.md#lint_select),
[`lint.extend-select`](settings.md#lint_extend-select), and [`lint.ignore`](settings.md#lint_ignore) settings.
Ruff's linter mirrors Flake8's rule code system, in which each rule code consists of a one-to-three
letter prefix, followed by three digits (e.g., `F401`). The prefix indicates that "source" of the rule
(e.g., `F` for Pyflakes, `E` for pycodestyle, `ANN` for flake8-annotations).
Rule selectors like [`select`](settings.md#select) and [`ignore`](settings.md#ignore) accept either
Rule selectors like [`lint.select`](settings.md#lint_select) and [`lint.ignore`](settings.md#lint_ignore) accept either
a full rule code (e.g., `F401`) or any valid prefix (e.g., `F`). For example, given the following
configuration file:
@ -60,7 +60,7 @@ formats. Ruff will automatically disable any conflicting rules when `ALL` is ena
If you're wondering how to configure Ruff, here are some **recommended guidelines**:
- Prefer [`select`](settings.md#select) over [`extend-select`](settings.md#extend-select) to make your rule set explicit.
- Prefer [`lint.select`](settings.md#lint_select) over [`lint.extend-select`](settings.md#lint_extend-select) to make your rule set explicit.
- Use `ALL` with discretion. Enabling `ALL` will implicitly enable new rules whenever you upgrade.
- Start with a small set of rules (`select = ["E", "F"]`) and add a category at-a-time. For example,
you might consider expanding to `select = ["E", "F", "B"]` to enable the popular flake8-bugbear
@ -109,13 +109,13 @@ pedantic) might look like the following:
]
```
To resolve the enabled rule set, Ruff may need to reconcile [`select`](settings.md#select) and
[`ignore`](settings.md#ignore) from a variety of sources, including the current `pyproject.toml`,
any inherited `pyproject.toml` files, and the CLI (e.g., [`--select`](settings.md#select)).
To resolve the enabled rule set, Ruff may need to reconcile [`lint.select`](settings.md#lint_select) and
[`lint.ignore`](settings.md#lint_ignore) from a variety of sources, including the current `pyproject.toml`,
any inherited `pyproject.toml` files, and the CLI (e.g., [`--select`](settings.md#lint_select)).
In those scenarios, Ruff uses the "highest-priority" [`select`](settings.md#select) as the basis for
the rule set, and then applies [`extend-select`](settings.md#extend-select) and
[`ignore`](settings.md#ignore) adjustments. CLI options are given higher priority than
In those scenarios, Ruff uses the "highest-priority" [`select`](settings.md#lint_select) as the basis for
the rule set, and then applies [`extend-select`](settings.md#lint_extend-select) and
[`ignore`](settings.md#lint_ignore) adjustments. CLI options are given higher priority than
`pyproject.toml` options, and the current `pyproject.toml` file is given higher priority than any
inherited `pyproject.toml` files.
@ -233,9 +233,9 @@ You may use prefixes to select rules as well, e.g., `F` can be used to promote f
### Disabling fixes
To limit the set of rules that Ruff should fix, use the [`fixable`](settings.md#fixable) and
[`unfixable`](settings.md#unfixable) settings, along with their [`extend-fixable`](settings.md#extend-fixable)
and [`extend-unfixable`](settings.md#extend-unfixable) variants.
To limit the set of rules that Ruff should fix, use the [`lint.fixable`](settings.md#lint_fixable) and
[`lint.unfixable`](settings.md#lint_unfixable) settings, along with their [`lint.extend-fixable`](settings.md#lint_extend-fixable)
and [`lint.extend-unfixable`](settings.md#lint_extend-unfixable) variants.
For example, the following configuration would enable fixes for all rules except
[`unused-imports`](rules/unused-import.md) (`F401`):
@ -277,7 +277,7 @@ Conversely, the following configuration would only enable fixes for `F401`:
Ruff supports several mechanisms for suppressing lint errors, be they false positives or
permissible violations.
To omit a lint rule entirely, add it to the "ignore" list via the [`ignore`](settings.md#ignore)
To omit a lint rule entirely, add it to the "ignore" list via the [`lint.ignore`](settings.md#lint_ignore)
setting, either on the command-line or in your `pyproject.toml` or `ruff.toml` file.
To suppress a violation inline, Ruff uses a `noqa` system similar to [Flake8](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html).
@ -326,7 +326,7 @@ file, preferably towards the top, like so:
# ruff: noqa: F841
```
Or see the [`per-file-ignores`](settings.md#per-file-ignores) setting, which enables the same
Or see the [`lint.per-file-ignores`](settings.md#lint_per-file-ignores) setting, which enables the same
functionality from within your `pyproject.toml` or `ruff.toml` file.
Global `noqa` comments must be on their own line to disambiguate from comments which ignore