mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Unify line size settings between ruff and the formatter (#6873)
This commit is contained in:
parent
a6aa16630d
commit
e615870659
28 changed files with 227 additions and 190 deletions
|
@ -3,9 +3,9 @@ use std::str::FromStr;
|
|||
|
||||
use clap::{command, Parser};
|
||||
use regex::Regex;
|
||||
use ruff::line_width::LineLength;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff::line_width::LineLength;
|
||||
use ruff::logging::LogLevel;
|
||||
use ruff::registry::Rule;
|
||||
use ruff::settings::types::{
|
||||
|
@ -256,7 +256,7 @@ pub struct CheckArgs {
|
|||
/// Set the line-length for length-associated rules and automatic
|
||||
/// formatting.
|
||||
#[arg(long, help_heading = "Rule configuration", hide = true)]
|
||||
pub line_length: Option<usize>,
|
||||
pub line_length: Option<LineLength>,
|
||||
/// Regular expression matching the name of dummy variables.
|
||||
#[arg(long, help_heading = "Rule configuration", hide = true)]
|
||||
pub dummy_variable_rgx: Option<Regex>,
|
||||
|
@ -497,7 +497,7 @@ pub struct Overrides {
|
|||
pub extend_unfixable: Option<Vec<RuleSelector>>,
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
pub line_length: Option<usize>,
|
||||
pub line_length: Option<LineLength>,
|
||||
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||
pub respect_gitignore: Option<bool>,
|
||||
pub select: Option<Vec<RuleSelector>>,
|
||||
|
@ -560,7 +560,7 @@ impl ConfigProcessor for Overrides {
|
|||
config.force_exclude = Some(*force_exclude);
|
||||
}
|
||||
if let Some(line_length) = &self.line_length {
|
||||
config.line_length = Some(LineLength::from(*line_length));
|
||||
config.line_length = Some(*line_length);
|
||||
}
|
||||
if let Some(per_file_ignores) = &self.per_file_ignores {
|
||||
config.per_file_ignores = Some(collect_per_file_ignores(per_file_ignores.clone()));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::io;
|
||||
use std::num::NonZeroU16;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -49,12 +50,8 @@ pub(crate) fn format(cli: &Arguments, overrides: &Overrides) -> Result<ExitStatu
|
|||
}
|
||||
|
||||
let line_length = resolver.resolve(path, &pyproject_config).line_length;
|
||||
// TODO(konstin): Unify `LineWidth` and `LineLength`
|
||||
let line_width = LineWidth::try_from(
|
||||
u16::try_from(line_length.get()).expect("Line shouldn't be larger than 2**16"),
|
||||
)
|
||||
.expect("Configured line length is too large for the formatter");
|
||||
let options = PyFormatOptions::from_extension(path).with_line_width(line_width);
|
||||
let options = PyFormatOptions::from_extension(path)
|
||||
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)));
|
||||
|
||||
format_path(path, options)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue