-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Extract message emitters from Printer #3895
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
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
43f9053 to
46de12b
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
46de12b to
08354a2
Compare
| use ruff_python_ast::types::Range; | ||
|
|
||
| #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Message { |
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.
Copied from src/message.rs
| grouped_messages | ||
| } | ||
|
|
||
| pub trait Emitter { |
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 is new
74ef23d to
d9a3769
Compare
ab2d3c2 to
6d2ccf7
Compare
| #[derive(Default)] | ||
| pub struct GithubEmitter; | ||
|
|
||
| impl Emitter for GithubEmitter { |
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.
My read on the Rust naming rules is that this is correct (over GitHubEmitter).
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 don't know. I chose this naming to keep it consistent with SerializationFormat::Github
f5193e6 to
2ba3c0d
Compare

This PR extracts the emitters for serializing
Messagesfrom thePrinterin the CLI toruff. The reason for moving the implementations to ruff is so that I use the text emitter to write the linter snapshots instead of serializing theDiagnosticto YAML. Using the rendered text output has the advantage that we can do refactors like replacingLocationwithTextSizewithout affecting the snapshot outputs, which gives us confidence in the refactor.I used this chance to:
writedirectly rather than usingformatand then writing the formatted string.Considerations
Printercallsemitstatically on all emitters (it isn't using dynamic dispatching). However, it helped to share logic between tests and it ensures that all emitters are structured similarly.ruffcrate isn't strictly necessary. For example, I don't plan to use thejunitemitter for the test infrastructure. I still decided to put them all into the same module for better discoverability.Performance
Avoiding
formatandto_stringimproves performance a bit