mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Reduce explcit clones (#3793)
This commit is contained in:
parent
b6f1fed424
commit
595cd065f3
73 changed files with 557 additions and 484 deletions
|
@ -65,7 +65,7 @@ pub struct Generator<'a> {
|
|||
/// The quote style to use for string literals.
|
||||
quote: Quote,
|
||||
/// The line ending to use.
|
||||
line_ending: &'a LineEnding,
|
||||
line_ending: LineEnding,
|
||||
buffer: String,
|
||||
indent_depth: usize,
|
||||
num_newlines: usize,
|
||||
|
@ -87,7 +87,7 @@ impl<'a> From<&'a Stylist<'a>> for Generator<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Generator<'a> {
|
||||
pub const fn new(indent: &'a Indentation, quote: Quote, line_ending: &'a LineEnding) -> Self {
|
||||
pub const fn new(indent: &'a Indentation, quote: Quote, line_ending: LineEnding) -> Self {
|
||||
Self {
|
||||
// Style preferences.
|
||||
indent,
|
||||
|
@ -128,7 +128,7 @@ impl<'a> Generator<'a> {
|
|||
fn p(&mut self, s: &str) {
|
||||
if self.num_newlines > 0 {
|
||||
for _ in 0..self.num_newlines {
|
||||
self.buffer += self.line_ending;
|
||||
self.buffer += &self.line_ending;
|
||||
}
|
||||
self.num_newlines = 0;
|
||||
}
|
||||
|
@ -1266,7 +1266,7 @@ mod tests {
|
|||
let line_ending = LineEnding::default();
|
||||
let program = parser::parse_program(contents, "<filename>").unwrap();
|
||||
let stmt = program.first().unwrap();
|
||||
let mut generator = Generator::new(&indentation, quote, &line_ending);
|
||||
let mut generator = Generator::new(&indentation, quote, line_ending);
|
||||
generator.unparse_stmt(stmt);
|
||||
generator.generate()
|
||||
}
|
||||
|
@ -1274,7 +1274,7 @@ mod tests {
|
|||
fn round_trip_with(
|
||||
indentation: &Indentation,
|
||||
quote: Quote,
|
||||
line_ending: &LineEnding,
|
||||
line_ending: LineEnding,
|
||||
contents: &str,
|
||||
) -> String {
|
||||
let program = parser::parse_program(contents, "<filename>").unwrap();
|
||||
|
@ -1449,7 +1449,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::Double,
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#""hello""#
|
||||
),
|
||||
r#""hello""#
|
||||
|
@ -1458,7 +1458,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::Single,
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#""hello""#
|
||||
),
|
||||
r#"'hello'"#
|
||||
|
@ -1467,7 +1467,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::Double,
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#"'hello'"#
|
||||
),
|
||||
r#""hello""#
|
||||
|
@ -1476,7 +1476,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::Single,
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#"'hello'"#
|
||||
),
|
||||
r#"'hello'"#
|
||||
|
@ -1489,7 +1489,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::new(" ".to_string()),
|
||||
Quote::default(),
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#"
|
||||
if True:
|
||||
pass
|
||||
|
@ -1507,7 +1507,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::new(" ".to_string()),
|
||||
Quote::default(),
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#"
|
||||
if True:
|
||||
pass
|
||||
|
@ -1525,7 +1525,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::new("\t".to_string()),
|
||||
Quote::default(),
|
||||
&LineEnding::default(),
|
||||
LineEnding::default(),
|
||||
r#"
|
||||
if True:
|
||||
pass
|
||||
|
@ -1547,7 +1547,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::default(),
|
||||
&LineEnding::Lf,
|
||||
LineEnding::Lf,
|
||||
"if True:\n print(42)",
|
||||
),
|
||||
"if True:\n print(42)",
|
||||
|
@ -1557,7 +1557,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::default(),
|
||||
&LineEnding::CrLf,
|
||||
LineEnding::CrLf,
|
||||
"if True:\n print(42)",
|
||||
),
|
||||
"if True:\r\n print(42)",
|
||||
|
@ -1567,7 +1567,7 @@ if True:
|
|||
round_trip_with(
|
||||
&Indentation::default(),
|
||||
Quote::default(),
|
||||
&LineEnding::Cr,
|
||||
LineEnding::Cr,
|
||||
"if True:\n print(42)",
|
||||
),
|
||||
"if True:\r print(42)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue