-
Notifications
You must be signed in to change notification settings - Fork 650
feat(rome_cli): add --json
argument to format command
#3066
Conversation
Deploying with
|
Latest commit: |
45faf07
|
Status: | ✅ Deploy successful! |
Preview URL: | https://cc661d19.tools-8rn.pages.dev |
Branch Preview URL: | https://feature-out-argument.tools-8rn.pages.dev |
378c451
to
b83f8b4
Compare
b83f8b4
to
0172d1c
Compare
0172d1c
to
85e74ad
Compare
Would you mind adding a short outline to the PR summary how the architecture changed. You mention three threads. What's the responsibility of each thread, why are multiple threads necessary? Are there specific reasons why you doubt that three threads are a good approach? Edit: Can you add an example of a formatter and check JSON output to the test section? |
Done. |
85e74ad
to
956d62e
Compare
Thanks for updating the description. Some feedback on the JSON format
|
crates/rome_cli/src/traversal.rs
Outdated
let mut has_errors = None; | ||
let mut duration = None; | ||
let mut stats = None; | ||
let send_stats_from_messages = send_stats_from_traversal.clone(); |
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.
Can you explain why printing the messages to the console from the current thread is no longer an option and it is instead necessary to spawn a separate thread?
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.
The printing of messages was already happening on separate thread. From this thread we now send the stats to the stats_thread
, because these messages contain diagnostics, which we want to capture. I hope this answer your question.
As an alternative to having a dedicated thread for receiving the stats, the |
This is true. But I thought, since we have the information at hand (and it's really detailed), why not expose it? Also, considering that our APIs can be used by other developers to make other plugins, they can use it for internal measurements.
Yes, but I am not sure these errors should be sent together with this JSON on Also, I am not sure if
I think it's a valuable information, since we already have it. If the script wants the information, it would require to make another I/O operation. If we scale this situation on folders, there would be lot of I/O operations... It's a trade-off. The JSON would be slim but scripts that require that information would be penalized. What do you think? Should we remove it? |
That depends on the use cases that we want to support. Overall, I'm leaning towards removing any information that we don't have an explicit use case for because it will be difficult to remove fields in the future. I would currently focus on only adding fields/information for which we have a direct use in the Node JS API, because that's the ultimate goal we're pursuing. So the question is, what's the result of
|
956d62e
to
4d36d62
Compare
|
||
/// Tells if the reporting is happening straight to terminal | ||
pub(crate) fn should_report_to_terminal(&self) -> bool { | ||
matches!(self.report_mode, ReportMode::Terminal) |
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.
Nit: is_terminal()
to keep in line with is_ci
, is_check
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 want to keep them different on purpose, because is_ci
is related to the traversal, while the terminal is related to the reporting
6f00d53
to
54ddbed
Compare
@leops I would like to defer your suggestion in another PR, mostly because @MichaReiser Are your concerns been covered? Are there any other things pending? I would like to merge this PR and continue to apply new changes from here. |
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.
Do you plan to create an issue for the follow up on select
or is it something we don't plan to pursue at the moment?
I plan to revisit this. This is was more of an optimization and I think it's not needed for our case. |
Summary
Closes #3049
The status of the PR is not the final design.
There are still things missing that I would like implement in subsequent PRs:
stderr
--json
to thecheck
commandThese were intentionally left out because I had spent enough time to experiment with other crates.
What I would like to review is:
format
command on a file/folderThe usage of three threads was necessary to because we need to collect information from two sources:
And we need a third thread to receive these messages.
Examples
Given the file
example.js
If we run the following command
rome format example.js --json
, we get the following JSON:If we run the command
rome format test.js --write --json
, we get the following JSON:The paths will be relative to the path where the command was run.
Test Plan
Added a test case to cover a simple case