-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Use new diff rendering format in tests #20101
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
Conversation
|
374c43d to
147f7a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty straightforward change, thanks for taking the time to go through the snapshot changes!
It would be useful for @zanieb to take a brief look as I think they've been heavily involved in the design process.
| "{note}: {msg}", | ||
| note = fmt_styled("note", self.stylesheet.warning), | ||
| msg = fmt_styled( | ||
| "This is an unsafe fix and may remove comments or change runtime behavior", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might just say "change behavior"? I guess we could keep "may remove comments" for now, but I'm wary to encode that into the meaning of "unsafe" (I think it's sort of vague these days). The silly part is that we should know if we've dropped a comment, e.g., by inspecting the diff? That's separate work though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Those are the two main criteria in our docs, but it does feel a bit too specific to include in each diagnostic message.
this keeps one blank line between each diagnostic, whether it has a fix or not
my manual tests had always had an equal number of insertions and deletions, so I didn't notice this. if you use old_index here then you end up with duplicate line numbers for any pure insertion, such as adding a required import
this was present before, I think I accidentally deleted it in a rebase
147f7a7 to
9930c94
Compare
* main: Fix mdtest ignore python code blocks (#20139) [ty] add support for cyclic legacy generic protocols (#20125) [ty] add cycle detection for find_legacy_typevars (#20124) Use new diff rendering format in tests (#20101) [ty] Fix 'too many cycle iterations' for unions of literals (#20137) [ty] No boundness analysis for implicit instance attributes (#20128) Bump 0.12.11 (#20136) [ty] Benchmarks for problematic implicit instance attributes cases (#20133) [`pyflakes`] Fix `allowed-unused-imports` matching for top-level modules (`F401`) (#20115) Move GitLab output rendering to `ruff_db` (#20117) [ty] Evaluate reachability of non-definitely-bound to Ambiguous (#19579) [ty] Introduce a representation for the top/bottom materialization of an invariant generic (#20076) [`flake8-async`] Implement `blocking-http-call-httpx` (`ASYNC212`) (#20091) [ty] print diagnostics with fully qualified name to disambiguate some cases (#19850) [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (#19647)
## Summary I spun this off from astral-sh#19919 to separate the rendering code change and snapshot updates from the (much smaller) changes to expose this in the CLI. I grouped all of the `ruff_linter` snapshot changes in the final commit in an effort to make this easier to review. The code changes are in [this range](https://github.com/astral-sh/ruff/pull/20101/files/619395eb417d2030e31fbb0e487a72dac58902db). I went through all of the snapshots, albeit fairly quickly, and they all looked correct to me. In the last few commits I was trying to resolve an existing issue in the alignment of the line number separator: https://github.com/astral-sh/ruff/blob/73720c73be981df6f71ce837a67ca1167da0265e/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap#L87-L89 In the snapshot above on `main`, you can see that a double-digit line number at the end of the context lines for a snippet was causing a misalignment with the other separators. That's now resolved. The one downside is that this can lead to a mismatch with the diagnostic above: ``` C409 [*] Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) --> C409.py:4:6 | 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) 4 | t4 = tuple([ | ______^ 5 | | 1, 6 | | 2 7 | | ]) | |__^ 8 | t5 = tuple( 9 | (1, 2) | help: Rewrite as a tuple literal 1 | t1 = tuple([]) 2 | t2 = tuple([1, 2]) 3 | t3 = tuple((1, 2)) - t4 = tuple([ 4 + t4 = ( 5 | 1, 6 | 2 - ]) 7 + ) 8 | t5 = tuple( 9 | (1, 2) 10 | ) note: This is an unsafe fix and may remove comments or change runtime behavior ``` But I don't think we can avoid that without really reworking this rendering to make the diagnostic and diff rendering aware of each other. Anyway, this should only happen in relatively rare cases where the diagnostic is near a digit boundary and also near a context boundary. Most of our diagnostics line up nicely. Another potential downside of the new rendering format is its handling of long stretches of `+` or `-` lines: ``` help: Replace with `Literal[...] | None` 21 | ... 22 | 23 | - def func6(arg1: Literal[ - "hello", - None # Comment 1 - , "world" - ]): 24 + def func6(arg1: Literal["hello", "world"] | None): 25 | ... 26 | 27 | note: This is an unsafe fix and may remove comments or change runtime behavior ``` To me it just seems a little hard to tell what's going on with just a long streak of `-`-prefixed lines. I saw an even more exaggerated example at some point, but I think this is also fairly rare. Most of the snapshots seem more like the examples we looked at on Discord with plenty of `|` lines and pairs of `+` and `-` lines. ## Test Plan Existing tests plus one new test in `ruff_db` to isolate a line separator alignment issue
Summary
I spun this off from #19919 to separate the rendering code change and snapshot updates from the (much smaller) changes to expose this in the CLI. I grouped all of the
ruff_lintersnapshot changes in the final commit in an effort to make this easier to review. The code changes are in this range.I went through all of the snapshots, albeit fairly quickly, and they all looked correct to me. In the last few commits I was trying to resolve an existing issue in the alignment of the line number separator:
ruff/crates/ruff_linter/src/rules/flake8_comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C409_C409.py.snap
Lines 87 to 89 in 73720c7
In the snapshot above on
main, you can see that a double-digit line number at the end of the context lines for a snippet was causing a misalignment with the other separators. That's now resolved. The one downside is that this can lead to a mismatch with the diagnostic above:But I don't think we can avoid that without really reworking this rendering to make the diagnostic and diff rendering aware of each other. Anyway, this should only happen in relatively rare cases where the diagnostic is near a digit boundary and also near a context boundary. Most of our diagnostics line up nicely.
Another potential downside of the new rendering format is its handling of long stretches of
+or-lines:To me it just seems a little hard to tell what's going on with just a long streak of
--prefixed lines. I saw an even more exaggerated example at some point, but I think this is also fairly rare. Most of the snapshots seem more like the examples we looked at on Discord with plenty of|lines and pairs of+and-lines.Test Plan
Existing tests plus one new test in
ruff_dbto isolate a line separator alignment issue