Skip to content

Commit

Permalink
Rename LineWidth to LineLength
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Aug 25, 2023
1 parent 0055640 commit 3914e5e
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 129 deletions.
6 changes: 3 additions & 3 deletions crates/ruff/src/checkers/physical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod tests {

use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use ruff_source_file::Locator;

use crate::registry::Rule;
Expand All @@ -120,7 +120,7 @@ mod tests {
let indexer = Indexer::from_tokens(&tokens, &locator);
let stylist = Stylist::from_tokens(&tokens, &locator);

let check_with_max_line_length = |line_length: LineWidth| {
let check_with_max_line_length = |line_length: LineLength| {
check_physical_lines(
&locator,
&stylist,
Expand All @@ -132,7 +132,7 @@ mod tests {
},
)
};
let line_length = LineWidth::try_from(8).unwrap();
let line_length = LineLength::try_from(8).unwrap();
assert_eq!(check_with_max_line_length(line_length), vec![]);
assert_eq!(check_with_max_line_length(line_length), vec![]);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/flake8_to_ruff/black.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Extract Black configuration settings from a pyproject.toml.

use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use serde::{Deserialize, Serialize};

use crate::settings::types::PythonVersion;

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct Black {
#[serde(alias = "line-length", alias = "line_length")]
pub line_length: Option<LineWidth>,
pub line_length: Option<LineLength>,
#[serde(alias = "target-version", alias = "target_version")]
pub target_version: Option<Vec<PythonVersion>>,
}
12 changes: 6 additions & 6 deletions crates/ruff/src/flake8_to_ruff/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;

use anyhow::Result;
use itertools::Itertools;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

use crate::registry::Linter;
use crate::rule_selector::RuleSelector;
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn convert(
"builtins" => {
options.builtins = Some(parser::parse_strings(value.as_ref()));
}
"max-line-length" | "max_line_length" => match LineWidth::from_str(value) {
"max-line-length" | "max_line_length" => match LineLength::from_str(value) {
Ok(line_length) => options.line_length = Some(line_length),
Err(e) => {
warn_user!("Unable to parse '{key}' property: {e}");
Expand Down Expand Up @@ -405,7 +405,7 @@ pub 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 {
match LineWidth::try_from(*line_length) {
match LineLength::try_from(*line_length) {
Ok(line_length) => options.line_length = Some(line_length),
Err(e) => {
warn_user!("Unable to parse black line length: {e}");
Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {
use itertools::Itertools;
use pep440_rs::VersionSpecifiers;
use pretty_assertions::assert_eq;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

use crate::flake8_to_ruff::converter::DEFAULT_SELECTORS;
use crate::flake8_to_ruff::pep621::Project;
Expand Down Expand Up @@ -518,7 +518,7 @@ mod tests {
Some(vec![]),
)?;
let expected = Pyproject::new(Options {
line_length: Some(LineWidth::try_from(100).unwrap()),
line_length: Some(LineLength::try_from(100).unwrap()),
..default_options([])
});
assert_eq!(actual, expected);
Expand All @@ -537,7 +537,7 @@ mod tests {
Some(vec![]),
)?;
let expected = Pyproject::new(Options {
line_length: Some(LineWidth::try_from(100).unwrap()),
line_length: Some(LineLength::try_from(100).unwrap()),
..default_options([])
});
assert_eq!(actual, expected);
Expand Down
17 changes: 4 additions & 13 deletions crates/ruff/src/line_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::num::NonZeroU8;
use unicode_width::UnicodeWidthChar;

use ruff_macros::CacheKey;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

/*
/// The length of a line of text that is considered too long.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, CacheKey)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
Expand All @@ -28,6 +29,7 @@ impl From<usize> for LineLength {
Self(value)
}
}
*/

/// A measure of the width of a line of text.
///
Expand Down Expand Up @@ -133,23 +135,12 @@ impl LineWidthBuilder {

impl PartialEq<LineLength> for LineWidthBuilder {
fn eq(&self, other: &LineLength) -> bool {
self.width == other.0
self.width == (other.value() as usize)
}
}

impl PartialOrd<LineLength> for LineWidthBuilder {
fn partial_cmp(&self, other: &LineLength) -> Option<std::cmp::Ordering> {
self.width.partial_cmp(&other.0)
}
}
impl PartialEq<LineWidth> for LineWidthBuilder {
fn eq(&self, other: &LineWidth) -> bool {
self.width == (other.value() as usize)
}
}

impl PartialOrd<LineWidth> for LineWidthBuilder {
fn partial_cmp(&self, other: &LineWidth) -> Option<std::cmp::Ordering> {
self.width.partial_cmp(&(other.value() as usize))
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/isort/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ruff_python_codegen::Stylist;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

use crate::line_width::LineWidthBuilder;

Expand Down Expand Up @@ -46,7 +46,7 @@ pub(crate) fn format_import_from(
import_from: &ImportFromData,
comments: &CommentSet,
aliases: &[(AliasData, CommentSet)],
line_length: LineWidth,
line_length: LineLength,
indentation_width: LineWidthBuilder,
stylist: &Stylist,
force_wrap_aliases: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/rules/isort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use normalize::normalize_imports;
use order::order_imports;
use ruff_python_ast::PySourceType;
use ruff_python_codegen::Stylist;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use ruff_source_file::Locator;
use settings::RelativeImportsOrder;
use sorting::cmp_either_import;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) fn format_imports(
block: &Block,
comments: Vec<Comment>,
locator: &Locator,
line_length: LineWidth,
line_length: LineLength,
indentation_width: LineWidthBuilder,
stylist: &Stylist,
src: &[PathBuf],
Expand Down Expand Up @@ -179,7 +179,7 @@ pub(crate) fn format_imports(
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
fn format_import_block(
block: ImportBlock,
line_length: LineWidth,
line_length: LineLength,
indentation_width: LineWidthBuilder,
stylist: &Stylist,
src: &[PathBuf],
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pycodestyle/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use unicode_width::UnicodeWidthStr;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::{CmpOp, Expr, Ranged};
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use ruff_source_file::{Line, Locator};
use ruff_text_size::{TextLen, TextRange};

Expand Down Expand Up @@ -58,7 +58,7 @@ pub(super) fn generate_comparison(

pub(super) fn is_overlong(
line: &Line,
limit: LineWidth,
limit: LineLength,
ignore_overlong_task_comments: bool,
task_tags: &[String],
tab_size: TabSize,
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
use std::path::Path;

use anyhow::Result;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use test_case::test_case;

use crate::registry::Rule;
Expand Down Expand Up @@ -170,7 +170,7 @@ mod tests {
Path::new("pycodestyle/W505.py"),
&settings::Settings {
pycodestyle: Settings {
max_doc_length: Some(LineWidth::try_from(50).unwrap()),
max_doc_length: Some(LineLength::try_from(50).unwrap()),
..Settings::default()
},
..settings::Settings::for_rule(Rule::DocLineTooLong)
Expand All @@ -186,7 +186,7 @@ mod tests {
Path::new("pycodestyle/W505_utf_8.py"),
&settings::Settings {
pycodestyle: Settings {
max_doc_length: Some(LineWidth::try_from(50).unwrap()),
max_doc_length: Some(LineLength::try_from(50).unwrap()),
..Settings::default()
},
..settings::Settings::for_rule(Rule::DocLineTooLong)
Expand All @@ -206,7 +206,7 @@ mod tests {
Path::new("pycodestyle/E501_2.py"),
&settings::Settings {
tab_size: NonZeroU8::new(tab_size).unwrap().into(),
line_length: LineWidth::try_from(6).unwrap(),
line_length: LineLength::try_from(6).unwrap(),
..settings::Settings::for_rule(Rule::LineTooLong)
},
)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/rules/pycodestyle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize};

use ruff_macros::{CacheKey, CombineOptions, ConfigurationOptions};
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

#[derive(
Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions, CombineOptions,
Expand All @@ -23,7 +23,7 @@ pub struct Options {
/// this is set to null which disables reporting violations.
///
/// See the [`doc-line-too-long`](https://beta.ruff.rs/docs/rules/doc-line-too-long/) rule for more information.
pub max_doc_length: Option<LineWidth>,
pub max_doc_length: Option<LineLength>,
#[option(
default = "false",
value_type = "bool",
Expand All @@ -39,7 +39,7 @@ pub struct Options {

#[derive(Debug, Default, CacheKey)]
pub struct Settings {
pub max_doc_length: Option<LineWidth>,
pub max_doc_length: Option<LineLength>,
pub ignore_overlong_task_comments: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pyupgrade/rules/f_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ruff_python_literal::format::{
FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate,
};
use ruff_python_parser::{lexer, Mode, Tok};
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use ruff_source_file::Locator;
use ruff_text_size::TextRange;

Expand Down Expand Up @@ -307,7 +307,7 @@ pub(crate) fn f_strings(
call: &ast::ExprCall,
summary: &FormatSummary,
template: &Expr,
line_length: LineWidth,
line_length: LineLength,
) {
if summary.has_nested_parts {
return;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/settings/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result};
use glob::{glob, GlobError, Paths, PatternError};
use regex::Regex;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use shellexpand;
use shellexpand::LookupError;

Expand Down Expand Up @@ -59,7 +59,7 @@ pub struct Configuration {
pub format: Option<SerializationFormat>,
pub ignore_init_module_imports: Option<bool>,
pub include: Option<Vec<FilePattern>>,
pub line_length: Option<LineWidth>,
pub line_length: Option<LineLength>,
pub logger_objects: Option<Vec<String>>,
pub namespace_packages: Option<Vec<PathBuf>>,
pub required_version: Option<Version>,
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/settings/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use once_cell::sync::Lazy;
use path_absolutize::path_dedot;
use regex::Regex;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use rustc_hash::FxHashSet;
use std::collections::HashSet;

Expand Down Expand Up @@ -82,7 +82,7 @@ impl Default for Settings {
force_exclude: false,
ignore_init_module_imports: false,
include: FilePatternSet::try_from_vec(INCLUDE.clone()).unwrap(),
line_length: LineWidth::default(),
line_length: LineLength::default(),
logger_objects: vec![],
namespace_packages: vec![],
per_file_ignores: vec![],
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use strum::IntoEnumIterator;

use ruff_cache::cache_dir;
use ruff_macros::CacheKey;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

use crate::registry::{Rule, RuleNamespace, RuleSet, INCOMPATIBLE_CODES};
use crate::rule_selector::{RuleSelector, Specificity};
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct Settings {
pub dummy_variable_rgx: Regex,
pub external: FxHashSet<String>,
pub ignore_init_module_imports: bool,
pub line_length: LineWidth,
pub line_length: LineLength,
pub logger_objects: Vec<String>,
pub namespace_packages: Vec<PathBuf>,
pub src: Vec<PathBuf>,
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/settings/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};

use ruff_macros::ConfigurationOptions;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;

use crate::line_width::TabSize;
use crate::rule_selector::RuleSelector;
Expand Down Expand Up @@ -314,7 +314,7 @@ pub struct Options {
)]
/// The line length to use when enforcing long-lines violations (like
/// `E501`). Must be greater than `0`.
pub line_length: Option<LineWidth>,
pub line_length: Option<LineLength>,
#[option(
default = "4",
value_type = "int",
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/settings/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod tests {
use std::str::FromStr;

use anyhow::Result;
use ruff_python_trivia::LineWidth;
use ruff_python_trivia::LineLength;
use rustc_hash::FxHashMap;

use crate::codes::{self, RuleCodePrefix};
Expand Down Expand Up @@ -194,7 +194,7 @@ line-length = 79
pyproject.tool,
Some(Tools {
ruff: Some(Options {
line_length: Some(LineWidth::try_from(79).unwrap()),
line_length: Some(LineLength::try_from(79).unwrap()),
..Options::default()
})
})
Expand Down Expand Up @@ -294,7 +294,7 @@ other-attribute = 1
assert_eq!(
config,
Options {
line_length: Some(LineWidth::try_from(88).unwrap()),
line_length: Some(LineLength::try_from(88).unwrap()),
extend_exclude: Some(vec![
"excluded_file.py".to_string(),
"migrations".to_string(),
Expand Down
Loading

0 comments on commit 3914e5e

Please sign in to comment.