Skip to content

[ruff] update and vendor annotate-snippets #15359

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

Merged
merged 23 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
143bd49
crates: vendor `annotate-snippets` crate
BurntSushi Dec 20, 2024
45bd9a1
ruff_annotate_snippets: make small change to enable omitting header
BurntSushi Dec 20, 2024
8ebb10e
ruff_linter,ruff_python_parser: migrate to updated `annotate-snippets`
BurntSushi Dec 20, 2024
dbc8732
ruff_linter: fix handling of unprintable characters
BurntSushi Jan 8, 2025
d97d74f
test: update snapshots with just whitespace changes
BurntSushi Jan 7, 2025
e1802df
test: update snapshots with missing annotations
BurntSushi Jan 7, 2025
566618c
test: update formatting of multi-line annotations
BurntSushi Jan 7, 2025
b905928
test: update snapshots with missing `^`
BurntSushi Jan 7, 2025
9228a2b
test: update snapshots with improper end-of-line placement
BurntSushi Jan 7, 2025
3f19d13
test: another line terminator bug fix
BurntSushi Jan 7, 2025
2a9f5ad
test: another set of updates related to line terminator handling
BurntSushi Jan 8, 2025
638c9a8
test: update snapshot with fixed annotation but carets include whites…
BurntSushi Jan 8, 2025
0b165ac
test: update another improperly rendered range
BurntSushi Jan 8, 2025
42160c1
ruff_annotate_snippets: update snapshot for single ASCII whitespace s…
BurntSushi Jan 8, 2025
51911c4
ruff_annotate_snippets: fix false positive line trimming
BurntSushi Jan 8, 2025
c3f4a65
ruff_annotate_snippets: support overriding the "cut indicator"
BurntSushi Jan 9, 2025
6d680d1
test: update snapshots with trimmed lines
BurntSushi Jan 8, 2025
50a77d1
test: tweak in alignment involving unprintable characters
BurntSushi Jan 8, 2025
85b441a
codeowners: make BurntSushi owner of ruff_annotate_snippets
BurntSushi Jan 14, 2025
17f5138
test: another update to add back a caret
BurntSushi Jan 14, 2025
ba5ccbb
test: add more missing carets
BurntSushi Jan 14, 2025
458153d
test: update a few indentation related diagnostics
BurntSushi Jan 14, 2025
6b3bda4
ruff_linter: adjust empty spans after line terminator more generally
BurntSushi Jan 15, 2025
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
39 changes: 33 additions & 6 deletions crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,20 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
// We report under-indentation on every line. This isn't great, but enables
// fix.
if (is_last || !is_blank) && line_indent_size < docstring_indent_size {
let mut diagnostic =
Diagnostic::new(UnderIndentation, TextRange::empty(line.start()));
// Previously, this used `TextRange::empty(line.start())`,
// but this creates an offset immediately after the line
// terminator. Probably, our renderer should create an
// annotation that points to the beginning of the following
// line. But it doesn't at present and this have proved
// difficult to fix without regressing other cases. So for now,
// we work around this by creating a range that points at the
// first codepoint in the corresponding line. This makes the
// renderer do what we want. ---AG
let start = line.start();
let end = checker
.locator()
.ceil_char_boundary(start + TextSize::from(1));
let mut diagnostic = Diagnostic::new(UnderIndentation, TextRange::new(start, end));
diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement(
clean_space(docstring.indentation),
TextRange::at(line.start(), line_indent.text_len()),
Expand Down Expand Up @@ -281,8 +293,16 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {

// We report over-indentation on every line. This isn't great, but
// enables the fix capability.
let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(line.start()));
//
// Also, we ensure that our range points to the first character
// of the line instead of the empty spance immediately
// preceding the line. See above for how we handle under
// indentation for more explanation. ---AG
let start = line.start();
let end = checker
.locator()
.ceil_char_boundary(start + TextSize::from(1));
let mut diagnostic = Diagnostic::new(OverIndentation, TextRange::new(start, end));

let edit = if indent.is_empty() {
// Delete the entire indent.
Expand Down Expand Up @@ -324,8 +344,15 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {

let is_indent_only = line_indent.len() == last.len();
if last_line_over_indent > 0 && is_indent_only {
let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(last.start()));
// We ensure that our range points to the first character of
// the line instead of the empty spance immediately preceding
// the line. See above for how we handle under indentation for
// more explanation. ---AG
let start = last.start();
let end = checker
.locator()
.ceil_char_boundary(start + TextSize::from(1));
let mut diagnostic = Diagnostic::new(OverIndentation, TextRange::new(start, end));
let indent = clean_space(docstring.indentation);
let range = TextRange::at(last.start(), line_indent.text_len());
let edit = if indent.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
snapshot_kind: text
---
D.py:232:1: D207 [*] Docstring is under-indented
|
230 | """Summary.
231 |
231 |
232 | Description.
| D207
233 |
| ^ D207
233 |
234 | """
|
= help: Increase indentation
Expand All @@ -26,9 +25,9 @@ D.py:232:1: D207 [*] Docstring is under-indented
D.py:244:1: D207 [*] Docstring is under-indented
|
242 | Description.
243 |
243 |
244 | """
| D207
| ^ D207
|
= help: Increase indentation

Expand All @@ -45,9 +44,9 @@ D.py:244:1: D207 [*] Docstring is under-indented
D.py:440:1: D207 [*] Docstring is under-indented
|
438 | def docstring_start_in_same_line(): """First Line.
439 |
439 |
440 | Second Line
| D207
| ^ D207
441 | """
|
= help: Increase indentation
Expand All @@ -66,7 +65,7 @@ D.py:441:1: D207 [*] Docstring is under-indented
|
440 | Second Line
441 | """
| D207
| ^ D207
|
= help: Increase indentation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
snapshot_kind: text
---
D.py:252:1: D208 [*] Docstring is over-indented
|
250 | """Summary.
251 |
251 |
252 | Description.
| D208
253 |
| ^ D208
253 |
254 | """
|
= help: Remove over-indentation
Expand All @@ -26,9 +25,9 @@ D.py:252:1: D208 [*] Docstring is over-indented
D.py:264:1: D208 [*] Docstring is over-indented
|
262 | Description.
263 |
263 |
264 | """
| D208
| ^ D208
|
= help: Remove over-indentation

Expand All @@ -45,10 +44,10 @@ D.py:264:1: D208 [*] Docstring is over-indented
D.py:272:1: D208 [*] Docstring is over-indented
|
270 | """Summary.
271 |
271 |
272 | Description.
| D208
273 |
| ^ D208
273 |
274 | """
|
= help: Remove over-indentation
Expand All @@ -66,9 +65,9 @@ D.py:272:1: D208 [*] Docstring is over-indented
D.py:673:1: D208 [*] Docstring is over-indented
|
671 | """Summary.
672 |
672 |
673 | This is overindented
| D208
| ^ D208
674 | And so is this, but it we should preserve the extra space on this line relative
675 | to the one before
|
Expand All @@ -88,7 +87,7 @@ D.py:674:1: D208 [*] Docstring is over-indented
|
673 | This is overindented
674 | And so is this, but it we should preserve the extra space on this line relative
| D208
| ^ D208
675 | to the one before
676 | """
|
Expand All @@ -109,7 +108,7 @@ D.py:675:1: D208 [*] Docstring is over-indented
673 | This is overindented
674 | And so is this, but it we should preserve the extra space on this line relative
675 | to the one before
| D208
| ^ D208
676 | """
|
= help: Remove over-indentation
Expand All @@ -127,9 +126,9 @@ D.py:675:1: D208 [*] Docstring is over-indented
D.py:682:1: D208 [*] Docstring is over-indented
|
680 | """Summary.
681 |
681 |
682 | This is overindented
| D208
| ^ D208
683 | And so is this, but it we should preserve the extra space on this line relative
684 | to the one before
|
Expand All @@ -149,7 +148,7 @@ D.py:683:1: D208 [*] Docstring is over-indented
|
682 | This is overindented
683 | And so is this, but it we should preserve the extra space on this line relative
| D208
| ^ D208
684 | to the one before
685 | This is also overindented
|
Expand All @@ -170,7 +169,7 @@ D.py:684:1: D208 [*] Docstring is over-indented
682 | This is overindented
683 | And so is this, but it we should preserve the extra space on this line relative
684 | to the one before
| D208
| ^ D208
685 | This is also overindented
686 | And so is this, but it we should preserve the extra space on this line relative
|
Expand All @@ -191,7 +190,7 @@ D.py:685:1: D208 [*] Docstring is over-indented
683 | And so is this, but it we should preserve the extra space on this line relative
684 | to the one before
685 | This is also overindented
| D208
| ^ D208
686 | And so is this, but it we should preserve the extra space on this line relative
687 | to the one before
|
Expand All @@ -212,7 +211,7 @@ D.py:686:1: D208 [*] Docstring is over-indented
684 | to the one before
685 | This is also overindented
686 | And so is this, but it we should preserve the extra space on this line relative
| D208
| ^ D208
687 | to the one before
688 | """
|
Expand All @@ -233,7 +232,7 @@ D.py:687:1: D208 [*] Docstring is over-indented
685 | This is also overindented
686 | And so is this, but it we should preserve the extra space on this line relative
687 | to the one before
| D208
| ^ D208
688 | """
|
= help: Remove over-indentation
Expand All @@ -251,9 +250,9 @@ D.py:687:1: D208 [*] Docstring is over-indented
D.py:695:1: D208 [*] Docstring is over-indented
|
693 | """Summary.
694 |
694 |
695 | This is overindented
| D208
| ^ D208
696 | And so is this, but it we should preserve the extra space on this line relative
697 | to the one before
|
Expand All @@ -273,7 +272,7 @@ D.py:696:1: D208 [*] Docstring is over-indented
|
695 | This is overindented
696 | And so is this, but it we should preserve the extra space on this line relative
| D208
| ^ D208
697 | to the one before
698 | And the relative indent here should be preserved too
|
Expand All @@ -294,7 +293,7 @@ D.py:697:1: D208 [*] Docstring is over-indented
695 | This is overindented
696 | And so is this, but it we should preserve the extra space on this line relative
697 | to the one before
| D208
| ^ D208
698 | And the relative indent here should be preserved too
699 | """
|
Expand All @@ -315,7 +314,7 @@ D.py:698:1: D208 [*] Docstring is over-indented
696 | And so is this, but it we should preserve the extra space on this line relative
697 | to the one before
698 | And the relative indent here should be preserved too
| D208
| ^ D208
699 | """
|
= help: Remove over-indentation
Expand All @@ -333,9 +332,9 @@ D.py:698:1: D208 [*] Docstring is over-indented
D.py:704:1: D208 [*] Docstring is over-indented
|
702 | """Summary.
703 |
703 |
704 | This is overindented
| D208
| ^ D208
705 | And so is this, but it we should preserve the extra space on this line relative
706 | This is overindented
|
Expand All @@ -355,7 +354,7 @@ D.py:705:1: D208 [*] Docstring is over-indented
|
704 | This is overindented
705 | And so is this, but it we should preserve the extra space on this line relative
| D208
| ^ D208
706 | This is overindented
707 | This is overindented
|
Expand All @@ -376,7 +375,7 @@ D.py:706:1: D208 [*] Docstring is over-indented
704 | This is overindented
705 | And so is this, but it we should preserve the extra space on this line relative
706 | This is overindented
| D208
| ^ D208
707 | This is overindented
708 | """
|
Expand All @@ -397,7 +396,7 @@ D.py:707:1: D208 [*] Docstring is over-indented
705 | And so is this, but it we should preserve the extra space on this line relative
706 | This is overindented
707 | This is overindented
| D208
| ^ D208
708 | """
|
= help: Remove over-indentation
Expand All @@ -415,9 +414,9 @@ D.py:707:1: D208 [*] Docstring is over-indented
D.py:723:1: D208 [*] Docstring is over-indented
|
721 | """There's a non-breaking space (2-bytes) after 3 spaces (https://github.com/astral-sh/ruff/issues/9080).
722 |
722 |
723 |     Returns:
| D208
| ^ D208
724 | """
|
= help: Remove over-indentation
Expand Down
Loading
Loading