Extract message emitters from Printer#3895
Merged
MichaReiser merged 2 commits intomainfrom Apr 11, 2023
Merged
Conversation
Member
Author
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
43f9053 to
46de12b
Compare
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
46de12b to
08354a2
Compare
MichaReiser
commented
Apr 6, 2023
| use ruff_python_ast::types::Range; | ||
|
|
||
| #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct Message { |
Member
Author
There was a problem hiding this comment.
Copied from src/message.rs
| grouped_messages | ||
| } | ||
|
|
||
| pub trait Emitter { |
74ef23d to
d9a3769
Compare
ab2d3c2 to
6d2ccf7
Compare
This was referenced Apr 6, 2023
| #[derive(Default)] | ||
| pub struct GithubEmitter; | ||
|
|
||
| impl Emitter for GithubEmitter { |
Member
There was a problem hiding this comment.
My read on the Rust naming rules is that this is correct (over GitHubEmitter).
Member
Author
There was a problem hiding this comment.
I don't know. I chose this naming to keep it consistent with SerializationFormat::Github
charliermarsh
approved these changes
Apr 6, 2023
This was referenced Apr 7, 2023
f5193e6 to
2ba3c0d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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