Skip to content

Commit

Permalink
Avoid debug panic with empty indent replacement (astral-sh#4364)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored May 11, 2023
1 parent f4f8830 commit 3b26bf8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/ruff/src/rules/pydocstyle/rules/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(over_indented.start()));
if checker.patch(diagnostic.kind.rule()) {
let new_indent = whitespace::clean(docstring.indentation);

let edit = if new_indent.is_empty() {
let indent = whitespace::clean(docstring.indentation);
let edit = if indent.is_empty() {
Edit::range_deletion(over_indented)
} else {
Edit::range_replacement(new_indent, over_indented)
Edit::range_replacement(indent, over_indented)
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
Expand All @@ -153,11 +152,15 @@ pub fn indent(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(last.start()));
if checker.patch(diagnostic.kind.rule()) {
let indent = whitespace::clean(docstring.indentation);
let range = TextRange::at(last.start(), line_indent.text_len());
let edit = if indent.is_empty() {
Edit::range_deletion(range)
} else {
Edit::range_replacement(indent, range)
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
whitespace::clean(docstring.indentation),
TextRange::at(last.start(), line_indent.text_len()),
)));
diagnostic.set_fix(Fix::unspecified(edit));
}
checker.diagnostics.push(diagnostic);
}
Expand Down

0 comments on commit 3b26bf8

Please sign in to comment.