Fix start >= end error in over-indentation (#8982)

Closes https://github.com/astral-sh/ruff/issues/8977.
This commit is contained in:
Charlie Marsh 2023-12-03 15:19:43 -05:00 committed by GitHub
parent 17c8817695
commit b358cbf398
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 41 deletions

View file

@ -1,3 +1,8 @@
"""
Author
"""
class Platform: class Platform:
""" Remove sampler """ Remove sampler
Args: Args:

View file

@ -251,7 +251,8 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic = let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(line.start())); Diagnostic::new(OverIndentation, TextRange::empty(line.start()));
let edit = if indent.is_empty() { let edit = if indent.is_empty() {
Edit::deletion(line.start(), line_indent.text_len()) // Delete the entire indent.
Edit::range_deletion(TextRange::at(line.start(), line_indent.text_len()))
} else { } else {
// Convert the character count to an offset within the source. // Convert the character count to an offset within the source.
let offset = checker let offset = checker

View file

@ -1,57 +1,75 @@
--- ---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
--- ---
D208.py:3:1: D208 [*] Docstring is over-indented D208.py:2:1: D208 [*] Docstring is over-indented
| |
1 | class Platform: 1 | """
2 | """ Remove sampler 2 | Author
3 | Args:
| D208 | D208
4 |     Returns: 3 | """
5 | """
| |
= help: Remove over-indentation = help: Remove over-indentation
Safe fix Safe fix
1 1 | class Platform: 1 1 | """
2 2 | """ Remove sampler 2 |- Author
3 |- Args: 2 |+Author
3 |+ Args: 3 3 | """
4 4 |     Returns: 4 4 |
5 5 | """ 5 5 |
D208.py:4:1: D208 [*] Docstring is over-indented D208.py:8:1: D208 [*] Docstring is over-indented
| |
2 | """ Remove sampler 6 | class Platform:
3 | Args: 7 | """ Remove sampler
4 |     Returns: 8 | Args:
| D208 | D208
5 | """ 9 |     Returns:
| 10 | """
= help: Remove over-indentation |
= help: Remove over-indentation
Safe fix Safe fix
1 1 | class Platform: 5 5 |
2 2 | """ Remove sampler 6 6 | class Platform:
3 3 | Args: 7 7 | """ Remove sampler
4 |-     Returns: 8 |- Args:
4 |+ Returns: 8 |+ Args:
5 5 | """ 9 9 |     Returns:
10 10 | """
D208.py:5:1: D208 [*] Docstring is over-indented D208.py:9:1: D208 [*] Docstring is over-indented
| |
3 | Args: 7 | """ Remove sampler
4 |     Returns: 8 | Args:
5 | """ 9 |     Returns:
| D208 | D208
| 10 | """
= help: Remove over-indentation |
= help: Remove over-indentation
Safe fix Safe fix
2 2 | """ Remove sampler 6 6 | class Platform:
3 3 | Args: 7 7 | """ Remove sampler
4 4 |     Returns: 8 8 | Args:
5 |- """ 9 |-     Returns:
5 |+ """ 9 |+ Returns:
10 10 | """
D208.py:10:1: D208 [*] Docstring is over-indented
|
8 | Args:
9 |     Returns:
10 | """
| D208
|
= help: Remove over-indentation
Safe fix
7 7 | """ Remove sampler
8 8 | Args:
9 9 |     Returns:
10 |- """
10 |+ """