Commit 6def73f
committed
Append the fix title to a
Summary
--
As noted in #22972 (comment),
attaching sub-diagnostics to Ruff's diagnostics can interact a bit awkwardly
with how we attach the `Violation::fix_title` and then render a fix diff. In
particular, the fix title is currently attached as a `help` sub-diagnostic when
the diagnostic is originally created, meaning that any additional
sub-diagnostics appear between the fix title and the rendered fix:
```
RUF064 [*] Non-octal mode
--> RUF064.py:6:17
|
4 | from pathlib import Path
5 |
6 | os.chmod("foo", 444) # Error
| ^^^
7 | os.chmod("foo", 0o444) # OK
8 | os.chmod("foo", 7777) # Error
|
help: Replace with octal literal
info: Current value of mode 444 (0o674) sets permissions: u=rw-, g=rwx, o=r--)
info: Suggested value of 292 sets permissions: u=r--, g=r--, o=r--
3 | import os
4 | from pathlib import Path
5 |
- os.chmod("foo", 444) # Error
6 + os.chmod("foo", 0o444) # Error
7 | os.chmod("foo", 0o444) # OK
8 | os.chmod("foo", 7777) # Error
9 | os.chmod("foo", 10000) # Error
note: This is an unsafe fix and may change runtime behavior
```
Instead of adding the fix title immediately, this PR stores it on our
`DiagnosticGuard` type to be added just before the guard is dropped and the
diagnostic is stored.
I think a better long-term fix would be to attach the diff to the sub-diagnostic
with the `help` message/fix title somehow and render these `info`
sub-diagnostics _after_ the diff (or let the diagnostic author choose the
order), but this seemed like an easy improvement over the current approach, at
least.
Test Plan
--
Existing tests for ISC004 and from #22972 showing the `help` message at the end.Diagnostic on drop1 parent f1f21f7 commit 6def73f
5 files changed
Lines changed: 44 additions & 43 deletions
File tree
- crates/ruff_linter/src
- checkers/ast
- message
- rules
- flake8_implicit_str_concat/snapshots
- ruff/snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3365 | 3365 | | |
3366 | 3366 | | |
3367 | 3367 | | |
| 3368 | + | |
3368 | 3369 | | |
3369 | 3370 | | |
3370 | 3371 | | |
| |||
3384 | 3385 | | |
3385 | 3386 | | |
3386 | 3387 | | |
| 3388 | + | |
3387 | 3389 | | |
3388 | 3390 | | |
3389 | 3391 | | |
| |||
3447 | 3449 | | |
3448 | 3450 | | |
3449 | 3451 | | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
3450 | 3457 | | |
3451 | 3458 | | |
3452 | 3459 | | |
| |||
3592 | 3599 | | |
3593 | 3600 | | |
3594 | 3601 | | |
3595 | | - | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
3596 | 3606 | | |
3597 | 3607 | | |
3598 | 3608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
| 78 | + | |
80 | 79 | | |
81 | | - | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
| |||
88 | 86 | | |
89 | 87 | | |
90 | 88 | | |
91 | | - | |
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
| |||
108 | 105 | | |
109 | 106 | | |
110 | 107 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 108 | | |
116 | 109 | | |
117 | 110 | | |
| |||
278 | 271 | | |
279 | 272 | | |
280 | 273 | | |
281 | | - | |
| 274 | + | |
282 | 275 | | |
283 | | - | |
284 | 276 | | |
285 | 277 | | |
286 | 278 | | |
| |||
291 | 283 | | |
292 | 284 | | |
293 | 285 | | |
| 286 | + | |
294 | 287 | | |
295 | 288 | | |
296 | | - | |
| 289 | + | |
297 | 290 | | |
298 | | - | |
299 | 291 | | |
300 | 292 | | |
301 | 293 | | |
| |||
306 | 298 | | |
307 | 299 | | |
308 | 300 | | |
| 301 | + | |
309 | 302 | | |
310 | 303 | | |
311 | 304 | | |
312 | 305 | | |
313 | 306 | | |
314 | 307 | | |
315 | | - | |
316 | 308 | | |
317 | 309 | | |
318 | 310 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | 62 | | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | 86 | | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | 111 | | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | 136 | | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
0 commit comments