From 80457ca0b4802cb62513107a16686655c016989f Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 26 Oct 2023 10:05:10 +0900 Subject: [PATCH] Use `line-length` setting for isort --- crates/ruff_linter/src/rules/isort/rules/organize_imports.rs | 2 +- crates/ruff_linter/src/settings/mod.rs | 3 +++ crates/ruff_workspace/src/configuration.rs | 1 + crates/ruff_workspace/src/options.rs | 2 +- ruff.schema.json | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) 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 4b0e6c7afc8f4..e571271d08c00 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.pycodestyle.max_line_length, + settings.line_length, LineWidthBuilder::new(settings.tab_size).add_str(indentation), stylist, &settings.src, diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 199b4a490d607..6f36a5280c871 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -14,6 +14,7 @@ use rustc_hash::FxHashSet; use crate::codes::RuleCodePrefix; use ruff_macros::CacheKey; +use crate::line_width::LineLength; use crate::registry::{Linter, Rule, RuleSet}; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions, @@ -59,6 +60,7 @@ pub struct LinterSettings { pub namespace_packages: Vec, pub src: Vec, pub tab_size: IndentWidth, + pub line_length: LineLength, pub task_tags: Vec, pub typing_modules: Vec, @@ -155,6 +157,7 @@ impl LinterSettings { src: vec![path_dedot::CWD.clone()], // Needs duplicating tab_size: IndentWidth::default(), + line_length: LineLength::default(), task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(), typing_modules: vec![], diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 842dea912b062..0f7924531a388 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -228,6 +228,7 @@ impl Configuration { .unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()), external: lint.external.unwrap_or_default(), ignore_init_module_imports: lint.ignore_init_module_imports.unwrap_or_default(), + line_length, tab_size: self.indent_width.unwrap_or_default(), namespace_packages: self.namespace_packages.unwrap_or_default(), per_file_ignores: resolve_per_file_ignores( diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index e895a444f2521..db953f49e535f 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -352,7 +352,7 @@ pub struct Options { // Global Formatting options /// The line length to use when enforcing long-lines violations (like `E501`) - /// and at which the formatter prefers to wrap lines. + /// and at which `isort` and the formatter prefers to wrap lines. /// /// The length is determined by the number of characters per line, except for lines containing East Asian characters or emojis. /// For these lines, the [unicode width](https://unicode.org/reports/tr11/) of each character is added up to determine the length. diff --git a/ruff.schema.json b/ruff.schema.json index 117404e0c26cd..d7661f0e516ce 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -436,7 +436,7 @@ ] }, "line-length": { - "description": "The line length to use when enforcing long-lines violations (like `E501`) and at which the formatter prefers to wrap lines.\n\nThe length is determined by the number of characters per line, except for lines containing East Asian characters or emojis. For these lines, the [unicode width](https://unicode.org/reports/tr11/) of each character is added up to determine the length.\n\nThe value must be greater than `0` and less than or equal to `320`.\n\nNote: While the formatter will attempt to format lines such that they remain within the `line-length`, it isn't a hard upper bound, and formatted lines may exceed the `line-length`.\n\nSee [`pycodestyle.max-line-length`](#pycodestyle-max-line-length) to configure different lengths for `E501` and the formatter.", + "description": "The line length to use when enforcing long-lines violations (like `E501`) and at which `isort` and the formatter prefers to wrap lines.\n\nThe length is determined by the number of characters per line, except for lines containing East Asian characters or emojis. For these lines, the [unicode width](https://unicode.org/reports/tr11/) of each character is added up to determine the length.\n\nThe value must be greater than `0` and less than or equal to `320`.\n\nNote: While the formatter will attempt to format lines such that they remain within the `line-length`, it isn't a hard upper bound, and formatted lines may exceed the `line-length`.\n\nSee [`pycodestyle.max-line-length`](#pycodestyle-max-line-length) to configure different lengths for `E501` and the formatter.", "anyOf": [ { "$ref": "#/definitions/LineLength"