Unify line size settings between ruff and the formatter (#6873)

This commit is contained in:
konsti 2023-08-28 08:44:56 +02:00 committed by GitHub
parent a6aa16630d
commit e615870659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 227 additions and 190 deletions

View file

@ -21,6 +21,7 @@ use similar::{ChangeTag, TextDiff};
use std::fmt::{Display, Formatter};
use std::fs::File;
use std::io::{BufWriter, Write};
use std::num::NonZeroU16;
use std::ops::{Add, AddAssign};
use std::panic::catch_unwind;
use std::path::{Path, PathBuf};
@ -838,7 +839,7 @@ struct PyprojectTomlTool {
struct BlackOptions {
// Black actually allows both snake case and kebab case
#[serde(alias = "line-length")]
line_length: u16,
line_length: NonZeroU16,
#[serde(alias = "skip-magic-trailing-comma")]
skip_magic_trailing_comma: bool,
#[allow(unused)]
@ -849,7 +850,7 @@ struct BlackOptions {
impl Default for BlackOptions {
fn default() -> Self {
Self {
line_length: 88,
line_length: NonZeroU16::new(88).unwrap(),
skip_magic_trailing_comma: false,
force_exclude: None,
}
@ -893,9 +894,7 @@ impl BlackOptions {
fn to_py_format_options(&self, file: &Path) -> PyFormatOptions {
PyFormatOptions::from_extension(file)
.with_line_width(
LineWidth::try_from(self.line_length).expect("Invalid line length limit"),
)
.with_line_width(LineWidth::from(self.line_length))
.with_magic_trailing_comma(if self.skip_magic_trailing_comma {
MagicTrailingComma::Ignore
} else {