Skip to content

Commit 3e2f778

Browse files
committed
remove dedent_to usage from adjust_indentation`
1 parent 5107a50 commit 3e2f778

5 files changed

Lines changed: 14 additions & 39 deletions

File tree

crates/ruff_linter/src/fix/edits.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use ruff_python_ast::{self as ast, Arguments, ExceptHandler, Expr, ExprList, Stm
88
use ruff_python_ast::{AnyNodeRef, ArgOrKeyword};
99
use ruff_python_codegen::Stylist;
1010
use ruff_python_index::Indexer;
11-
use ruff_python_trivia::textwrap::dedent_to;
1211
use ruff_python_trivia::{
1312
has_leading_content, is_python_whitespace, CommentRanges, PythonWhitespace, SimpleTokenKind,
1413
SimpleTokenizer,
@@ -297,34 +296,27 @@ pub(crate) fn adjust_indentation(
297296
range: TextRange,
298297
indentation: &str,
299298
locator: &Locator,
300-
indexer: &Indexer,
301299
stylist: &Stylist,
302300
) -> Result<String> {
303301
// If the range includes a multi-line string, use LibCST to ensure that we don't adjust the
304302
// whitespace _within_ the string.
305-
if indexer.multiline_ranges().intersects(range) || indexer.fstring_ranges().intersects(range) {
306-
let contents = locator.slice(range);
303+
let contents = locator.slice(range);
307304

308-
let module_text = format!("def f():{}{contents}", stylist.line_ending().as_str());
305+
let module_text = format!("def f():{}{contents}", stylist.line_ending().as_str());
309306

310-
let mut tree = match_statement(&module_text)?;
307+
let mut tree = match_statement(&module_text)?;
311308

312-
let embedding = match_function_def(&mut tree)?;
309+
let embedding = match_function_def(&mut tree)?;
313310

314-
let indented_block = match_indented_block(&mut embedding.body)?;
315-
indented_block.indent = Some(indentation);
311+
let indented_block = match_indented_block(&mut embedding.body)?;
312+
indented_block.indent = Some(indentation);
316313

317-
let module_text = indented_block.codegen_stylist(stylist);
318-
let module_text = module_text
319-
.strip_prefix(stylist.line_ending().as_str())
320-
.unwrap()
321-
.to_string();
322-
Ok(module_text)
323-
} else {
324-
// Otherwise, we can do a simple adjustment ourselves.
325-
let contents = locator.slice(range);
326-
Ok(dedent_to(contents, indentation))
327-
}
314+
let module_text = indented_block.codegen_stylist(stylist);
315+
let module_text = module_text
316+
.strip_prefix(stylist.line_ending().as_str())
317+
.unwrap()
318+
.to_string();
319+
Ok(module_text)
328320
}
329321

330322
/// Determine if a vector contains only one, specific element.

crates/ruff_linter/src/rules/flake8_return/rules/function.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,6 @@ fn remove_else(
877877
TextRange::new(else_colon_end, elif_else.end()),
878878
desired_indentation,
879879
locator,
880-
indexer,
881880
stylist,
882881
)?;
883882

crates/ruff_linter/src/rules/pylint/rules/collapsible_else_if.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
55
use ruff_macros::{derive_message_formats, violation};
66
use ruff_python_ast::{self as ast, ElifElseClause, Stmt};
77
use ruff_python_codegen::Stylist;
8-
use ruff_python_index::Indexer;
98
use ruff_source_file::Locator;
109
use ruff_text_size::{Ranged, TextRange};
1110

@@ -85,15 +84,8 @@ pub(crate) fn collapsible_else_if(checker: &mut Checker, stmt: &Stmt) {
8584
CollapsibleElseIf,
8685
TextRange::new(else_clause.start(), first.start()),
8786
);
88-
diagnostic.try_set_fix(|| {
89-
convert_to_elif(
90-
first,
91-
else_clause,
92-
checker.locator(),
93-
checker.indexer(),
94-
checker.stylist(),
95-
)
96-
});
87+
diagnostic
88+
.try_set_fix(|| convert_to_elif(first, else_clause, checker.locator(), checker.stylist()));
9789
checker.diagnostics.push(diagnostic);
9890
}
9991

@@ -102,7 +94,6 @@ fn convert_to_elif(
10294
first: &Stmt,
10395
else_clause: &ElifElseClause,
10496
locator: &Locator,
105-
indexer: &Indexer,
10697
stylist: &Stylist,
10798
) -> Result<Fix> {
10899
let inner_if_line_start = locator.line_start(first.start());
@@ -118,7 +109,6 @@ fn convert_to_elif(
118109
TextRange::new(inner_if_line_start, inner_if_line_end),
119110
indentation,
120111
locator,
121-
indexer,
122112
stylist,
123113
)?;
124114

crates/ruff_linter/src/rules/pylint/rules/useless_else_on_loop.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use ruff_macros::{derive_message_formats, violation};
66
use ruff_python_ast::identifier;
77
use ruff_python_ast::{self as ast, ExceptHandler, MatchCase, Stmt};
88
use ruff_python_codegen::Stylist;
9-
use ruff_python_index::Indexer;
109
use ruff_source_file::Locator;
1110
use ruff_text_size::{Ranged, TextRange};
1211

@@ -82,7 +81,6 @@ pub(crate) fn useless_else_on_loop(
8281
orelse,
8382
else_range,
8483
checker.locator(),
85-
checker.indexer(),
8684
checker.stylist(),
8785
)
8886
});
@@ -136,7 +134,6 @@ fn remove_else(
136134
orelse: &[Stmt],
137135
else_range: TextRange,
138136
locator: &Locator,
139-
indexer: &Indexer,
140137
stylist: &Stylist,
141138
) -> Result<Fix> {
142139
let Some(start) = orelse.first() else {
@@ -167,7 +164,6 @@ fn remove_else(
167164
),
168165
desired_indentation,
169166
locator,
170-
indexer,
171167
stylist,
172168
)?;
173169

crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ fn fix_always_false_branch(
304304
),
305305
indentation,
306306
checker.locator(),
307-
checker.indexer(),
308307
checker.stylist(),
309308
)
310309
.ok()
@@ -379,7 +378,6 @@ fn fix_always_true_branch(
379378
TextRange::new(checker.locator().line_start(start.start()), end.end()),
380379
indentation,
381380
checker.locator(),
382-
checker.indexer(),
383381
checker.stylist(),
384382
)
385383
.ok()

0 commit comments

Comments
 (0)