Use deletion for D215 full-line removals (#7625)

Closes https://github.com/astral-sh/ruff/issues/7619.
This commit is contained in:
Charlie Marsh 2023-09-23 18:44:55 -04:00 committed by GitHub
parent 8ba8896a7f
commit 1a22eae98c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 6 deletions

View file

@ -0,0 +1,4 @@
"""
TODO:
-
"""

View file

@ -79,6 +79,7 @@ mod tests {
#[test_case(Rule::SectionNameEndsInColon, Path::new("D.py"))]
#[test_case(Rule::SectionNotOverIndented, Path::new("sections.py"))]
#[test_case(Rule::SectionNotOverIndented, Path::new("D214_module.py"))]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("D215.py"))]
#[test_case(Rule::SectionUnderlineAfterName, Path::new("sections.py"))]
#[test_case(Rule::SectionUnderlineMatchesSectionLength, Path::new("sections.py"))]
#[test_case(Rule::SectionUnderlineNotOverIndented, Path::new("sections.py"))]

View file

@ -1440,16 +1440,17 @@ fn blanks_and_section_underline(
docstring.range(),
);
if checker.patch(diagnostic.kind.rule()) {
// Replace the existing indentation with whitespace of the appropriate length.
let range = TextRange::at(
blank_lines_end,
leading_space.text_len() + TextSize::from(1),
);
// Replace the existing indentation with whitespace of the appropriate length.
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
clean_space(docstring.indentation),
range,
)));
let contents = clean_space(docstring.indentation);
diagnostic.set_fix(Fix::automatic(if contents.is_empty() {
Edit::range_deletion(range)
} else {
Edit::range_replacement(contents, range)
}));
};
checker.diagnostics.push(diagnostic);
}

View file

@ -0,0 +1,21 @@
---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
---
D215.py:1:1: D215 [*] Section underline is over-indented ("TODO")
|
1 | / """
2 | | TODO:
3 | | -
4 | | """
| |___^ D215
|
= help: Remove over-indentation from "TODO" underline
Fix
1 1 | """
2 2 | TODO:
3 |- -
3 |+
4 4 | """