Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deletion for D215 full-line removals #7625

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydocstyle/D215.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
TODO:
-
"""
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/pydocstyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
13 changes: 7 additions & 6 deletions crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 | """


Loading