diff --git a/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml index 63e7153b20c7d..620a79b7a002f 100644 --- a/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml @@ -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"] diff --git a/crates/ruff_linter/resources/test/fixtures/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/pyproject.toml index 5525b69dea8a5..6a2564d488950 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/pyproject.toml @@ -5,4 +5,6 @@ extend-exclude = [ "migrations", "with_excluded_file/other_excluded_file.py", ] + +[tool.ruff.lint] per-file-ignores = { "__init__.py" = ["F401"] } diff --git a/crates/ruff_linter/resources/test/project/pyproject.toml b/crates/ruff_linter/resources/test/project/pyproject.toml index a4e950134416b..86e2d51f0ddf3 100644 --- a/crates/ruff_linter/resources/test/project/pyproject.toml +++ b/crates/ruff_linter/resources/test/project/pyproject.toml @@ -1,5 +1,7 @@ [tool.ruff] src = [".", "python_modules/*"] exclude = ["examples/excluded"] + +[tool.ruff.lint] extend-select = ["I001"] extend-ignore = ["F841"] diff --git a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs index 1db658efef269..e667fa25328ec 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs @@ -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 /// ``` /// diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index b065f22b39e38..5884bfa0a12b9 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -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" /// ``` /// diff --git a/crates/ruff_workspace/src/pyproject.rs b/crates/ruff_workspace/src/pyproject.rs index 38b7811dd634f..7080df65c9ac0 100644 --- a/crates/ruff_workspace/src/pyproject.rs +++ b/crates/ruff_workspace/src/pyproject.rs @@ -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 { - 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() }) }) @@ -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 { - 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() }) }) @@ -279,7 +285,7 @@ line_length = 79 assert!(toml::from_str::( 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 { - 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() } ); diff --git a/docs/faq.md b/docs/faq.md index 0eb4a5aa1d20b..2194b09c25e18 100644 --- a/docs/faq.md +++ b/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" ``` diff --git a/docs/preview.md b/docs/preview.md index ccb04bb02428f..3e1faab110bd1 100644 --- a/docs/preview.md +++ b/docs/preview.md @@ -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 ``` diff --git a/python/ruff-ecosystem/pyproject.toml b/python/ruff-ecosystem/pyproject.toml index 8bff7a17060b8..68d8e2a953a7c 100644 --- a/python/ruff-ecosystem/pyproject.toml +++ b/python/ruff-ecosystem/pyproject.toml @@ -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 diff --git a/ruff.schema.json b/ruff.schema.json index 5a6f12aeabf91..82500eadbda0a 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -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" diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 1a3a318a1a36a..e3fe79432f7bd 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -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"]