Skip to content

Commit

Permalink
Use tool.ruff.lint in more places (#8317)
Browse files Browse the repository at this point in the history
## Summary

As a follow-up of #7732, use
`tool.ruff.lint` in more places in documentations, tests and internal
usages.
  • Loading branch information
mkniewallner authored Oct 28, 2023
1 parent 2f5734d commit 317b6e8
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ extend-exclude = [
"migrations",
"with_excluded_file/other_excluded_file.py",
]

[tool.ruff.lint]
per-file-ignores = { "__init__.py" = ["F401"] }
2 changes: 2 additions & 0 deletions crates/ruff_linter/resources/test/project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[tool.ruff]
src = [".", "python_modules/*"]
exclude = ["examples/excluded"]

[tool.ruff.lint]
extend-select = ["I001"]
extend-ignore = ["F841"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// ```
///
Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
"#
Expand All @@ -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"]
"#
)]
Expand Down Expand Up @@ -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"
Expand All @@ -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"
"#
Expand All @@ -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"]
"#
Expand Down Expand Up @@ -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."
"#
Expand Down Expand Up @@ -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"]
"#
)]
Expand Down Expand Up @@ -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"]
Expand All @@ -2385,7 +2385,7 @@ pub struct PydocstyleOptions {
/// # documentation for every function parameter.
/// ignore = ["D417"]
///
/// [tool.ruff.pydocstyle]
/// [tool.ruff.lint.pydocstyle]
/// convention = "google"
/// ```
///
Expand Down
49 changes: 29 additions & 20 deletions crates/ruff_workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -228,18 +228,21 @@ exclude = ["foo.py"]
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
[tool.ruff.lint]
select = ["E501"]
"#,
)?;
assert_eq!(
pyproject.tool,
Some(Tools {
ruff: Some(Options {
lint_top_level: LintCommonOptions {
select: Some(vec![codes::Pycodestyle::E501.into()]),
..LintCommonOptions::default()
},
lint: Some(LintOptions {
common: LintCommonOptions {
select: Some(vec![codes::Pycodestyle::E501.into()]),
..LintCommonOptions::default()
},
..LintOptions::default()
}),
..Options::default()
})
})
Expand All @@ -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"]
"#,
Expand All @@ -257,11 +260,14 @@ ignore = ["E501"]
pyproject.tool,
Some(Tools {
ruff: Some(Options {
lint_top_level: LintCommonOptions {
extend_select: Some(vec![codes::Ruff::_100.into()]),
ignore: Some(vec![codes::Pycodestyle::E501.into()]),
..LintCommonOptions::default()
},
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()
})
})
Expand All @@ -279,7 +285,7 @@ line_length = 79
assert!(toml::from_str::<Pyproject>(
r#"
[tool.black]
[tool.ruff]
[tool.ruff.lint]
select = ["E123"]
"#,
)
Expand Down Expand Up @@ -315,13 +321,16 @@ other-attribute = 1
"with_excluded_file/other_excluded_file.py".to_string(),
]),

lint_top_level: LintCommonOptions {
per_file_ignores: Some(FxHashMap::from_iter([(
"__init__.py".to_string(),
vec![codes::Pyflakes::_401.into()]
)])),
..LintCommonOptions::default()
},
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()
}
);
Expand Down
12 changes: 6 additions & 6 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
```

Expand Down Expand Up @@ -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".
```

Expand All @@ -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"
```

Expand Down Expand Up @@ -423,7 +423,7 @@ For example, given this `pyproject.toml`:
[tool.ruff]
line-length = 88

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"
```

Expand Down
10 changes: 5 additions & 5 deletions docs/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion python/ruff-ecosystem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion scripts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ line-length = 88

[tool.ruff]
line-length = 88

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"C901", # McCabe complexity
Expand All @@ -22,5 +24,5 @@ ignore = [
"ANN401",
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

0 comments on commit 317b6e8

Please sign in to comment.