Skip to content
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): add --write, --fix and --unsafe options to fixable commands #2898

Merged
merged 32 commits into from
May 19, 2024

Conversation

unvalley
Copy link
Member

@unvalley unvalley commented May 17, 2024

Summary

Closes #2267

Add --write, --fix and --unsafe options to biome check and biome lint commands.

  • --apply -> --fix or --write
  • --apply-unsafe -> --fix --unsafe or --write --unsafe

Add --fix option to biome format and biome migrate commands.

biome <lint|check> --<fix|write> [--unsafe]
biome format --<fix|write>

⚠️ NOTE

  • --unsafe should be used with --fix or --write.
  • --apply and --apply-unsafe cannot be used with any --fix, --write, --unsafe
  • currently --unsafe --fix and --unsafe --write is allowed, iow it doesn't care the order

Test Plan

  • unit tests for functions added
  • snapshot tests

remained

  • Update docs in website repo
  • CHANGELOG.md
  • deprecate --apply and --apply-unsafe, it will be removed in biome v2.0
    • I'll create another PR to deprecate them, because of the number of file changed

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project labels May 17, 2024
Copy link
Member Author

@unvalley unvalley May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added test cases for snapshots, but they might not be very valuable (some cases should be tested). Although the commands are different, the actual behavior is the same, so unit tests might be sufficient. If they seem unnecessary, I'll remove them.

@@ -548,7 +548,7 @@ pub struct FormatOnTypeParams {
pub offset: TextSize,
}

#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq)]
Copy link
Member Author

@unvalley unvalley May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartialEq is needed in unit tests to check incompatible command tests.

Comment on lines 80 to 83
#[bpaf(long("apply"), switch, hide_usage)]
apply: bool,
/// Apply safe fixes and unsafe fixes, formatting and import sorting
#[bpaf(long("apply-unsafe"), switch)]
#[bpaf(long("apply-unsafe"), switch, hide_usage)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note; Hide --apply, --apply-unsafe, please check snapshot diff for the help command.

@github-actions github-actions bot added the A-Changelog Area: changelog label May 17, 2024
@unvalley unvalley marked this pull request as ready for review May 17, 2024 19:26
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a preliminary comment, the command biome migrate also accepts the --write option. This means it should accept --fix too

@unvalley unvalley marked this pull request as draft May 18, 2024 15:03
fix,
unsafe_,
} = options;
if apply && apply_unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to print a warning in the console, and communicate that --apply and --apply-unsafe are deprecated, and users should use --fix/--write and --unsafe

If we're worried about snapshots, we could use

if cfg_if!(debug_assertion) {}

Copy link
Member Author

@unvalley unvalley May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we don't have cfg_if crate in biome_cli, I have a PR that deprecates --apply and --apply-unsafe unvalley#3

I think diffs due to deprecation (--apply, --apply-unsafe and --help, etc.) should be recorded in the snapshot, so I would like to address that in another PR. Or, if it is not a problem, I will include the deprecation change in this PR.

@unvalley unvalley marked this pull request as ready for review May 19, 2024 09:12
@unvalley unvalley requested a review from Conaclos May 19, 2024 10:44
@unvalley unvalley merged commit 39f5ea3 into biomejs:main May 19, 2024
11 checks passed
@ematipico
Copy link
Member

@unvalley this is a reminder for you: we'll have to update the website to use these new options instead of the old one.

Also, the changelog doesn't say anything about the deprecation of the old CLI options

@unvalley
Copy link
Member Author

unvalley commented May 19, 2024

@ematipico As for deprecation, I created a new PR #2918

I'll close the website update issue biomejs/website#398

mongolyy added a commit to mongolyy/reviewdog-action-biome that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-CLI Area: CLI A-Project Area: project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 --write everywhere
3 participants