From ef66597020db601e12c7504d89925db0a8e7a723 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 19 Oct 2023 10:14:12 +0900 Subject: [PATCH] remove line-width option from LinterSettings --- .../rules/flake8_simplify/rules/ast_with.rs | 2 +- .../flake8_simplify/rules/collapsible_if.rs | 2 +- .../if_else_block_instead_of_dict_get.rs | 2 +- .../rules/if_else_block_instead_of_if_exp.rs | 2 +- .../rules/reimplemented_builtin.rs | 4 +-- .../src/rules/isort/rules/organize_imports.rs | 2 +- .../rules/pycodestyle/rules/line_too_long.rs | 1 + .../src/rules/pyupgrade/rules/f_strings.rs | 2 +- crates/ruff_linter/src/settings/mod.rs | 4 +-- crates/ruff_workspace/src/configuration.rs | 14 ++++++---- crates/ruff_workspace/src/options.rs | 28 +++++++++---------- ruff.schema.json | 2 +- 12 files changed, 34 insertions(+), 31 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs index b9183f2872667..10ac1f6ff271c 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs @@ -139,7 +139,7 @@ pub(crate) fn multiple_with_statements( content, with_stmt.into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) }) { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs index 0617589b8ff03..6fc1b6469437e 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/collapsible_if.rs @@ -128,7 +128,7 @@ pub(crate) fn nested_if_statements( content, (&nested_if).into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) }) { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs index 3d21d3caa930b..26df905ae8e91 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs @@ -182,7 +182,7 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &mut Checker, stmt_if: &contents, stmt_if.into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) { return; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs index 16a7db6b7bbe3..68ecf03b6ebe5 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs @@ -130,7 +130,7 @@ pub(crate) fn if_else_block_instead_of_if_exp(checker: &mut Checker, stmt_if: &a &contents, stmt_if.into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) { return; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 4bbc7e62359aa..7b16e4da02956 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -101,7 +101,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) { &contents, stmt.into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) { return; @@ -188,7 +188,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) { .slice(TextRange::new(line_start, stmt.start())), ) .add_str(&contents) - > checker.settings.line_width + > checker.settings.pycodestyle.max_line_width { return; } diff --git a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs index 2f362c2be9d1d..ce97b27eded3f 100644 --- a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs @@ -120,7 +120,7 @@ pub(crate) fn organize_imports( block, comments, locator, - settings.line_width, + settings.pycodestyle.max_line_width, LineWidthBuilder::new(settings.tab_size).add_str(indentation), stylist, &settings.src, diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs index 16a41294419b3..8442efa022ccd 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs @@ -47,6 +47,7 @@ use crate::settings::LinterSettings; /// /// ## Options /// - `line-width` +/// - `pycodestyle.max-line-width` /// - `task-tags` /// - `pycodestyle.ignore-overlong-task-comments` /// diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index 1478372d14011..24b96feb322f8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -399,7 +399,7 @@ pub(crate) fn f_strings( &contents, template.into(), checker.locator(), - checker.settings.line_width, + checker.settings.pycodestyle.max_line_width, checker.settings.tab_size, ) { return; diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 610a265c0800d..c72dc70b00b83 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -26,7 +26,7 @@ use crate::rules::{ use crate::settings::types::{FilePatternSet, PerFileIgnore, PythonVersion}; use crate::{codes, RuleSelector}; -use super::line_width::{LineWidth, TabSize}; +use super::line_width::TabSize; use self::rule_table::RuleTable; use self::types::PreviewMode; @@ -56,7 +56,6 @@ pub struct LinterSettings { pub dummy_variable_rgx: Regex, pub external: FxHashSet, pub ignore_init_module_imports: bool, - pub line_width: LineWidth, pub logger_objects: Vec, pub namespace_packages: Vec, pub src: Vec, @@ -147,7 +146,6 @@ impl LinterSettings { external: HashSet::default(), ignore_init_module_imports: false, - line_width: LineWidth::default(), logger_objects: vec![], namespace_packages: vec![], diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 0340ac1f8e091..75c5538d73c5e 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -21,6 +21,7 @@ use ruff_linter::line_width::{LineWidth, TabSize}; use ruff_linter::registry::RuleNamespace; use ruff_linter::registry::{Rule, RuleSet, INCOMPATIBLE_CODES}; use ruff_linter::rule_selector::{PreviewOptions, Specificity}; +use ruff_linter::rules::pycodestyle; use ruff_linter::settings::rule_table::RuleTable; use ruff_linter::settings::types::{ FilePattern, FilePatternSet, PerFileIgnore, PreviewMode, PythonVersion, SerializationFormat, @@ -225,7 +226,6 @@ impl Configuration { .unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()), external: FxHashSet::from_iter(lint.external.unwrap_or_default()), ignore_init_module_imports: lint.ignore_init_module_imports.unwrap_or_default(), - line_width, tab_size: self.tab_size.unwrap_or_default(), namespace_packages: self.namespace_packages.unwrap_or_default(), per_file_ignores: resolve_per_file_ignores( @@ -346,10 +346,14 @@ impl Configuration { .map(Pep8NamingOptions::try_into_settings) .transpose()? .unwrap_or_default(), - pycodestyle: lint - .pycodestyle - .map(|options| options.into_settings(line_width)) - .unwrap_or_default(), + pycodestyle: if let Some(pycodestyle) = lint.pycodestyle { + pycodestyle.into_settings(line_width) + } else { + pycodestyle::settings::Settings { + max_line_width: line_width, + ..pycodestyle::settings::Settings::default() + } + }, pydocstyle: lint .pydocstyle .map(PydocstyleOptions::into_settings) diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 8107c1ce6aa1a..61255ad427c8f 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -60,7 +60,7 @@ pub struct Options { /// this base configuration file, then merge in any properties defined /// in the current configuration file. #[option( - default = r#"None"#, + default = r#"null"#, value_type = "str", example = r#" # Extend the `pyproject.toml` file in the parent directory. @@ -132,7 +132,7 @@ pub struct Options { /// results across many environments, e.g., with a `pyproject.toml` /// file). #[option( - default = "None", + default = "null", value_type = "str", example = r#" required-version = "0.0.193" @@ -359,6 +359,8 @@ pub struct Options { /// /// Note: Formatted code may exceed the configured line width when it can't automatically /// split the line into shorter lines, e.g. because it is a too long comment or identifier. + /// + /// See [`pycodestyle.max-line-width`](#pycodestyle-max-line-width) to configure different limits for `E501` and the formatter. #[option( default = "88", value_type = "int", @@ -1062,7 +1064,7 @@ pub struct Flake8CopyrightOptions { /// Author to enforce within the copyright notice. If provided, the /// author must be present immediately following the copyright notice. - #[option(default = "None", value_type = "str", example = r#"author = "Ruff""#)] + #[option(default = "null", value_type = "str", example = r#"author = "Ruff""#)] pub author: Option, /// A minimum file size (in bytes) required for a copyright notice to @@ -2266,11 +2268,11 @@ impl Pep8NamingOptions { #[serde(deny_unknown_fields, rename_all = "kebab-case")] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct PycodestyleOptions { - /// The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`line-too-long`] violations. By default, + /// The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`line-too-long`](rules/line-too-long.md) violations. By default, /// this is set to the value of the global `line-width` option. /// - /// Overriding the global [`line-width`] allows to use a lower limit for Ruff's formatter and warn about - /// extra-long lines that can't be split by the formatter using [`line-too-long`]: + /// Overriding the global [`line-width`](#line-width) allows to use a lower limit for Ruff's formatter and warn about + /// extra-long lines that can't be split by the formatter using the [`line-too-long`](rules/line-too-long.md) rule: /// /// ```toml /// line-width = 88 # The formatter breaks line's with a width of 88. @@ -2279,9 +2281,7 @@ pub struct PycodestyleOptions { /// max-line-width = 100 # E501 reports lines that exceed the width of 100. /// ``` /// - /// [`line-too-long`]. - /// - /// See the [`line-too-long`](https://docs.astral.sh/ruff/rules/line-too-long/) rule for more information. + /// See the [`line-too-long`](rules/line-too-long.md) rule for more information. #[option( default = "null", value_type = "int", @@ -2291,11 +2291,11 @@ pub struct PycodestyleOptions { )] pub max_line_width: Option, - /// The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`doc-line-too-long`] violations within + /// The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`doc-line-too-long`](rules/doc-line-too-long.md) violations within /// documentation (`W505`), including standalone comments. By default, /// this is set to null which disables reporting violations. /// - /// See the [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) rule for more information. + /// See the [`doc-line-too-long`](rules/doc-line-too-long.md) rule for more information. #[option( default = "null", value_type = "int", @@ -2309,9 +2309,9 @@ pub struct PycodestyleOptions { /// documentation (`W505`), including standalone comments. By default, /// this is set to null which disables reporting violations. /// - /// See the [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) rule for more information. + /// See the [`doc-line-too-long`](rules/doc-line-too-long.md) rule for more information. #[option( - default = "None", + default = "null", value_type = "int", example = r#" max-doc-length = 88 @@ -2389,7 +2389,7 @@ pub struct PydocstyleOptions { /// enabling _additional_ rules on top of a convention is currently /// unsupported. #[option( - default = r#"None"#, + default = r#"null"#, value_type = r#""google" | "numpy" | "pep257""#, example = r#" # Use Google-style docstrings. diff --git a/ruff.schema.json b/ruff.schema.json index 3d2607e175c30..702beada32cf6 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -2231,7 +2231,7 @@ ] }, "max-line-width": { - "description": "The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`line-too-long`] violations. By default, this is set to the value of the global `line-width` option.\n\nOverriding the global [`line-width`] allows to use a lower limit for Ruff's formatter and warn about extra-long lines that can't be split by the formatter using [`line-too-long`]:\n\n```toml line-width = 88 # The formatter breaks line's with a width of 88.\n\n[pycodestyle] max-line-width = 100 # E501 reports lines that exceed the width of 100. ```\n\n[`line-too-long`].\n\nSee the [`line-too-long`](https://docs.astral.sh/ruff/rules/line-too-long/) rule for more information.", + "description": "The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`line-too-long`] violations. By default, this is set to the value of the global `line-width` option.\n\nOverriding the global [`line-width`](#line-width) allows to use a lower limit for Ruff's formatter and warn about extra-long lines that can't be split by the formatter using the [`line-too-long`](https://docs.astral.sh/ruff/rules/line-too-long/) rule:\n\n```toml line-width = 88 # The formatter breaks line's with a width of 88.\n\n[pycodestyle] max-line-width = 100 # E501 reports lines that exceed the width of 100. ```\n\nSee the [`line-too-long`](https://docs.astral.sh/ruff/rules/line-too-long/) rule for more information.", "anyOf": [ { "$ref": "#/definitions/LineWidth"