-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pretty print Diagnostic
s 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we do in production? Continue to show just the changed line?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be try_from_message
? Or is try_from_*
only used for Result
?
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.
Not sure. NonZeroUsize
returns Option
from new
. My reasoning is that it isn't failing, it's just that not all Message
s can print a diff
.
c61412e
to
117cace
Compare
PR Check ResultsBenchmarkLinux
Windows
|
0d46f76
to
cff3d22
Compare
117cace
to
0bab2f4
Compare
c7b5b1d
to
2323617
Compare
0bab2f4
to
04e924f
Compare
This PR extends the
TextEmitter
to print diffs for fixes (explicit opt-in) and changes the snapshot tests to use theTextEmitter
instead ofassert_yaml_snapshot
.Pretty printing the diagnostics makes our linter tests more resilient to changes. For example, changing the field ordering of
Diagnostic
or 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.