Pretty print Diagnostics in snapshot tests#3906
Conversation
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
9521ae1 to
0d46f76
Compare
1042404 to
bc9565b
Compare
| 57 | pass | ||
| | | ||
|
|
||
| ./resources/test/fixtures/flake8_blind_except/BLE.py:60:8: BLE001 Do not catch blind exception: `Exception` |
There was a problem hiding this comment.
a blind exception... interesting 🙈
625430d to
c61412e
Compare
|
|
||
| /// Renders a diff that shows the code fixes. | ||
| /// | ||
| /// The implementation isn't fully fledged out and only used by tests. Before using in production, try |
There was a problem hiding this comment.
What do we do in production? Continue to show just the changed line?
There was a problem hiding this comment.
Oh right, sorry, in production we don't show suggested fixes at all, we only show the suggestion message, and highlight the relevant code.
There was a problem hiding this comment.
I do wonder if there's anything we can leverage from Clippy or rustc to facilitate printing diffs.
There was a problem hiding this comment.
We can look into it when redoing Diagnostics. I would like to replace annotate snippet and colored. Ideally, the code frame and diff is something we build ourselves as it is an important core component of all our tools. This is something that we could inherit from Rome
| } | ||
|
|
||
| impl<'a> Diff<'a> { | ||
| pub fn from_message(message: &'a Message) -> Option<Diff> { |
There was a problem hiding this comment.
Should this be try_from_message? Or is try_from_* only used for Result?
There was a problem hiding this comment.
Not sure. NonZeroUsize returns Option from new. My reasoning is that it isn't failing, it's just that not all Messages can print a diff.
c61412e to
117cace
Compare
PR Check ResultsBenchmarkLinuxWindows |
0d46f76 to
cff3d22
Compare
117cace to
0bab2f4
Compare
c7b5b1d to
2323617
Compare
0bab2f4 to
04e924f
Compare

This PR extends the
TextEmitterto print diffs for fixes (explicit opt-in) and changes the snapshot tests to use theTextEmitterinstead ofassert_yaml_snapshot.Pretty printing the diagnostics makes our linter tests more resilient to changes. For example, changing the field ordering of
Diagnosticor its representation no longer breaks the snapshot tests because it doesn't change the pretty printed output.The pretty printed output further has the advantage that it is easier to spot errors. No more offset counting to verify that the diagnostic or edit points to the right locations.