Skip to content

Commit

Permalink
Deduplicate autofixes in the autofixer
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Apr 26, 2023
1 parent 5fa866e commit e314827
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/ruff/src/rules/pydocstyle/rules/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,18 @@ fn common_section(checker: &mut Checker, docstring: &Docstring, context: &Sectio
},
Range::from(docstring.expr),
);
if checker.patch(diagnostic.kind.rule())
&& !checker.patch(Rule::NoBlankLineBeforeSection)
{
// Add a newline after the section if we haven't already added one from
// `NoBlankLineBeforeSection`.
let line = context.following_lines.last().unwrap_or(&context.line);

if checker.patch(diagnostic.kind.rule()) {
// Add a blank line on the line after this section so that the new line doesn't
// conflict with NoBlankLineBeforeSection.
diagnostic.set_fix(Edit::insertion(
line_end.to_string(),
Location::new(
docstring.expr.location.row()
+ context.original_index
+ context.following_lines.len(),
line.trim_end().chars().count(),
+ context.following_lines.len()
+ 1,
0,
),
));
}
Expand Down

0 comments on commit e314827

Please sign in to comment.