-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
feat(cli): generic reporter APIs #853
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Nice one! Glad I'm not the only one making big PRs 🤣
I would like it if we could keep the output format a bit more condensed though, even if it requires some amount of "opinionatedness" in the reporter.
} | ||
|
||
/// When using this trait, the type that implements this trait is the one that will **write** the data, ideally inside a buffer | ||
pub trait ReporterVisitor { |
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'm thinking a little bit about what would be the best way to design output for the biome search
command. Would it report search results through "info" diagnostics? Would it report a a summary? Would it use the reporter infrastructure at all?
We don't need answers to those questions for this PR, but they might be good to keep in the back of our minds.
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.
Yeah, unfortunately, we don't have a design yet; I suppose we will have to make the APIs better as we implement new features, such as JSON output, writing things in files, and other formats.
crates/biome_cli/src/reporter/mod.rs
Outdated
/// A type that holds the result of the traversal | ||
#[derive(Debug, Default)] | ||
pub struct TraversalSummary { | ||
changed: usize, |
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 we maybe track processed
instead of unchanged
? I'm thinking processed = changed + unchanged
, so it would change the method of tracking slightly, but I feel changed
/unchanged
feels a little bit like a mismatch for use cases that aren't intended to change files in the first place, such as biome ci
or the upcoming biome search
.
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, although not in this PR because It seems out of scope
} | ||
} else { | ||
Ok(()) | ||
} |
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.
Nice cleanup! I like that these concerns got nicely separated in the Reporter
trait.
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.
Same there! Looks cleaner 🤩.
crates/biome_cli/tests/snapshots/main_cases_biome_json_support/biome_json_is_not_ignored.snap
Outdated
Show resolved
Hide resolved
What do you think if all the methods I'll have to create a |
I addressed all the comments |
FYI I already found some flaws in the initial APIs, so the next PR will further change them to accommodate the JSON reporter |
Summary
This PR implements a new reporter API.
This API uses traits, and it's heavily inspired by the diagnostics advices traits:
Reporter
trait. Usually the type that implementsReporter
is the one that will hold the data to read from.ReporterVisitor
. Usually, the type that will implementReporterVisitor
is the one that will hold a buffer where information is written.I also added an example that should show how to use the reporter.
Having such generic APIs should allow us to create new reporters easily, based on Biome's needs.
I had to do some refactors around the
traverse
function and the data returned by it.Test Plan
There are a lot of changes, mainly because now the logs are written at different times instead of once, and our
BufferConsole
pushes messages inside a vector.