Skip to content

Commit 5aa797b

Browse files
committed
fix(linter): avoid overlapping edits between prefer-arrow-function and prefer-static-closure
closes #828 Signed-off-by: azjezz <[email protected]>
1 parent 854c667 commit 5aa797b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/linter/src/rule/best_practices/prefer_arrow_function.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ impl LintRule for PreferArrowFunctionRule {
136136
.with_help("Consider rewriting this as an arrow function to improve readability.");
137137

138138
ctx.collector.propose(issue, |edits| {
139-
let to_replace_with_fn = closure.function.span;
139+
let function_span = closure.function.span;
140+
let to_replace_with_n = function_span.from_start(function_span.start.forward(1));
140141
let to_replace_with_arrow = match &closure.use_clause {
141142
Some(use_clause) => use_clause.span().join(keyword.span),
142143
None => closure.body.left_brace.join(keyword.span),
143144
};
144145
let to_remove = terminator.span().join(closure.body.right_brace);
145146

146-
edits.push(TextEdit::replace(to_replace_with_fn, "fn").with_safety(Safety::PotentiallyUnsafe));
147+
edits.push(TextEdit::replace(to_replace_with_n, "n").with_safety(Safety::PotentiallyUnsafe));
147148
edits.push(TextEdit::replace(to_replace_with_arrow, "=>").with_safety(Safety::PotentiallyUnsafe));
148149
edits.push(TextEdit::delete(to_remove).with_safety(Safety::PotentiallyUnsafe));
149150
});

0 commit comments

Comments
 (0)