mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Use tool.ruff.lint
in more places (#8317)
## Summary As a follow-up of https://github.com/astral-sh/ruff/pull/7732, use `tool.ruff.lint` in more places in documentations, tests and internal usages.
This commit is contained in:
parent
2f5734d1ac
commit
317b6e8682
11 changed files with 60 additions and 45 deletions
|
@ -1,7 +1,7 @@
|
|||
[tool.ruff]
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff.isort]
|
||||
[tool.ruff.lint.isort]
|
||||
lines-after-imports = 3
|
||||
lines-between-types = 2
|
||||
known-local-folder = ["ruff"]
|
||||
|
|
|
@ -5,4 +5,6 @@ extend-exclude = [
|
|||
"migrations",
|
||||
"with_excluded_file/other_excluded_file.py",
|
||||
]
|
||||
|
||||
[tool.ruff.lint]
|
||||
per-file-ignores = { "__init__.py" = ["F401"] }
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
[tool.ruff]
|
||||
src = [".", "python_modules/*"]
|
||||
exclude = ["examples/excluded"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["I001"]
|
||||
extend-ignore = ["F841"]
|
||||
|
|
|
@ -265,7 +265,7 @@ impl Violation for MissingReturnTypePrivateFunction {
|
|||
/// or `ruff.toml` file:
|
||||
///
|
||||
/// ```toml
|
||||
/// [tool.ruff.flake8-annotations]
|
||||
/// [tool.ruff.lint.flake8-annotations]
|
||||
/// mypy-init-return = true
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -828,7 +828,7 @@ pub struct LintCommonOptions {
|
|||
value_type = "dict[str, list[RuleSelector]]",
|
||||
example = r#"
|
||||
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
|
||||
[tool.ruff.per-file-ignores]
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"__init__.py" = ["E402"]
|
||||
"path/to/file.py" = ["E402"]
|
||||
"#
|
||||
|
@ -842,7 +842,7 @@ pub struct LintCommonOptions {
|
|||
value_type = "dict[str, list[RuleSelector]]",
|
||||
example = r#"
|
||||
# Also ignore `E402` in all `__init__.py` files.
|
||||
[tool.ruff.extend-per-file-ignores]
|
||||
[tool.ruff.lint.extend-per-file-ignores]
|
||||
"__init__.py" = ["E402"]
|
||||
"#
|
||||
)]
|
||||
|
@ -1198,7 +1198,7 @@ pub struct Flake8ImportConventionsOptions {
|
|||
default = r#"{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "tkinter": "tk", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa"}"#,
|
||||
value_type = "dict[str, str]",
|
||||
example = r#"
|
||||
[tool.ruff.flake8-import-conventions.aliases]
|
||||
[tool.ruff.lint.flake8-import-conventions.aliases]
|
||||
# Declare the default aliases.
|
||||
altair = "alt"
|
||||
"matplotlib.pyplot" = "plt"
|
||||
|
@ -1216,7 +1216,7 @@ pub struct Flake8ImportConventionsOptions {
|
|||
default = r#"{}"#,
|
||||
value_type = "dict[str, str]",
|
||||
example = r#"
|
||||
[tool.ruff.flake8-import-conventions.extend-aliases]
|
||||
[tool.ruff.lint.flake8-import-conventions.extend-aliases]
|
||||
# Declare a custom alias for the `matplotlib` module.
|
||||
"dask.dataframe" = "dd"
|
||||
"#
|
||||
|
@ -1228,7 +1228,7 @@ pub struct Flake8ImportConventionsOptions {
|
|||
default = r#"{}"#,
|
||||
value_type = "dict[str, list[str]]",
|
||||
example = r#"
|
||||
[tool.ruff.flake8-import-conventions.banned-aliases]
|
||||
[tool.ruff.lint.flake8-import-conventions.banned-aliases]
|
||||
# Declare the banned aliases.
|
||||
"tensorflow.keras.backend" = ["K"]
|
||||
"#
|
||||
|
@ -1541,7 +1541,7 @@ pub struct Flake8TidyImportsOptions {
|
|||
default = r#"{}"#,
|
||||
value_type = r#"dict[str, { "msg": str }]"#,
|
||||
example = r#"
|
||||
[tool.ruff.flake8-tidy-imports.banned-api]
|
||||
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
||||
"cgi".msg = "The cgi module is deprecated, see https://peps.python.org/pep-0594/#cgi."
|
||||
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."
|
||||
"#
|
||||
|
@ -1994,7 +1994,7 @@ pub struct IsortOptions {
|
|||
value_type = "dict[str, list[str]]",
|
||||
example = r#"
|
||||
# Group all Django imports into a separate section.
|
||||
[tool.ruff.isort.sections]
|
||||
[tool.ruff.lint.isort.sections]
|
||||
"django" = ["django"]
|
||||
"#
|
||||
)]
|
||||
|
@ -2376,7 +2376,7 @@ pub struct PydocstyleOptions {
|
|||
/// documentation for every function parameter:
|
||||
///
|
||||
/// ```toml
|
||||
/// [tool.ruff]
|
||||
/// [tool.ruff.lint]
|
||||
/// # Enable all `pydocstyle` rules, limiting to those that adhere to the
|
||||
/// # Google convention via `convention = "google"`, below.
|
||||
/// select = ["D"]
|
||||
|
@ -2385,7 +2385,7 @@ pub struct PydocstyleOptions {
|
|||
/// # documentation for every function parameter.
|
||||
/// ignore = ["D417"]
|
||||
///
|
||||
/// [tool.ruff.pydocstyle]
|
||||
/// [tool.ruff.lint.pydocstyle]
|
||||
/// convention = "google"
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -161,7 +161,7 @@ mod tests {
|
|||
use ruff_linter::line_width::LineLength;
|
||||
use ruff_linter::settings::types::PatternPrefixPair;
|
||||
|
||||
use crate::options::{LintCommonOptions, Options};
|
||||
use crate::options::{LintCommonOptions, LintOptions, Options};
|
||||
use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools};
|
||||
use crate::tests::test_resource_path;
|
||||
|
||||
|
@ -228,7 +228,7 @@ exclude = ["foo.py"]
|
|||
let pyproject: Pyproject = toml::from_str(
|
||||
r#"
|
||||
[tool.black]
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
select = ["E501"]
|
||||
"#,
|
||||
)?;
|
||||
|
@ -236,10 +236,13 @@ select = ["E501"]
|
|||
pyproject.tool,
|
||||
Some(Tools {
|
||||
ruff: Some(Options {
|
||||
lint_top_level: LintCommonOptions {
|
||||
lint: Some(LintOptions {
|
||||
common: LintCommonOptions {
|
||||
select: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
..LintCommonOptions::default()
|
||||
},
|
||||
..LintOptions::default()
|
||||
}),
|
||||
..Options::default()
|
||||
})
|
||||
})
|
||||
|
@ -248,7 +251,7 @@ select = ["E501"]
|
|||
let pyproject: Pyproject = toml::from_str(
|
||||
r#"
|
||||
[tool.black]
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["RUF100"]
|
||||
ignore = ["E501"]
|
||||
"#,
|
||||
|
@ -257,11 +260,14 @@ ignore = ["E501"]
|
|||
pyproject.tool,
|
||||
Some(Tools {
|
||||
ruff: Some(Options {
|
||||
lint_top_level: LintCommonOptions {
|
||||
lint: Some(LintOptions {
|
||||
common: LintCommonOptions {
|
||||
extend_select: Some(vec![codes::Ruff::_100.into()]),
|
||||
ignore: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
..LintCommonOptions::default()
|
||||
},
|
||||
..LintOptions::default()
|
||||
}),
|
||||
..Options::default()
|
||||
})
|
||||
})
|
||||
|
@ -279,7 +285,7 @@ line_length = 79
|
|||
assert!(toml::from_str::<Pyproject>(
|
||||
r#"
|
||||
[tool.black]
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
select = ["E123"]
|
||||
"#,
|
||||
)
|
||||
|
@ -315,13 +321,16 @@ other-attribute = 1
|
|||
"with_excluded_file/other_excluded_file.py".to_string(),
|
||||
]),
|
||||
|
||||
lint_top_level: LintCommonOptions {
|
||||
lint: Some(LintOptions {
|
||||
common: LintCommonOptions {
|
||||
per_file_ignores: Some(FxHashMap::from_iter([(
|
||||
"__init__.py".to_string(),
|
||||
vec![codes::Pyflakes::_401.into()]
|
||||
)])),
|
||||
..LintCommonOptions::default()
|
||||
},
|
||||
..LintOptions::default()
|
||||
}),
|
||||
..Options::default()
|
||||
}
|
||||
);
|
||||
|
|
12
docs/faq.md
12
docs/faq.md
|
@ -261,7 +261,7 @@ them. You can find the supported settings in the [API reference](settings.md#iso
|
|||
For example, you can set `known-first-party` like so:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
# Pyflakes
|
||||
"F",
|
||||
|
@ -275,7 +275,7 @@ select = [
|
|||
# Note: Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||
src = ["src", "tests"]
|
||||
|
||||
[tool.ruff.isort]
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["my_module1", "my_module2"]
|
||||
```
|
||||
|
||||
|
@ -375,7 +375,7 @@ Found 3 errors.
|
|||
Yes! To enforce a docstring convention, add the following to your `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.ruff.pydocstyle]
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google" # Accepts: "google", "numpy", or "pep257".
|
||||
```
|
||||
|
||||
|
@ -387,12 +387,12 @@ Alongside `convention`, you'll want to explicitly enable the `D` rule code prefi
|
|||
rules are not enabled by default:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
"D",
|
||||
]
|
||||
|
||||
[tool.ruff.pydocstyle]
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google"
|
||||
```
|
||||
|
||||
|
@ -423,7 +423,7 @@ For example, given this `pyproject.toml`:
|
|||
[tool.ruff]
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff.pydocstyle]
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google"
|
||||
```
|
||||
|
||||
|
|
|
@ -32,28 +32,28 @@ hypothetical rule, `HYP001`. If `HYP001` were in preview, it would _not_ be enab
|
|||
`pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["HYP001"]
|
||||
```
|
||||
|
||||
It also would _not_ be enabled by selecting the `HYP` category, like so:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["HYP"]
|
||||
```
|
||||
|
||||
Similarly, it would _not_ be enabled via the `ALL` selector:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
select = ["ALL"]
|
||||
```
|
||||
|
||||
However, it would be enabled in any of the above cases if you enabled preview in your configuration file:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["HYP"]
|
||||
preview = true
|
||||
```
|
||||
|
@ -69,7 +69,7 @@ If you'd prefer to opt-in to each preview rule individually, you can toggle the
|
|||
setting in your `pyproject.toml`:
|
||||
|
||||
```toml
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
preview = true
|
||||
explicit-preview-rules = true
|
||||
```
|
||||
|
|
|
@ -10,6 +10,6 @@ dependencies = ["unidiff==0.7.5"]
|
|||
[project.scripts]
|
||||
ruff-ecosystem = "ruff_ecosystem.cli:entrypoint"
|
||||
|
||||
[tool.ruff]
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["I"]
|
||||
preview = true
|
||||
|
|
2
ruff.schema.json
generated
2
ruff.schema.json
generated
|
@ -2241,7 +2241,7 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"convention": {
|
||||
"description": "Whether to use Google-style or NumPy-style conventions or the [PEP 257](https://peps.python.org/pep-0257/) defaults when analyzing docstring sections.\n\nEnabling a convention will force-disable any rules that are not included in the specified convention. As such, the intended use is to enable a convention and then selectively disable any additional rules on top of it.\n\nFor example, to use Google-style conventions but avoid requiring documentation for every function parameter:\n\n```toml [tool.ruff] # Enable all `pydocstyle` rules, limiting to those that adhere to the # Google convention via `convention = \"google\"`, below. select = [\"D\"]\n\n# On top of the Google convention, disable `D417`, which requires # documentation for every function parameter. ignore = [\"D417\"]\n\n[tool.ruff.pydocstyle] convention = \"google\" ```\n\nAs conventions force-disable all rules not included in the convention, enabling _additional_ rules on top of a convention is currently unsupported.",
|
||||
"description": "Whether to use Google-style or NumPy-style conventions or the [PEP 257](https://peps.python.org/pep-0257/) defaults when analyzing docstring sections.\n\nEnabling a convention will force-disable any rules that are not included in the specified convention. As such, the intended use is to enable a convention and then selectively disable any additional rules on top of it.\n\nFor example, to use Google-style conventions but avoid requiring documentation for every function parameter:\n\n```toml [tool.ruff.lint] # Enable all `pydocstyle` rules, limiting to those that adhere to the # Google convention via `convention = \"google\"`, below. select = [\"D\"]\n\n# On top of the Google convention, disable `D417`, which requires # documentation for every function parameter. ignore = [\"D417\"]\n\n[tool.ruff.lint.pydocstyle] convention = \"google\" ```\n\nAs conventions force-disable all rules not included in the convention, enabling _additional_ rules on top of a convention is currently unsupported.",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Convention"
|
||||
|
|
|
@ -9,6 +9,8 @@ line-length = 88
|
|||
|
||||
[tool.ruff]
|
||||
line-length = 88
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["ALL"]
|
||||
ignore = [
|
||||
"C901", # McCabe complexity
|
||||
|
@ -22,5 +24,5 @@ ignore = [
|
|||
"ANN401",
|
||||
]
|
||||
|
||||
[tool.ruff.isort]
|
||||
[tool.ruff.lint.isort]
|
||||
required-imports = ["from __future__ import annotations"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue