Skip to content

Commit

Permalink
Fix D209 D400 conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanPlasse committed Mar 16, 2023
1 parent 9474a01 commit e568bd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
15 changes: 13 additions & 2 deletions crates/ruff/src/autofix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ruff_python_ast::source_code::Locator;
use ruff_python_ast::types::Range;

use crate::linter::FixTable;
use crate::registry::AsRule;
use crate::registry::{AsRule, Rule};

pub mod helpers;

Expand All @@ -22,6 +22,17 @@ pub fn fix_file(diagnostics: &[Diagnostic], locator: &Locator) -> Option<(String
}
}

pub fn cmp_fix(rule1: &Rule, rule2: &Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Ordering {
match fix1.location.cmp(&fix2.location) {
std::cmp::Ordering::Equal => match (rule1, rule2) {
(Rule::EndsInPeriod, Rule::NewLineAfterLastParagraph) => std::cmp::Ordering::Less,
(Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod) => std::cmp::Ordering::Greater,
_ => std::cmp::Ordering::Equal,
},
other => other,
}
}

/// Apply a series of fixes.
fn apply_fixes<'a>(
diagnostics: impl Iterator<Item = &'a Diagnostic>,
Expand All @@ -39,7 +50,7 @@ fn apply_fixes<'a>(
.as_ref()
.map(|fix| (diagnostic.kind.rule(), fix))
})
.sorted_by_key(|(.., fix)| fix.location)
.sorted_by(|(rule1, fix1), (rule2, fix2)| cmp_fix(rule1, rule2, fix1, fix2))
{
// If we already applied an identical fix as part of another correction, skip
// any re-application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,4 @@ expression: diagnostics
row: 3
column: 69
parent: ~
- kind:
name: NewLineAfterLastParagraph
body: Multi-line docstring closing quotes should be on a separate line
suggestion: Move closing quotes to new line
fixable: true
location:
row: 2
column: 4
end_location:
row: 4
column: 8
fix:
content: "\n "
location:
row: 4
column: 5
end_location:
row: 4
column: 5
parent: ~

0 comments on commit e568bd3

Please sign in to comment.