From 3be7279ecbb8493409949769a277505dfe39e31b Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 18 Oct 2023 08:45:20 +0900 Subject: [PATCH] Rename `-size` options to `-width` Signed-off-by: Micha Reiser --- README.md | 4 +- crates/flake8_to_ruff/src/black.rs | 4 +- crates/flake8_to_ruff/src/converter.rs | 14 ++-- crates/ruff_cli/src/args.rs | 28 ++++--- crates/ruff_cli/src/lib.rs | 5 ++ crates/ruff_cli/tests/format.rs | 2 +- crates/ruff_cli/tests/lint.rs | 76 +++++++++++++++++++ .../isort/detect_same_package/pyproject.toml | 2 +- .../test/fixtures/isort/pyproject.toml | 2 +- .../resources/test/fixtures/pyproject.toml | 2 +- .../pyproject_toml/maturin/pyproject.toml | 2 +- .../src/checkers/physical_lines.rs | 8 +- crates/ruff_linter/src/fix/edits.rs | 18 ++--- crates/ruff_linter/src/line_width.rs | 44 +++++------ .../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 +- crates/ruff_linter/src/rules/isort/format.rs | 4 +- crates/ruff_linter/src/rules/isort/mod.rs | 6 +- .../src/rules/isort/rules/organize_imports.rs | 2 +- .../ruff_linter/src/rules/pycodestyle/mod.rs | 8 +- .../src/rules/pycodestyle/overlong.rs | 4 +- .../pycodestyle/rules/doc_line_too_long.rs | 16 ++-- .../rules/pycodestyle/rules/line_too_long.rs | 20 ++--- .../src/rules/pycodestyle/settings.rs | 4 +- ...les__pycodestyle__tests__E501_E501.py.snap | 12 +-- ...s__pycodestyle__tests__E501_E501_3.py.snap | 2 +- ...s__pycodestyle__tests__max_doc_length.snap | 14 ++-- ...yle__tests__max_doc_length_with_utf_8.snap | 14 ++-- ...rules__pycodestyle__tests__tab_size_1.snap | 10 +-- ...rules__pycodestyle__tests__tab_size_2.snap | 18 ++--- ...rules__pycodestyle__tests__tab_size_4.snap | 22 +++--- ...rules__pycodestyle__tests__tab_size_8.snap | 22 +++--- ...__pycodestyle__tests__task_tags_false.snap | 16 ++-- .../src/rules/pyupgrade/rules/f_strings.rs | 2 +- ..._linter__rules__ruff__tests__ruf100_0.snap | 2 +- crates/ruff_linter/src/settings/mod.rs | 6 +- crates/ruff_python_formatter/README.md | 9 +-- crates/ruff_wasm/src/lib.rs | 4 +- crates/ruff_workspace/src/configuration.rs | 29 ++++--- crates/ruff_workspace/src/options.rs | 70 +++++++++++++++-- crates/ruff_workspace/src/pyproject.rs | 10 +-- docs/configuration.md | 8 +- docs/faq.md | 8 +- docs/tutorial.md | 16 ++-- ruff.schema.json | 32 +++++++- scripts/pyproject.toml | 2 +- 49 files changed, 393 insertions(+), 222 deletions(-) diff --git a/README.md b/README.md index d68ccfadf08749..3e63c6854e8db7 100644 --- a/README.md +++ b/README.md @@ -205,8 +205,8 @@ exclude = [ "venv", ] -# Same as Black. -line-length = 88 +# Same as Black's `line-length`. +line-width = 88 # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" diff --git a/crates/flake8_to_ruff/src/black.rs b/crates/flake8_to_ruff/src/black.rs index 2db11a4695fda3..3990425467f754 100644 --- a/crates/flake8_to_ruff/src/black.rs +++ b/crates/flake8_to_ruff/src/black.rs @@ -1,13 +1,13 @@ //! Extract Black configuration settings from a pyproject.toml. -use ruff_linter::line_width::LineLength; +use ruff_linter::line_width::LineWidth; use ruff_linter::settings::types::PythonVersion; use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)] pub(crate) struct Black { #[serde(alias = "line-length", alias = "line_length")] - pub(crate) line_length: Option, + pub(crate) line_length: Option, #[serde(alias = "target-version", alias = "target_version")] pub(crate) target_version: Option>, } diff --git a/crates/flake8_to_ruff/src/converter.rs b/crates/flake8_to_ruff/src/converter.rs index af1fd3c4373b33..7be65daaf7b8dc 100644 --- a/crates/flake8_to_ruff/src/converter.rs +++ b/crates/flake8_to_ruff/src/converter.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use itertools::Itertools; -use ruff_linter::line_width::LineLength; +use ruff_linter::line_width::LineWidth; use ruff_linter::registry::Linter; use ruff_linter::rule_selector::RuleSelector; use ruff_linter::rules::flake8_pytest_style::types::{ @@ -117,8 +117,8 @@ pub(crate) fn convert( "builtins" => { options.builtins = Some(parser::parse_strings(value.as_ref())); } - "max-line-length" | "max_line_length" => match LineLength::from_str(value) { - Ok(line_length) => options.line_length = Some(line_length), + "max-line-length" | "max_line_length" => match LineWidth::from_str(value) { + Ok(line_length) => options.line_width = Some(line_length), Err(e) => { warn_user!("Unable to parse '{key}' property: {e}"); } @@ -401,7 +401,7 @@ pub(crate) fn convert( // Extract any settings from the existing `pyproject.toml`. if let Some(black) = &external_config.black { if let Some(line_length) = &black.line_length { - options.line_length = Some(*line_length); + options.line_width = Some(*line_length); } if let Some(target_version) = &black.target_version { @@ -462,7 +462,7 @@ mod tests { use pep440_rs::VersionSpecifiers; use pretty_assertions::assert_eq; - use ruff_linter::line_width::LineLength; + use ruff_linter::line_width::LineWidth; use ruff_linter::registry::Linter; use ruff_linter::rule_selector::RuleSelector; use ruff_linter::rules::flake8_quotes; @@ -523,7 +523,7 @@ mod tests { Some(vec![]), ); let expected = Pyproject::new(Options { - line_length: Some(LineLength::try_from(100).unwrap()), + line_width: Some(LineWidth::try_from(100).unwrap()), lint: Some(LintOptions { common: lint_default_options([]), ..LintOptions::default() @@ -544,7 +544,7 @@ mod tests { Some(vec![]), ); let expected = Pyproject::new(Options { - line_length: Some(LineLength::try_from(100).unwrap()), + line_width: Some(LineWidth::try_from(100).unwrap()), lint: Some(LintOptions { common: lint_default_options([]), ..LintOptions::default() diff --git a/crates/ruff_cli/src/args.rs b/crates/ruff_cli/src/args.rs index 8a1006a6e6484c..2d37f536797745 100644 --- a/crates/ruff_cli/src/args.rs +++ b/crates/ruff_cli/src/args.rs @@ -4,7 +4,7 @@ use clap::{command, Parser}; use regex::Regex; use rustc_hash::FxHashMap; -use ruff_linter::line_width::LineLength; +use ruff_linter::line_width::LineWidth; use ruff_linter::logging::LogLevel; use ruff_linter::registry::Rule; use ruff_linter::settings::types::{ @@ -259,9 +259,15 @@ pub struct CheckCommand { force_exclude: bool, #[clap(long, overrides_with("force_exclude"), hide = true)] no_force_exclude: bool, - /// Set the line-length for length-associated rules and automatic formatting. + /// Set the line-width for width-associated rules. #[arg(long, help_heading = "Rule configuration", hide = true)] - pub line_length: Option, + pub line_width: Option, + + /// Set the line-length for width-associated rules. + #[arg(long, help_heading = "Rule configuration", hide = true)] + #[deprecated(note = "Deprecated in favor of `--line-width`")] + pub line_length: Option, + /// Regular expression matching the name of dummy variables. #[arg(long, help_heading = "Rule configuration", hide = true)] pub dummy_variable_rgx: Option, @@ -389,9 +395,6 @@ pub struct FormatCommand { force_exclude: bool, #[clap(long, overrides_with("force_exclude"), hide = true)] no_force_exclude: bool, - /// Set the line-length. - #[arg(long, help_heading = "Rule configuration", hide = true)] - pub line_length: Option, /// Ignore all configuration files. #[arg(long, conflicts_with = "config", help_heading = "Miscellaneous")] pub isolated: bool, @@ -463,6 +466,9 @@ impl CheckCommand { /// Partition the CLI into command-line arguments and configuration /// overrides. pub fn partition(self) -> (CheckArguments, CliOverrides) { + #[allow(deprecated)] + let line_width = self.line_width.or(self.line_length); + ( CheckArguments { add_noqa: self.add_noqa, @@ -492,7 +498,7 @@ impl CheckCommand { extend_unfixable: self.extend_unfixable, fixable: self.fixable, ignore: self.ignore, - line_length: self.line_length, + line_width, per_file_ignores: self.per_file_ignores, preview: resolve_bool_arg(self.preview, self.no_preview).map(PreviewMode::from), respect_gitignore: resolve_bool_arg( @@ -531,7 +537,7 @@ impl FormatCommand { stdin_filename: self.stdin_filename, }, CliOverrides { - line_length: self.line_length, + line_width: None, respect_gitignore: resolve_bool_arg( self.respect_gitignore, self.no_respect_gitignore, @@ -602,7 +608,7 @@ pub struct CliOverrides { pub extend_unfixable: Option>, pub fixable: Option>, pub ignore: Option>, - pub line_length: Option, + pub line_width: Option, pub per_file_ignores: Option>, pub preview: Option, pub respect_gitignore: Option, @@ -669,8 +675,8 @@ impl ConfigurationTransformer for CliOverrides { if let Some(force_exclude) = &self.force_exclude { config.force_exclude = Some(*force_exclude); } - if let Some(line_length) = &self.line_length { - config.line_length = Some(*line_length); + if let Some(line_width) = self.line_width { + config.line_width = Some(line_width); } if let Some(preview) = &self.preview { config.preview = Some(*preview); diff --git a/crates/ruff_cli/src/lib.rs b/crates/ruff_cli/src/lib.rs index 993f0f8771bf7b..12ca85d8ba658d 100644 --- a/crates/ruff_cli/src/lib.rs +++ b/crates/ruff_cli/src/lib.rs @@ -177,6 +177,11 @@ fn format(args: FormatCommand, log_level: LogLevel) -> Result { } pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { + #[allow(deprecated)] + if args.line_length.is_some() { + warn_user_once!("The option `--line-length` has been renamed to `--line-width` to emphasize that the limit is the display width of a line and not the number of characters. Use the option `--line-width` instead."); + } + let (cli, overrides) = args.partition(); // Construct the "default" settings. These are used when no `pyproject.toml` diff --git a/crates/ruff_cli/tests/format.rs b/crates/ruff_cli/tests/format.rs index 22ba8adf0bd8bc..626b29f39bccb0 100644 --- a/crates/ruff_cli/tests/format.rs +++ b/crates/ruff_cli/tests/format.rs @@ -52,7 +52,7 @@ fn format_options() -> Result<()> { &ruff_toml, r#" tab-size = 8 -line-length = 84 +line-width = 84 [format] indent-style = "tab" diff --git a/crates/ruff_cli/tests/lint.rs b/crates/ruff_cli/tests/lint.rs index 35e2226f9fea43..5809c5894b5081 100644 --- a/crates/ruff_cli/tests/lint.rs +++ b/crates/ruff_cli/tests/lint.rs @@ -270,3 +270,79 @@ if __name__ == "__main__": "###); Ok(()) } + +#[test] +fn deprecated_length_options() -> Result<()> { + let tempdir = TempDir::new()?; + let ruff_toml = tempdir.path().join("ruff.toml"); + fs::write( + &ruff_toml, + r#" +line-length = 100 +select = ["E501", "W505"] + +[pycodestyle] +max-doc-length = 80 +"#, + )?; + + assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + .args(STDIN_BASE_OPTIONS) + .arg("--config") + .arg(&ruff_toml) + .args(["--stdin-filename", "test.py"]) + .arg("-") + .pass_stdin(r#" +_ = "---------------------------------------------------------------------------亜亜亜亜亜亜亜亜亜亜亜亜亜亜" + +class Bar: + """ + This is a long sentence that ends with a shortened URL and, therefore, could easily be broken across multiple lines ([source](https://ruff.rs)) + """ + "#), @r###" + success: false + exit_code: 1 + ----- stdout ----- + test.py:2:91: E501 Line too long (109 > 100 width) + test.py:6:81: W505 Doc line too long (147 > 80 width) + test.py:6:101: E501 Line too long (147 > 100 width) + Found 3 errors. + + ----- stderr ----- + warning: The option `line-length` has been renamed to `line-width` to emphasize that the limit is the display width of a line and not the number of characters. Use `line-width` instead. + warning: The option `pycodestyle.max-doc-length` has been renamed to `pycodestyle.max-doc-width` to emphasize that the limit is the display width of a line and not the number of characters. Use `pycodestyle.max-doc-width` instead. + "###); + Ok(()) +} + +#[test] +fn deprecated_line_length_cli_option() -> Result<()> { + let tempdir = TempDir::new()?; + let ruff_toml = tempdir.path().join("ruff.toml"); + fs::write( + &ruff_toml, + r#" +select = ["E501"] +"#, + )?; + + assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + .args(STDIN_BASE_OPTIONS) + .arg("--config") + .arg(&ruff_toml) + .args(["--stdin-filename", "test.py", "--line-length", "100"]) + .arg("-") + .pass_stdin(r#" +_ = "---------------------------------------------------------------------------亜亜亜亜亜亜亜亜亜亜亜亜亜亜" + "#), @r###" + success: false + exit_code: 1 + ----- stdout ----- + test.py:2:91: E501 Line too long (109 > 100 width) + Found 1 error. + + ----- stderr ----- + warning: The option `--line-length` has been renamed to `--line-width` to emphasize that the limit is the display width of a line and not the number of characters. Use the option `--line-width` instead. + "###); + Ok(()) +} diff --git a/crates/ruff_linter/resources/test/fixtures/isort/detect_same_package/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/isort/detect_same_package/pyproject.toml index 97fda9d62e0a92..d16a353c65db93 100644 --- a/crates/ruff_linter/resources/test/fixtures/isort/detect_same_package/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/isort/detect_same_package/pyproject.toml @@ -1,2 +1,2 @@ [tool.ruff] -line-length = 88 +line-width = 88 diff --git a/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml index 63e7153b20c7d8..e973e66b0a93ec 100644 --- a/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/isort/pyproject.toml @@ -1,5 +1,5 @@ [tool.ruff] -line-length = 88 +line-width = 88 [tool.ruff.isort] lines-after-imports = 3 diff --git a/crates/ruff_linter/resources/test/fixtures/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/pyproject.toml index 5525b69dea8a50..9bba186dd03f43 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/pyproject.toml @@ -1,5 +1,5 @@ [tool.ruff] -line-length = 88 +line-width = 88 extend-exclude = [ "excluded_file.py", "migrations", diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/pyproject_toml/maturin/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/ruff/pyproject_toml/maturin/pyproject.toml index 6cbcadc76841e2..10ca71baf97846 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/pyproject_toml/maturin/pyproject.toml +++ b/crates/ruff_linter/resources/test/fixtures/ruff/pyproject_toml/maturin/pyproject.toml @@ -47,7 +47,7 @@ extend-exclude = ''' ''' [tool.ruff] -line-length = 120 +line-width = 120 target-version = "py37" [tool.mypy] diff --git a/crates/ruff_linter/src/checkers/physical_lines.rs b/crates/ruff_linter/src/checkers/physical_lines.rs index 3c1e5d73574c6d..93fe0e0e600cb2 100644 --- a/crates/ruff_linter/src/checkers/physical_lines.rs +++ b/crates/ruff_linter/src/checkers/physical_lines.rs @@ -93,7 +93,7 @@ mod tests { use ruff_python_parser::Mode; use ruff_source_file::Locator; - use crate::line_width::LineLength; + use crate::line_width::LineWidth; use crate::registry::Rule; use crate::settings::LinterSettings; @@ -107,19 +107,19 @@ mod tests { let indexer = Indexer::from_tokens(&tokens, &locator); let stylist = Stylist::from_tokens(&tokens, &locator); - let check_with_max_line_length = |line_length: LineLength| { + let check_with_max_line_length = |line_width: LineWidth| { check_physical_lines( &locator, &stylist, &indexer, &[], &LinterSettings { - line_length, + line_width, ..LinterSettings::for_rule(Rule::LineTooLong) }, ) }; - let line_length = LineLength::try_from(8).unwrap(); + let line_length = LineWidth::try_from(8).unwrap(); assert_eq!(check_with_max_line_length(line_length), vec![]); assert_eq!(check_with_max_line_length(line_length), vec![]); } diff --git a/crates/ruff_linter/src/fix/edits.rs b/crates/ruff_linter/src/fix/edits.rs index 0a23555497faa9..2f985082b7dcf8 100644 --- a/crates/ruff_linter/src/fix/edits.rs +++ b/crates/ruff_linter/src/fix/edits.rs @@ -14,7 +14,7 @@ use ruff_source_file::{Locator, NewlineWithTrailingNewline, UniversalNewlines}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use crate::fix::codemods; -use crate::line_width::{LineLength, LineWidthBuilder, TabSize}; +use crate::line_width::{LineWidth, LineWidthBuilder, TabSize}; /// Return the `Fix` to use when deleting a `Stmt`. /// @@ -292,10 +292,10 @@ pub(crate) fn fits( fix: &str, node: AnyNodeRef, locator: &Locator, - line_length: LineLength, + line_width: LineWidth, tab_size: TabSize, ) -> bool { - all_lines_fit(fix, node, locator, line_length.value() as usize, tab_size) + all_lines_fit(fix, node, locator, line_width.value() as usize, tab_size) } /// Returns `true` if the fix fits within the maximum configured line length, or produces lines that @@ -304,11 +304,11 @@ pub(crate) fn fits_or_shrinks( fix: &str, node: AnyNodeRef, locator: &Locator, - line_length: LineLength, + line_width: LineWidth, tab_size: TabSize, ) -> bool { // Use the larger of the line length limit, or the longest line in the existing AST node. - let line_length = std::iter::once(line_length.value() as usize) + let line_length = std::iter::once(line_width.value() as usize) .chain( locator .slice(locator.lines_range(node.range())) @@ -316,7 +316,7 @@ pub(crate) fn fits_or_shrinks( .map(|line| LineWidthBuilder::new(tab_size).add_str(&line).get()), ) .max() - .unwrap_or(line_length.value() as usize); + .unwrap_or(line_width.value() as usize); all_lines_fit(fix, node, locator, line_length, tab_size) } @@ -326,7 +326,7 @@ fn all_lines_fit( fix: &str, node: AnyNodeRef, locator: &Locator, - line_length: usize, + line_width: usize, tab_size: TabSize, ) -> bool { let prefix = locator.slice(TextRange::new( @@ -343,7 +343,7 @@ fn all_lines_fit( // {} -> offset = 0 // """.format(0, 1) -> offset = 0 // ``` - let measured_length = if idx == 0 { + let measured_width = if idx == 0 { LineWidthBuilder::new(tab_size) .add_str(prefix) .add_str(&line) @@ -352,7 +352,7 @@ fn all_lines_fit( LineWidthBuilder::new(tab_size).add_str(&line).get() }; - measured_length <= line_length + measured_width <= line_width }) } diff --git a/crates/ruff_linter/src/line_width.rs b/crates/ruff_linter/src/line_width.rs index fe8fc31849452e..4caa30581dce44 100644 --- a/crates/ruff_linter/src/line_width.rs +++ b/crates/ruff_linter/src/line_width.rs @@ -15,15 +15,15 @@ use ruff_text_size::TextSize; /// The allowed range of values is 1..=320 #[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct LineLength( +pub struct LineWidth( #[cfg_attr(feature = "schemars", schemars(range(min = 1, max = 320)))] NonZeroU16, ); -impl LineLength { - /// Maximum allowed value for a valid [`LineLength`] +impl LineWidth { + /// Maximum allowed value for a valid [`LineWidth`] pub const MAX: u16 = 320; - /// Return the numeric value for this [`LineLength`] + /// Return the numeric value for this [`LineWidth`] pub fn value(&self) -> u16 { self.0.get() } @@ -33,23 +33,23 @@ impl LineLength { } } -impl Default for LineLength { +impl Default for LineWidth { fn default() -> Self { Self(NonZeroU16::new(88).unwrap()) } } -impl CacheKey for LineLength { +impl CacheKey for LineWidth { fn cache_key(&self, state: &mut CacheKeyHasher) { state.write_u16(self.0.get()); } } -/// Error type returned when parsing a [`LineLength`] from a string fails +/// Error type returned when parsing a [`LineWidth`] from a string fails pub enum ParseLineWidthError { /// The string could not be parsed as a valid [u16] ParseError(ParseIntError), - /// The [u16] value of the string is not a valid [LineLength] + /// The [u16] value of the string is not a valid [LineWidth] TryFromIntError(LineLengthFromIntError), } @@ -70,7 +70,7 @@ impl std::fmt::Display for ParseLineWidthError { impl Error for ParseLineWidthError {} -impl FromStr for LineLength { +impl FromStr for LineWidth { type Err = ParseLineWidthError; fn from_str(s: &str) -> Result { @@ -80,16 +80,16 @@ impl FromStr for LineLength { } } -/// Error type returned when converting a u16 to a [`LineLength`] fails +/// Error type returned when converting a u16 to a [`LineWidth`] fails #[derive(Clone, Copy, Debug)] pub struct LineLengthFromIntError(pub u16); -impl TryFrom for LineLength { +impl TryFrom for LineWidth { type Error = LineLengthFromIntError; fn try_from(value: u16) -> Result { match NonZeroU16::try_from(value) { - Ok(value) if value.get() <= Self::MAX => Ok(LineLength(value)), + Ok(value) if value.get() <= Self::MAX => Ok(LineWidth(value)), Ok(_) | Err(_) => Err(LineLengthFromIntError(value)), } } @@ -100,19 +100,19 @@ impl std::fmt::Display for LineLengthFromIntError { writeln!( f, "The line width must be a value between 1 and {}.", - LineLength::MAX + LineWidth::MAX ) } } -impl From for u16 { - fn from(value: LineLength) -> Self { +impl From for u16 { + fn from(value: LineWidth) -> Self { value.0.get() } } -impl From for NonZeroU16 { - fn from(value: LineLength) -> Self { +impl From for NonZeroU16 { + fn from(value: LineWidth) -> Self { value.0 } } @@ -120,7 +120,7 @@ impl From for NonZeroU16 { /// A measure of the width of a line of text. /// /// This is used to determine if a line is too long. -/// It should be compared to a [`LineLength`]. +/// It should be compared to a [`LineWidth`]. #[derive(Clone, Copy, Debug)] pub struct LineWidthBuilder { /// The width of the line. @@ -219,14 +219,14 @@ impl LineWidthBuilder { } } -impl PartialEq for LineWidthBuilder { - fn eq(&self, other: &LineLength) -> bool { +impl PartialEq for LineWidthBuilder { + fn eq(&self, other: &LineWidth) -> bool { self.width == (other.value() as usize) } } -impl PartialOrd for LineWidthBuilder { - fn partial_cmp(&self, other: &LineLength) -> Option { +impl PartialOrd for LineWidthBuilder { + fn partial_cmp(&self, other: &LineWidth) -> Option { self.width.partial_cmp(&(other.value() as usize)) } } 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 7294ccfb8741bd..b9183f2872667e 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_length, + checker.settings.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 7f9cde0604edfb..a872c2253c6cd2 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 @@ -117,7 +117,7 @@ pub(crate) fn nested_if_statements( content, (&nested_if).into(), checker.locator(), - checker.settings.line_length, + checker.settings.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 820a02d6861dd6..d12829fd2401fe 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 @@ -171,7 +171,7 @@ pub(crate) fn use_dict_get_with_default(checker: &mut Checker, stmt_if: &ast::St &contents, stmt_if.into(), checker.locator(), - checker.settings.line_length, + checker.settings.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 19bcca6d7e3675..23bf1960dd866d 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 use_ternary_operator(checker: &mut Checker, stmt: &Stmt) { &contents, stmt.into(), checker.locator(), - checker.settings.line_length, + checker.settings.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 651b775ddf338a..4bbc7e62359aac 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_length, + checker.settings.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_length + > checker.settings.line_width { return; } diff --git a/crates/ruff_linter/src/rules/isort/format.rs b/crates/ruff_linter/src/rules/isort/format.rs index 1226bbc10317e9..bc1200372c43c6 100644 --- a/crates/ruff_linter/src/rules/isort/format.rs +++ b/crates/ruff_linter/src/rules/isort/format.rs @@ -1,6 +1,6 @@ use ruff_python_codegen::Stylist; -use crate::line_width::{LineLength, LineWidthBuilder}; +use crate::line_width::{LineWidth, LineWidthBuilder}; use super::types::{AliasData, CommentSet, ImportFromData, Importable}; @@ -45,7 +45,7 @@ pub(crate) fn format_import_from( import_from: &ImportFromData, comments: &CommentSet, aliases: &[(AliasData, CommentSet)], - line_length: LineLength, + line_length: LineWidth, indentation_width: LineWidthBuilder, stylist: &Stylist, force_wrap_aliases: bool, diff --git a/crates/ruff_linter/src/rules/isort/mod.rs b/crates/ruff_linter/src/rules/isort/mod.rs index bbe155c6effa89..dccd20d9a46753 100644 --- a/crates/ruff_linter/src/rules/isort/mod.rs +++ b/crates/ruff_linter/src/rules/isort/mod.rs @@ -18,7 +18,7 @@ use sorting::cmp_either_import; use types::EitherImport::{Import, ImportFrom}; use types::{AliasData, EitherImport, ImportBlock, TrailingComma}; -use crate::line_width::{LineLength, LineWidthBuilder}; +use crate::line_width::{LineWidth, LineWidthBuilder}; use crate::settings::types::PythonVersion; mod annotate; @@ -65,7 +65,7 @@ pub(crate) fn format_imports( block: &Block, comments: Vec, locator: &Locator, - line_length: LineLength, + line_length: LineWidth, indentation_width: LineWidthBuilder, stylist: &Stylist, src: &[PathBuf], @@ -138,7 +138,7 @@ pub(crate) fn format_imports( #[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)] fn format_import_block( block: ImportBlock, - line_length: LineLength, + line_length: LineWidth, indentation_width: LineWidthBuilder, stylist: &Stylist, src: &[PathBuf], 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 e571271d08c003..2f362c2be9d1df 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_length, + settings.line_width, LineWidthBuilder::new(settings.tab_size).add_str(indentation), stylist, &settings.src, diff --git a/crates/ruff_linter/src/rules/pycodestyle/mod.rs b/crates/ruff_linter/src/rules/pycodestyle/mod.rs index b46ca90532c8df..fd0067a6828740 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/mod.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/mod.rs @@ -14,7 +14,7 @@ mod tests { use test_case::test_case; - use crate::line_width::LineLength; + use crate::line_width::LineWidth; use crate::registry::Rule; use crate::test::test_path; use crate::{assert_messages, settings}; @@ -174,7 +174,7 @@ mod tests { Path::new("pycodestyle/W505.py"), &settings::LinterSettings { pycodestyle: Settings { - max_doc_length: Some(LineLength::try_from(50).unwrap()), + max_doc_width: Some(LineWidth::try_from(50).unwrap()), ..Settings::default() }, ..settings::LinterSettings::for_rule(Rule::DocLineTooLong) @@ -190,7 +190,7 @@ mod tests { Path::new("pycodestyle/W505_utf_8.py"), &settings::LinterSettings { pycodestyle: Settings { - max_doc_length: Some(LineLength::try_from(50).unwrap()), + max_doc_width: Some(LineWidth::try_from(50).unwrap()), ..Settings::default() }, ..settings::LinterSettings::for_rule(Rule::DocLineTooLong) @@ -210,7 +210,7 @@ mod tests { Path::new("pycodestyle/E501_2.py"), &settings::LinterSettings { tab_size: NonZeroU8::new(tab_size).unwrap().into(), - line_length: LineLength::try_from(6).unwrap(), + line_width: LineWidth::try_from(6).unwrap(), ..settings::LinterSettings::for_rule(Rule::LineTooLong) }, )?; diff --git a/crates/ruff_linter/src/rules/pycodestyle/overlong.rs b/crates/ruff_linter/src/rules/pycodestyle/overlong.rs index a91655892d4692..34dda943c26621 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/overlong.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/overlong.rs @@ -7,7 +7,7 @@ use ruff_python_trivia::is_pragma_comment; use ruff_source_file::Line; use ruff_text_size::{TextLen, TextRange}; -use crate::line_width::{LineLength, LineWidthBuilder, TabSize}; +use crate::line_width::{LineWidth, LineWidthBuilder, TabSize}; #[derive(Debug)] pub(super) struct Overlong { @@ -21,7 +21,7 @@ impl Overlong { pub(super) fn try_from_line( line: &Line, indexer: &Indexer, - limit: LineLength, + limit: LineWidth, task_tags: &[String], tab_size: TabSize, ) -> Option { diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs index b42f1ebca41456..438df1bdb7c1b6 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs @@ -7,13 +7,13 @@ use crate::rules::pycodestyle::overlong::Overlong; use crate::settings::LinterSettings; /// ## What it does -/// Checks for doc lines that exceed the specified maximum character length. +/// Checks for doc lines that exceed the specified maximum width. /// /// ## Why is this bad? /// For flowing long blocks of text (docstrings or comments), overlong lines /// can hurt readability. [PEP 8], for example, recommends that such lines be /// limited to 72 characters, while this rule enforces the limit specified by -/// the [`pycodestyle.max-doc-length`] setting. (If no value is provided, this +/// the [`pycodestyle.max-doc-width`] setting. (If no value is provided, this /// rule will be ignored, even if it's added to your `--select` list.) /// /// In the context of this rule, a "doc line" is defined as a line consisting @@ -25,11 +25,11 @@ use crate::settings::LinterSettings; /// 1. Ignores lines that consist of a single "word" (i.e., without any /// whitespace between its characters). /// 2. Ignores lines that end with a URL, as long as the URL starts before -/// the line-length threshold. +/// the line-width threshold. /// 3. Ignores line that end with a pragma comment (e.g., `# type: ignore` /// or `# noqa`), as long as the pragma comment starts before the -/// line-length threshold. That is, a line will not be flagged as -/// overlong if a pragma comment _causes_ it to exceed the line length. +/// line-width threshold. That is, a line will not be flagged as +/// overlong if a pragma comment _causes_ it to exceed the line width. /// (This behavior aligns with that of the Ruff formatter.) /// /// If [`pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will @@ -53,7 +53,7 @@ use crate::settings::LinterSettings; /// /// ## Options /// - `task-tags` -/// - `pycodestyle.max-doc-length` +/// - `pycodestyle.max-doc-width` /// - `pycodestyle.ignore-overlong-task-comments` /// /// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length @@ -64,7 +64,7 @@ impl Violation for DocLineTooLong { #[derive_message_formats] fn message(&self) -> String { let DocLineTooLong(width, limit) = self; - format!("Doc line too long ({width} > {limit} characters)") + format!("Doc line too long ({width} > {limit} width)") } } @@ -74,7 +74,7 @@ pub(crate) fn doc_line_too_long( indexer: &Indexer, settings: &LinterSettings, ) -> Option { - let Some(limit) = settings.pycodestyle.max_doc_length else { + let Some(limit) = settings.pycodestyle.max_doc_width else { return None; }; 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 dfc94324a777ab..e8f8abbe6eac87 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 @@ -7,13 +7,13 @@ use crate::rules::pycodestyle::overlong::Overlong; use crate::settings::LinterSettings; /// ## What it does -/// Checks for lines that exceed the specified maximum character length. +/// Checks for lines that exceed the specified maximum width. /// /// ## Why is this bad? /// Overlong lines can hurt readability. [PEP 8], for example, recommends -/// limiting lines to 79 characters. By default, this rule enforces a limit -/// of 88 characters for compatibility with Black, though that limit is -/// configurable via the [`line-length`] setting. +/// limiting lines to 79 characters. By default, this rule enforces a [display-width](http://www.unicode.org/reports/tr11/#Overview) +/// of 88 for compatibility with Black, though that limit is +/// configurable via the [`line-width`] setting. /// /// In the interest of pragmatism, this rule makes a few exceptions when /// determining whether a line is overlong. Namely, it: @@ -21,11 +21,11 @@ use crate::settings::LinterSettings; /// 1. Ignores lines that consist of a single "word" (i.e., without any /// whitespace between its characters). /// 2. Ignores lines that end with a URL, as long as the URL starts before -/// the line-length threshold. +/// the `line-width` threshold. /// 3. Ignores line that end with a pragma comment (e.g., `# type: ignore` /// or `# noqa`), as long as the pragma comment starts before the -/// line-length threshold. That is, a line will not be flagged as -/// overlong if a pragma comment _causes_ it to exceed the line length. +/// `line-width` threshold. That is, a line will not be flagged as +/// overlong if a pragma comment _causes_ it to exceed the line width. /// (This behavior aligns with that of the Ruff formatter.) /// /// If [`pycodestyle.ignore-overlong-task-comments`] is `true`, this rule will @@ -46,7 +46,7 @@ use crate::settings::LinterSettings; /// ``` /// /// ## Options -/// - `line-length` +/// - `line-width` /// - `task-tags` /// - `pycodestyle.ignore-overlong-task-comments` /// @@ -58,7 +58,7 @@ impl Violation for LineTooLong { #[derive_message_formats] fn message(&self) -> String { let LineTooLong(width, limit) = self; - format!("Line too long ({width} > {limit} characters)") + format!("Line too long ({width} > {limit} width)") } } @@ -68,7 +68,7 @@ pub(crate) fn line_too_long( indexer: &Indexer, settings: &LinterSettings, ) -> Option { - let limit = settings.line_length; + let limit = settings.line_width; Overlong::try_from_line( line, diff --git a/crates/ruff_linter/src/rules/pycodestyle/settings.rs b/crates/ruff_linter/src/rules/pycodestyle/settings.rs index 55c9890ac10ced..bc352012ff0632 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/settings.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/settings.rs @@ -2,10 +2,10 @@ use ruff_macros::CacheKey; -use crate::line_width::LineLength; +use crate::line_width::LineWidth; #[derive(Debug, Default, CacheKey)] pub struct Settings { - pub max_doc_length: Option, + pub max_doc_width: Option, pub ignore_overlong_task_comments: bool, } diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501.py.snap index 9445864d5756a3..50fad36836da4e 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501.py:5:89: E501 Line too long (123 > 88 characters) +E501.py:5:89: E501 Line too long (123 > 88 width) | 3 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 4 | @@ -10,14 +10,14 @@ E501.py:5:89: E501 Line too long (123 > 88 characters) 6 | """ | -E501.py:16:85: E501 Line too long (95 > 88 characters) +E501.py:16:85: E501 Line too long (95 > 88 width) | 15 | _ = "---------------------------------------------------------------------------AAAAAAA" 16 | _ = "---------------------------------------------------------------------------亜亜亜亜亜亜亜" | ^^^^^^^ E501 | -E501.py:25:89: E501 Line too long (127 > 88 characters) +E501.py:25:89: E501 Line too long (127 > 88 width) | 23 | caller( 24 | """ @@ -27,7 +27,7 @@ E501.py:25:89: E501 Line too long (127 > 88 characters) 27 | ) | -E501.py:40:89: E501 Line too long (132 > 88 characters) +E501.py:40:89: E501 Line too long (132 > 88 width) | 38 | "Lorem ipsum dolor": "sit amet", 39 | # E501 Line too long @@ -37,7 +37,7 @@ E501.py:40:89: E501 Line too long (132 > 88 characters) 42 | "Lorem ipsum dolor": """ | -E501.py:43:89: E501 Line too long (105 > 88 characters) +E501.py:43:89: E501 Line too long (105 > 88 width) | 41 | # E501 Line too long 42 | "Lorem ipsum dolor": """ @@ -47,7 +47,7 @@ E501.py:43:89: E501 Line too long (105 > 88 characters) 45 | # OK | -E501.py:83:89: E501 Line too long (147 > 88 characters) +E501.py:83:89: E501 Line too long (147 > 88 width) | 81 | class Bar: 82 | """ diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501_3.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501_3.py.snap index 8f3121813daa47..0b200f6691b161 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501_3.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E501_E501_3.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_3.py:11:89: E501 Line too long (89 > 88 characters) +E501_3.py:11:89: E501 Line too long (89 > 88 width) | 10 | # Error (89 characters) 11 | "shape:" + "shape:" + "shape:" + "shape:" + "shape:" + "shape:" + "shape:" + "shape:aaaa" # type: ignore diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length.snap index 18e19e53e295ea..63e06d8ad2906f 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length.snap @@ -1,14 +1,14 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -W505.py:2:51: W505 Doc line too long (57 > 50 characters) +W505.py:2:51: W505 Doc line too long (57 > 50 width) | 1 | #!/usr/bin/env python3 2 | """Here's a top-level docstring that's over the limit.""" | ^^^^^^^ W505 | -W505.py:6:51: W505 Doc line too long (56 > 50 characters) +W505.py:6:51: W505 Doc line too long (56 > 50 width) | 5 | def f1(): 6 | """Here's a docstring that's also over the limit.""" @@ -17,7 +17,7 @@ W505.py:6:51: W505 Doc line too long (56 > 50 characters) 8 | x = 1 # Here's a comment that's over the limit, but it's not standalone. | -W505.py:10:51: W505 Doc line too long (56 > 50 characters) +W505.py:10:51: W505 Doc line too long (56 > 50 width) | 8 | x = 1 # Here's a comment that's over the limit, but it's not standalone. 9 | @@ -27,7 +27,7 @@ W505.py:10:51: W505 Doc line too long (56 > 50 characters) 12 | x = 2 | -W505.py:13:51: W505 Doc line too long (93 > 50 characters) +W505.py:13:51: W505 Doc line too long (93 > 50 width) | 12 | x = 2 13 | # Another standalone that is preceded by a newline and indent toke and is over the limit. @@ -36,13 +36,13 @@ W505.py:13:51: W505 Doc line too long (93 > 50 characters) 15 | print("Here's a string that's over the limit, but it's not a docstring.") | -W505.py:18:51: W505 Doc line too long (61 > 50 characters) +W505.py:18:51: W505 Doc line too long (61 > 50 width) | 18 | "This is also considered a docstring, and is over the limit." | ^^^^^^^^^^^ W505 | -W505.py:24:51: W505 Doc line too long (82 > 50 characters) +W505.py:24:51: W505 Doc line too long (82 > 50 width) | 22 | """Here's a multi-line docstring. 23 | @@ -51,7 +51,7 @@ W505.py:24:51: W505 Doc line too long (82 > 50 characters) 25 | """ | -W505.py:31:51: W505 Doc line too long (85 > 50 characters) +W505.py:31:51: W505 Doc line too long (85 > 50 width) | 29 | """Here's a multi-line docstring. 30 | diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length_with_utf_8.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length_with_utf_8.snap index 42bcfd88d7edb3..ab5bd9eb0f15dc 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length_with_utf_8.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__max_doc_length_with_utf_8.snap @@ -1,14 +1,14 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -W505_utf_8.py:2:50: W505 Doc line too long (57 > 50 characters) +W505_utf_8.py:2:50: W505 Doc line too long (57 > 50 width) | 1 | #!/usr/bin/env python3 2 | """Here's a top-level ß9💣2ℝing that's over theß9💣2ℝ.""" | ^^^^^^ W505 | -W505_utf_8.py:6:49: W505 Doc line too long (56 > 50 characters) +W505_utf_8.py:6:49: W505 Doc line too long (56 > 50 width) | 5 | def f1(): 6 | """Here's a ß9💣2ℝing that's also over theß9💣2ℝ.""" @@ -17,7 +17,7 @@ W505_utf_8.py:6:49: W505 Doc line too long (56 > 50 characters) 8 | x = 1 # Here's a comment that's over theß9💣2ℝ, but it's not standalone. | -W505_utf_8.py:10:51: W505 Doc line too long (56 > 50 characters) +W505_utf_8.py:10:51: W505 Doc line too long (56 > 50 width) | 8 | x = 1 # Here's a comment that's over theß9💣2ℝ, but it's not standalone. 9 | @@ -27,7 +27,7 @@ W505_utf_8.py:10:51: W505 Doc line too long (56 > 50 characters) 12 | x = 2 | -W505_utf_8.py:13:51: W505 Doc line too long (93 > 50 characters) +W505_utf_8.py:13:51: W505 Doc line too long (93 > 50 width) | 12 | x = 2 13 | # Another standalone that is preceded by a newline and indent toke and is over theß9💣2ℝ. @@ -36,13 +36,13 @@ W505_utf_8.py:13:51: W505 Doc line too long (93 > 50 characters) 15 | print("Here's a string that's over theß9💣2ℝ, but it's not a ß9💣2ℝing.") | -W505_utf_8.py:18:50: W505 Doc line too long (61 > 50 characters) +W505_utf_8.py:18:50: W505 Doc line too long (61 > 50 width) | 18 | "This is also considered a ß9💣2ℝing, and is over theß9💣2ℝ." | ^^^^^^^^^^^ W505 | -W505_utf_8.py:24:50: W505 Doc line too long (82 > 50 characters) +W505_utf_8.py:24:50: W505 Doc line too long (82 > 50 width) | 22 | """Here's a multi-line ß9💣2ℝing. 23 | @@ -51,7 +51,7 @@ W505_utf_8.py:24:50: W505 Doc line too long (82 > 50 characters) 25 | """ | -W505_utf_8.py:31:50: W505 Doc line too long (85 > 50 characters) +W505_utf_8.py:31:50: W505 Doc line too long (85 > 50 width) | 29 | """Here's a multi-line ß9💣2ℝing. 30 | diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_1.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_1.snap index 414ff813095104..82f00c7abd27c9 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_1.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_1.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_2.py:2:7: E501 Line too long (7 > 6 characters) +E501_2.py:2:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -10,7 +10,7 @@ E501_2.py:2:7: E501 Line too long (7 > 6 characters) 4 | # a | -E501_2.py:3:7: E501 Line too long (7 > 6 characters) +E501_2.py:3:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -20,7 +20,7 @@ E501_2.py:3:7: E501 Line too long (7 > 6 characters) 5 | # aa | -E501_2.py:7:7: E501 Line too long (7 > 6 characters) +E501_2.py:7:7: E501 Line too long (7 > 6 width) | 5 | # aa 6 | # aaa @@ -30,7 +30,7 @@ E501_2.py:7:7: E501 Line too long (7 > 6 characters) 9 | # aa | -E501_2.py:10:7: E501 Line too long (7 > 6 characters) +E501_2.py:10:7: E501 Line too long (7 > 6 width) | 8 | # a 9 | # aa @@ -40,7 +40,7 @@ E501_2.py:10:7: E501 Line too long (7 > 6 characters) 12 | if True: # noqa: E501 | -E501_2.py:16:7: E501 Line too long (7 > 6 characters) +E501_2.py:16:7: E501 Line too long (7 > 6 width) | 14 | [12 ] 15 | [1,2] diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_2.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_2.snap index 34f004a6069ad4..081c040a565d5a 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_2.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_2.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_2.py:2:7: E501 Line too long (7 > 6 characters) +E501_2.py:2:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -10,7 +10,7 @@ E501_2.py:2:7: E501 Line too long (7 > 6 characters) 4 | # a | -E501_2.py:3:7: E501 Line too long (7 > 6 characters) +E501_2.py:3:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -20,7 +20,7 @@ E501_2.py:3:7: E501 Line too long (7 > 6 characters) 5 | # aa | -E501_2.py:6:6: E501 Line too long (7 > 6 characters) +E501_2.py:6:6: E501 Line too long (7 > 6 width) | 4 | # a 5 | # aa @@ -30,7 +30,7 @@ E501_2.py:6:6: E501 Line too long (7 > 6 characters) 8 | # a | -E501_2.py:7:6: E501 Line too long (8 > 6 characters) +E501_2.py:7:6: E501 Line too long (8 > 6 width) | 5 | # aa 6 | # aaa @@ -40,7 +40,7 @@ E501_2.py:7:6: E501 Line too long (8 > 6 characters) 9 | # aa | -E501_2.py:8:5: E501 Line too long (7 > 6 characters) +E501_2.py:8:5: E501 Line too long (7 > 6 width) | 6 | # aaa 7 | # aaaa @@ -50,7 +50,7 @@ E501_2.py:8:5: E501 Line too long (7 > 6 characters) 10 | # aaa | -E501_2.py:9:5: E501 Line too long (8 > 6 characters) +E501_2.py:9:5: E501 Line too long (8 > 6 width) | 7 | # aaaa 8 | # a @@ -59,7 +59,7 @@ E501_2.py:9:5: E501 Line too long (8 > 6 characters) 10 | # aaa | -E501_2.py:10:5: E501 Line too long (9 > 6 characters) +E501_2.py:10:5: E501 Line too long (9 > 6 width) | 8 | # a 9 | # aa @@ -69,7 +69,7 @@ E501_2.py:10:5: E501 Line too long (9 > 6 characters) 12 | if True: # noqa: E501 | -E501_2.py:14:6: E501 Line too long (7 > 6 characters) +E501_2.py:14:6: E501 Line too long (7 > 6 width) | 12 | if True: # noqa: E501 13 | [12] @@ -79,7 +79,7 @@ E501_2.py:14:6: E501 Line too long (7 > 6 characters) 16 | [1, 2] | -E501_2.py:16:6: E501 Line too long (8 > 6 characters) +E501_2.py:16:6: E501 Line too long (8 > 6 width) | 14 | [12 ] 15 | [1,2] diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_4.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_4.snap index b9717b2f59d972..6828d9fc99ee6e 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_4.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_4.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_2.py:2:7: E501 Line too long (7 > 6 characters) +E501_2.py:2:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -10,7 +10,7 @@ E501_2.py:2:7: E501 Line too long (7 > 6 characters) 4 | # a | -E501_2.py:3:7: E501 Line too long (7 > 6 characters) +E501_2.py:3:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -20,7 +20,7 @@ E501_2.py:3:7: E501 Line too long (7 > 6 characters) 5 | # aa | -E501_2.py:4:4: E501 Line too long (7 > 6 characters) +E501_2.py:4:4: E501 Line too long (7 > 6 width) | 2 | # aaaaa 3 | # a @@ -30,7 +30,7 @@ E501_2.py:4:4: E501 Line too long (7 > 6 characters) 6 | # aaa | -E501_2.py:5:4: E501 Line too long (8 > 6 characters) +E501_2.py:5:4: E501 Line too long (8 > 6 width) | 3 | # a 4 | # a @@ -40,7 +40,7 @@ E501_2.py:5:4: E501 Line too long (8 > 6 characters) 7 | # aaaa | -E501_2.py:6:4: E501 Line too long (9 > 6 characters) +E501_2.py:6:4: E501 Line too long (9 > 6 width) | 4 | # a 5 | # aa @@ -50,7 +50,7 @@ E501_2.py:6:4: E501 Line too long (9 > 6 characters) 8 | # a | -E501_2.py:7:4: E501 Line too long (10 > 6 characters) +E501_2.py:7:4: E501 Line too long (10 > 6 width) | 5 | # aa 6 | # aaa @@ -60,7 +60,7 @@ E501_2.py:7:4: E501 Line too long (10 > 6 characters) 9 | # aa | -E501_2.py:8:3: E501 Line too long (11 > 6 characters) +E501_2.py:8:3: E501 Line too long (11 > 6 width) | 6 | # aaa 7 | # aaaa @@ -70,7 +70,7 @@ E501_2.py:8:3: E501 Line too long (11 > 6 characters) 10 | # aaa | -E501_2.py:9:3: E501 Line too long (12 > 6 characters) +E501_2.py:9:3: E501 Line too long (12 > 6 width) | 7 | # aaaa 8 | # a @@ -79,7 +79,7 @@ E501_2.py:9:3: E501 Line too long (12 > 6 characters) 10 | # aaa | -E501_2.py:10:3: E501 Line too long (13 > 6 characters) +E501_2.py:10:3: E501 Line too long (13 > 6 width) | 8 | # a 9 | # aa @@ -89,7 +89,7 @@ E501_2.py:10:3: E501 Line too long (13 > 6 characters) 12 | if True: # noqa: E501 | -E501_2.py:14:4: E501 Line too long (9 > 6 characters) +E501_2.py:14:4: E501 Line too long (9 > 6 width) | 12 | if True: # noqa: E501 13 | [12] @@ -99,7 +99,7 @@ E501_2.py:14:4: E501 Line too long (9 > 6 characters) 16 | [1, 2] | -E501_2.py:16:4: E501 Line too long (10 > 6 characters) +E501_2.py:16:4: E501 Line too long (10 > 6 width) | 14 | [12 ] 15 | [1,2] diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_8.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_8.snap index 9adffbfb99aea4..53710aa8749fa8 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_8.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__tab_size_8.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_2.py:2:7: E501 Line too long (7 > 6 characters) +E501_2.py:2:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -10,7 +10,7 @@ E501_2.py:2:7: E501 Line too long (7 > 6 characters) 4 | # a | -E501_2.py:3:7: E501 Line too long (7 > 6 characters) +E501_2.py:3:7: E501 Line too long (7 > 6 width) | 1 | # aaaa 2 | # aaaaa @@ -20,7 +20,7 @@ E501_2.py:3:7: E501 Line too long (7 > 6 characters) 5 | # aa | -E501_2.py:4:2: E501 Line too long (11 > 6 characters) +E501_2.py:4:2: E501 Line too long (11 > 6 width) | 2 | # aaaaa 3 | # a @@ -30,7 +30,7 @@ E501_2.py:4:2: E501 Line too long (11 > 6 characters) 6 | # aaa | -E501_2.py:5:2: E501 Line too long (12 > 6 characters) +E501_2.py:5:2: E501 Line too long (12 > 6 width) | 3 | # a 4 | # a @@ -40,7 +40,7 @@ E501_2.py:5:2: E501 Line too long (12 > 6 characters) 7 | # aaaa | -E501_2.py:6:2: E501 Line too long (13 > 6 characters) +E501_2.py:6:2: E501 Line too long (13 > 6 width) | 4 | # a 5 | # aa @@ -50,7 +50,7 @@ E501_2.py:6:2: E501 Line too long (13 > 6 characters) 8 | # a | -E501_2.py:7:2: E501 Line too long (14 > 6 characters) +E501_2.py:7:2: E501 Line too long (14 > 6 width) | 5 | # aa 6 | # aaa @@ -60,7 +60,7 @@ E501_2.py:7:2: E501 Line too long (14 > 6 characters) 9 | # aa | -E501_2.py:8:2: E501 Line too long (19 > 6 characters) +E501_2.py:8:2: E501 Line too long (19 > 6 width) | 6 | # aaa 7 | # aaaa @@ -70,7 +70,7 @@ E501_2.py:8:2: E501 Line too long (19 > 6 characters) 10 | # aaa | -E501_2.py:9:2: E501 Line too long (20 > 6 characters) +E501_2.py:9:2: E501 Line too long (20 > 6 width) | 7 | # aaaa 8 | # a @@ -79,7 +79,7 @@ E501_2.py:9:2: E501 Line too long (20 > 6 characters) 10 | # aaa | -E501_2.py:10:2: E501 Line too long (21 > 6 characters) +E501_2.py:10:2: E501 Line too long (21 > 6 width) | 8 | # a 9 | # aa @@ -89,7 +89,7 @@ E501_2.py:10:2: E501 Line too long (21 > 6 characters) 12 | if True: # noqa: E501 | -E501_2.py:14:2: E501 Line too long (13 > 6 characters) +E501_2.py:14:2: E501 Line too long (13 > 6 width) | 12 | if True: # noqa: E501 13 | [12] @@ -99,7 +99,7 @@ E501_2.py:14:2: E501 Line too long (13 > 6 characters) 16 | [1, 2] | -E501_2.py:16:2: E501 Line too long (14 > 6 characters) +E501_2.py:16:2: E501 Line too long (14 > 6 width) | 14 | [12 ] 15 | [1,2] diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__task_tags_false.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__task_tags_false.snap index 0d29160a27fd23..842436e86dc0c2 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__task_tags_false.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__task_tags_false.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -E501_1.py:1:89: E501 Line too long (149 > 88 characters) +E501_1.py:1:89: E501 Line too long (149 > 88 width) | 1 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 @@ -9,7 +9,7 @@ E501_1.py:1:89: E501 Line too long (149 > 88 characters) 3 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:2:89: E501 Line too long (158 > 88 characters) +E501_1.py:2:89: E501 Line too long (158 > 88 width) | 1 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 2 | # TODO(charlie): comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -18,7 +18,7 @@ E501_1.py:2:89: E501 Line too long (158 > 88 characters) 4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:3:89: E501 Line too long (148 > 88 characters) +E501_1.py:3:89: E501 Line too long (148 > 88 width) | 1 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 2 | # TODO(charlie): comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -28,7 +28,7 @@ E501_1.py:3:89: E501 Line too long (148 > 88 characters) 5 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:4:89: E501 Line too long (155 > 88 characters) +E501_1.py:4:89: E501 Line too long (155 > 88 width) | 2 | # TODO(charlie): comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 3 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -38,7 +38,7 @@ E501_1.py:4:89: E501 Line too long (155 > 88 characters) 6 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:5:89: E501 Line too long (150 > 88 characters) +E501_1.py:5:89: E501 Line too long (150 > 88 width) | 3 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -48,7 +48,7 @@ E501_1.py:5:89: E501 Line too long (150 > 88 characters) 7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:6:89: E501 Line too long (149 > 88 characters) +E501_1.py:6:89: E501 Line too long (149 > 88 width) | 4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 5 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -58,7 +58,7 @@ E501_1.py:6:89: E501 Line too long (149 > 88 characters) 8 | # FIXME(charlie): comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:7:89: E501 Line too long (156 > 88 characters) +E501_1.py:7:89: E501 Line too long (156 > 88 width) | 5 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 6 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` @@ -67,7 +67,7 @@ E501_1.py:7:89: E501 Line too long (156 > 88 characters) 8 | # FIXME(charlie): comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` | -E501_1.py:8:89: E501 Line too long (159 > 88 characters) +E501_1.py:8:89: E501 Line too long (159 > 88 width) | 6 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` 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 290a7cd55294ae..1478372d14011d 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_length, + checker.settings.line_width, checker.settings.tab_size, ) { return; diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap index 357787e1539489..3dc3877a035a56 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__ruf100_0.snap @@ -237,7 +237,7 @@ RUF100_0.py:85:8: F401 [*] `shelve` imported but unused 87 86 | 88 87 | print(sys.path) -RUF100_0.py:90:89: E501 Line too long (89 > 88 characters) +RUF100_0.py:90:89: E501 Line too long (89 > 88 width) | 88 | print(sys.path) 89 | diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index 699288a4e07677..610a265c0800d1 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::{LineLength, TabSize}; +use super::line_width::{LineWidth, TabSize}; use self::rule_table::RuleTable; use self::types::PreviewMode; @@ -56,7 +56,7 @@ pub struct LinterSettings { pub dummy_variable_rgx: Regex, pub external: FxHashSet, pub ignore_init_module_imports: bool, - pub line_length: LineLength, + pub line_width: LineWidth, pub logger_objects: Vec, pub namespace_packages: Vec, pub src: Vec, @@ -147,7 +147,7 @@ impl LinterSettings { external: HashSet::default(), ignore_init_module_imports: false, - line_length: LineLength::default(), + line_width: LineWidth::default(), logger_objects: vec![], namespace_packages: vec![], diff --git a/crates/ruff_python_formatter/README.md b/crates/ruff_python_formatter/README.md index 9ae5abcd69655f..e6c35bbe81cf5c 100644 --- a/crates/ruff_python_formatter/README.md +++ b/crates/ruff_python_formatter/README.md @@ -117,12 +117,11 @@ indent-style = "tab" quote-style = "single" ``` -The Ruff formatter also respects Ruff's [`line-length`](https://docs.astral.sh/ruff/settings/#line-length) -setting, which also can be provided via a `pyproject.toml` or `ruff.toml` file, or on the CLI, as -in: +The Ruff formatter also respects Ruff's [`line-width`](https://docs.astral.sh/ruff/settings/#line-width) +setting, which also can be provided via a `pyproject.toml` or `ruff.toml` file: -```console -ruff format --line-length 100 /path/to/file.py +```toml +line-width = 100 ``` ### Excluding code from formatting diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index f2fcc8055263fc..04e4fe4f78034e 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*; use ruff_formatter::{FormatResult, Formatted, IndentStyle}; use ruff_linter::directives; -use ruff_linter::line_width::{LineLength, TabSize}; +use ruff_linter::line_width::{LineWidth, TabSize}; use ruff_linter::linter::{check_path, LinterResult}; use ruff_linter::registry::AsRule; use ruff_linter::settings::types::PythonVersion; @@ -124,7 +124,7 @@ impl Workspace { // Propagate defaults. builtins: Some(Vec::default()), - line_length: Some(LineLength::default()), + line_width: Some(LineWidth::default()), tab_size: Some(TabSize::default()), target_version: Some(PythonVersion::default()), diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 8f208da039139c..4532be95ba88f1 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -16,8 +16,8 @@ use shellexpand::LookupError; use strum::IntoEnumIterator; use ruff_cache::cache_dir; -use ruff_formatter::{IndentStyle, IndentWidth, LineWidth}; -use ruff_linter::line_width::{LineLength, TabSize}; +use ruff_formatter::{IndentStyle, IndentWidth}; +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}; @@ -131,7 +131,7 @@ pub struct Configuration { pub target_version: Option, // Global formatting options - pub line_length: Option, + pub line_width: Option, pub tab_size: Option, pub lint: LintConfiguration, @@ -162,11 +162,9 @@ impl Configuration { PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, }, - line_width: self - .line_length - .map_or(format_defaults.line_width, |length| { - LineWidth::from(NonZeroU16::from(length)) - }), + line_width: self.line_width.map_or(format_defaults.line_width, |width| { + ruff_formatter::LineWidth::from(NonZeroU16::from(width)) + }), line_ending: format.line_ending.unwrap_or(format_defaults.line_ending), indent_style: format.indent_style.unwrap_or(format_defaults.indent_style), indent_width: self @@ -225,7 +223,7 @@ 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_length: self.line_length.unwrap_or_default(), + line_width: self.line_width.unwrap_or_default(), tab_size: self.tab_size.unwrap_or_default(), namespace_packages: self.namespace_packages.unwrap_or_default(), per_file_ignores: resolve_per_file_ignores( @@ -383,6 +381,15 @@ impl Configuration { } }; + #[allow(deprecated)] + let line_width = { + if options.line_length.is_some() { + warn_user_once!("The option `line-length` has been renamed to `line-width` to emphasize that the limit is the display width of a line and not the number of characters. Use `line-width` instead."); + } + + options.line_width.or(options.line_length) + }; + Ok(Self { builtins: options.builtins, cache_dir: options @@ -449,7 +456,7 @@ impl Configuration { unsafe_fixes: options.unsafe_fixes.map(UnsafeFixes::from), output_format: options.output_format, force_exclude: options.force_exclude, - line_length: options.line_length, + line_width, tab_size: options.tab_size, namespace_packages: options .namespace_packages @@ -497,7 +504,7 @@ impl Configuration { unsafe_fixes: self.unsafe_fixes.or(config.unsafe_fixes), output_format: self.output_format.or(config.output_format), force_exclude: self.force_exclude.or(config.force_exclude), - line_length: self.line_length.or(config.line_length), + line_width: self.line_width.or(config.line_width), tab_size: self.tab_size.or(config.tab_size), namespace_packages: self.namespace_packages.or(config.namespace_packages), required_version: self.required_version.or(config.required_version), diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index d268d110de9440..bb6362a62abb50 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; use ruff_formatter::IndentStyle; -use ruff_linter::line_width::{LineLength, TabSize}; +use ruff_linter::line_width::{LineWidth, TabSize}; use ruff_linter::rules::flake8_pytest_style::settings::SettingsError; use ruff_linter::rules::flake8_pytest_style::types; use ruff_linter::rules::flake8_quotes::settings::Quote; @@ -66,7 +66,7 @@ pub struct Options { # Extend the `pyproject.toml` file in the parent directory. extend = "../pyproject.toml" # But use a different line length. - line-length = 100 + line-width = 100 "# )] pub extend: Option, @@ -351,17 +351,45 @@ pub struct Options { pub src: Option>, // Global Formatting options - /// The line length to use when enforcing long-lines violations (like - /// `E501`). Must be greater than `0` and less than or equal to `320`. + /// The maximum [width](http://www.unicode.org/reports/tr11/#Overview) of a line when + /// formatting code and when enforcing long-lines violations (like + /// `E501`). + /// + /// Must be greater than `0` and less than or equal to `320`. + /// + /// 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. + #[option( + default = "88", + value_type = "int", + example = r#" + # Allow lines to have a display width up to 120. + line-width = 120 + "# + )] + pub line_width: Option, + + /// The maximum [display width](http://www.unicode.org/reports/tr11/#Overview) of each line when + /// formatting code and when enforcing long-lines violations (like + /// `E501`). + /// + /// Must be greater than `0` and less than or equal to `320`. + /// + /// 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. #[option( default = "88", value_type = "int", example = r#" - # Allow lines to be as long as 120 characters. + # Allow lines to have a width up to 120. line-length = 120 "# )] - pub line_length: Option, + #[deprecated( + since = "0.1.1", + note = "Renamed to `line-width` to emphasize that the limit is the line's display width rather than the number of characters . Use `line-width = ` instead." + )] + pub line_length: Option, /// The number of spaces a tab is equal to when enforcing long-line violations (like `E501`) /// or formatting code with the formatter. @@ -2238,6 +2266,20 @@ 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 [`doc-line-too-long`] 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. + #[option( + default = "null", + value_type = "int", + example = r#" + max-doc-width = 88 + "# + )] + pub max_doc_width: Option, + /// The maximum line length to allow for line-length violations within /// documentation (`W505`), including standalone comments. By default, /// this is set to null which disables reporting violations. @@ -2250,7 +2292,11 @@ pub struct PycodestyleOptions { max-doc-length = 88 "# )] - pub max_doc_length: Option, + #[deprecated( + since = "0.1.1", + note = "Renamed to `max-doc-width` to emphasize that the limit is the line's display width rather than the number of characters . Use `max-doc-width = ` instead." + )] + pub max_doc_length: Option, /// Whether line-length violations (`E501`) should be triggered for /// comments starting with `task-tags` (by default: \["TODO", "FIXME", @@ -2267,8 +2313,16 @@ pub struct PycodestyleOptions { impl PycodestyleOptions { pub fn into_settings(self) -> pycodestyle::settings::Settings { + #[allow(deprecated)] + let max_doc_width = { + if self.max_doc_length.is_some() { + warn_user_once!("The option `pycodestyle.max-doc-length` has been renamed to `pycodestyle.max-doc-width` to emphasize that the limit is the display width of a line and not the number of characters. Use `pycodestyle.max-doc-width` instead."); + } + self.max_doc_width.or(self.max_doc_length) + }; + pycodestyle::settings::Settings { - max_doc_length: self.max_doc_length, + max_doc_width, ignore_overlong_task_comments: self.ignore_overlong_task_comments.unwrap_or_default(), } } diff --git a/crates/ruff_workspace/src/pyproject.rs b/crates/ruff_workspace/src/pyproject.rs index 38b7811dd634f2..609504bf9a0bae 100644 --- a/crates/ruff_workspace/src/pyproject.rs +++ b/crates/ruff_workspace/src/pyproject.rs @@ -158,7 +158,7 @@ mod tests { use rustc_hash::FxHashMap; use ruff_linter::codes; - use ruff_linter::line_width::LineLength; + use ruff_linter::line_width::LineWidth; use ruff_linter::settings::types::PatternPrefixPair; use crate::options::{LintCommonOptions, Options}; @@ -195,14 +195,14 @@ mod tests { r#" [tool.black] [tool.ruff] -line-length = 79 +line-width = 79 "#, )?; assert_eq!( pyproject.tool, Some(Tools { ruff: Some(Options { - line_length: Some(LineLength::try_from(79).unwrap()), + line_width: Some(LineWidth::try_from(79).unwrap()), ..Options::default() }) }) @@ -289,7 +289,7 @@ select = ["E123"] r#" [tool.black] [tool.ruff] -line-length = 79 +line-width = 79 other-attribute = 1 "#, ) @@ -308,7 +308,7 @@ other-attribute = 1 assert_eq!( config, Options { - line_length: Some(LineLength::try_from(88).unwrap()), + line_width: Some(LineWidth::try_from(88).unwrap()), extend_exclude: Some(vec![ "excluded_file.py".to_string(), "migrations".to_string(), diff --git a/docs/configuration.md b/docs/configuration.md index 4f91a90563d429..d8a06be736349c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -47,8 +47,8 @@ exclude = [ ] per-file-ignores = {} -# Same as Black. -line-length = 88 +# Same as Black's line-length. +line-width = 88 # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" @@ -305,8 +305,8 @@ supports an [`extend`](settings.md#extend) field, which allows you to inherit th ```toml # Extend the `pyproject.toml` file in the parent directory. extend = "../pyproject.toml" -# But use a different line length. -line-length = 100 +# But use a different line width. +line-width = 100 ``` All of the above rules apply equivalently to `ruff.toml` and `.ruff.toml` files. If Ruff detects diff --git a/docs/faq.md b/docs/faq.md index 2953408cb56c77..cc20cf7252f953 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -3,7 +3,7 @@ ## Is Ruff compatible with Black? Yes. Ruff is compatible with [Black](https://github.com/psf/black) out-of-the-box, as long as -the `line-length` setting is consistent between the two. +Ruff's `line-width` setting is consistent with Black's `line-length` setting. As a project, Ruff is designed to be used alongside Black and, as such, will defer implementing stylistic lint rules that are obviated by automated formatting. @@ -11,7 +11,7 @@ stylistic lint rules that are obviated by automated formatting. Note that Ruff and Black treat line-length enforcement a little differently. Black makes a best-effort attempt to adhere to the `line-length`, but avoids automatic line-wrapping in some cases (e.g., within comments). Ruff, on the other hand, will flag rule `E501` for any line that exceeds -the `line-length` setting. As such, if `E501` is enabled, Ruff can still trigger line-length +the `line-width` setting. As such, if `E501` is enabled, Ruff can still trigger line-width violations even when Black is enabled. ## How does Ruff compare to Flake8? @@ -404,7 +404,7 @@ For example, given this `pyproject.toml`: ```toml [tool.ruff] -line-length = 88 +line-width = 88 [tool.ruff.pydocstyle] convention = "google" @@ -413,7 +413,7 @@ convention = "google" You could instead use a `ruff.toml` file like so: ```toml -line-length = 88 +line-width = 88 [pydocstyle] convention = "google" diff --git a/docs/tutorial.md b/docs/tutorial.md index 6eb932ce003a4e..851529cb617596 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -77,15 +77,15 @@ Let's create a `pyproject.toml` file in our project's root directory: ```toml [tool.ruff] -# Decrease the maximum line length to 79 characters. -line-length = 79 +# Decrease the maximum line width to 79. +line-width = 79 ``` Running Ruff again, we can see that it now enforces a line length of 79 characters: ```shell ❯ ruff check . -numbers/numbers.py:6:80: E501 Line too long (83 > 79 characters) +numbers/numbers.py:6:80: E501 Line too long (83 > 79 width) Found 1 error. ``` @@ -98,8 +98,8 @@ specifically, we'll want to make note of the minimum supported Python version: requires-python = ">=3.10" [tool.ruff] -# Decrease the maximum line length to 79 characters. -line-length = 79 +# Decrease the maximum line width to 79 characters. +line-width = 79 src = ["src"] ``` @@ -135,7 +135,7 @@ the use of `List` instead of its standard-library variant: ```shell ❯ ruff check . numbers/numbers.py:5:31: UP006 [*] Use `list` instead of `List` for type annotations -numbers/numbers.py:6:80: E501 Line too long (83 > 79 characters) +numbers/numbers.py:6:80: E501 Line too long (83 > 79 width) Found 2 errors. [*] 1 potentially fixable with the --fix option. ``` @@ -163,7 +163,7 @@ If we run Ruff again, we'll see that it now enforces the pydocstyle rules: numbers/__init__.py:1:1: D104 Missing docstring in public package numbers/numbers.py:1:1: D100 Missing docstring in public module numbers/numbers.py:5:31: UP006 [*] Use `list` instead of `List` for type annotations -numbers/numbers.py:5:80: E501 Line too long (83 > 79 characters) +numbers/numbers.py:5:80: E501 Line too long (83 > 79 width) Found 3 errors. [*] 1 potentially fixable with the --fix option. ``` @@ -188,7 +188,7 @@ Running Ruff again, we'll see that it no longer flags the `List` import: ❯ ruff check . numbers/__init__.py:1:1: D104 Missing docstring in public package numbers/numbers.py:1:1: D100 Missing docstring in public module -numbers/numbers.py:5:80: E501 Line too long (83 > 79 characters) +numbers/numbers.py:5:80: E501 Line too long (83 > 79 width) Found 3 errors. ``` diff --git a/ruff.schema.json b/ruff.schema.json index e4ad0ae65cd86d..d8f261633aed87 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -426,10 +426,22 @@ ] }, "line-length": { - "description": "The line length to use when enforcing long-lines violations (like `E501`). Must be greater than `0` and less than or equal to `320`.", + "description": "The maximum [display width](http://www.unicode.org/reports/tr11/#Overview) of each line when formatting code and when enforcing long-lines violations (like `E501`).\n\nMust be greater than `0` and less than or equal to `320`.\n\nNote: 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.", + "deprecated": true, + "anyOf": [ + { + "$ref": "#/definitions/LineWidth" + }, + { + "type": "null" + } + ] + }, + "line-width": { + "description": "The maximum [width](http://www.unicode.org/reports/tr11/#Overview) of a line when formatting code and when enforcing long-lines violations (like `E501`).\n\nMust be greater than `0` and less than or equal to `320`.\n\nNote: 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.", "anyOf": [ { - "$ref": "#/definitions/LineLength" + "$ref": "#/definitions/LineWidth" }, { "type": "null" @@ -1594,7 +1606,7 @@ } ] }, - "LineLength": { + "LineWidth": { "description": "The length of a line of text that is considered too long.\n\nThe allowed range of values is 1..=320", "type": "integer", "format": "uint16", @@ -2198,9 +2210,21 @@ }, "max-doc-length": { "description": "The maximum line length to allow for line-length violations within documentation (`W505`), including standalone comments. By default, this is set to null which disables reporting violations.\n\nSee the [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) rule for more information.", + "deprecated": true, + "anyOf": [ + { + "$ref": "#/definitions/LineWidth" + }, + { + "type": "null" + } + ] + }, + "max-doc-width": { + "description": "The maximum [width](http://www.unicode.org/reports/tr11/#Overview) to allow for [`doc-line-too-long`] violations within documentation (`W505`), including standalone comments. By default, this is set to null which disables reporting violations.\n\nSee the [`doc-line-too-long`](https://docs.astral.sh/ruff/rules/doc-line-too-long/) rule for more information.", "anyOf": [ { - "$ref": "#/definitions/LineLength" + "$ref": "#/definitions/LineWidth" }, { "type": "null" diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 1a3a318a1a36aa..c0675933dd7e08 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -8,7 +8,7 @@ requires-python = ">=3.8" line-length = 88 [tool.ruff] -line-length = 88 +line-width = 88 select = ["ALL"] ignore = [ "C901", # McCabe complexity