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: custom explanations with --suppress #4343

Merged
merged 101 commits into from
Nov 4, 2024

Conversation

anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Oct 21, 2024

Summary

#4008 introduces a --suppress flag, but it would add ignore comments using the default explanation (<explanation>). Since --suppress bulk ignores existing diagnostics, you'd have to go back through your changes to give a more worthwhile explanation (or accept <explanation> being in your codebase). Instead, this PR sets a more informative default message of "Ignored using --suppress".

Additionally, you can now add a custom explanation with --reason. This flag can only be used when you use --suppress.

Test Plan

Updated tests to use this default message. I've also manually tested the binary against a few of my repositories.

--unsafe Allow to do unsafe fixes, should be used with `--write` or `--fix`
--fix Alias for `--write`, writes safe fixes
--apply Alias for `--write`, writes safe fixes (deprecated, use `--write`)
--apply-unsafe Alias for `--write --unsafe`, writes safe and unsafe fixes
(deprecated, use `--write --unsafe`)
--suppress Bulk fix diagnostics with suppression comments if the language
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I felt like it helped to add "Bulk" here to portray that you'd want to use this for migration purposes. Can take it off if desired.

@anthonyshew anthonyshew marked this pull request as ready for review October 26, 2024 03:42
@anthonyshew anthonyshew changed the title feat: default message when using --suppress feat: custom explanations with --suppress Oct 26, 2024
@anthonyshew
Copy link
Contributor Author

anthonyshew commented Oct 26, 2024

I've verified that this works by writing a few more tests and running it against a few repositories I have. I'm admittedly not 100% certain the way that I've written it is the best way to go about it. Ema let me know to go through AnalyzerOptions, but not sure about the rest of what I have.

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.

Overall it looks good. We should avoid .clone, and rely on references where is possible.

crates/biome_analyze/src/lib.rs Outdated Show resolved Hide resolved
crates/biome_analyze/src/signals.rs Outdated Show resolved Hide resolved
crates/biome_cli/src/commands/mod.rs Outdated Show resolved Hide resolved
crates/biome_cli/src/diagnostics.rs Outdated Show resolved Hide resolved
crates/biome_cli/src/execute/process_file/lint.rs Outdated Show resolved Hide resolved
crates/biome_cli/src/execute/process_file/lint.rs Outdated Show resolved Hide resolved
@anthonyshew
Copy link
Contributor Author

anthonyshew commented Oct 28, 2024

I was using String so I could avoid playing "The Lifetime Game" while I was trying to get the codepaths right. 😄

Now that I'm doing the lifetime-ing, the error you see on the build is something I honestly have no idea how to contend with. It might take me awhile to sort this out. Also noteworthy that there's a bunch of changes due to putting lifetimes in a bunch of places, so possibly worth another more general look over things.

@ematipico
Copy link
Member

Ok, then let's keep String inside AnalyzerOptions, having a lifetime there doesn't make sense.

Push the change and then I'll have a look if you still have lifetime issues

@ematipico
Copy link
Member

@anthonyshew I optimised some code here 3e9a369 (#4343), the was some unneeded allocations

@anthonyshew
Copy link
Contributor Author

anthonyshew commented Oct 28, 2024

Thanks! I had just caught onto that while I was looking for a few more places to put string slices. You beat me to it. 🤝

It seems like we're in a good spot now on String vs. &str. bpaf needs a String so it feels like it makes sense to let it keep being String in the CLI crate. It's only gets passed through a couple layers to get to AnalyzerOptions after that? We definitely can bring it to a &str and back to String. It felt a bit silly when I started doing it so asking first.

After it makes it through the options, it's a &str now in the file handlers, suppression actions, etc.

@ematipico ematipico merged commit 3f152b3 into biomejs:main Nov 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Linter Area: linter A-LSP Area: language server protocol A-Project Area: project A-Tooling Area: internal tools L-CSS Language: CSS L-JavaScript Language: JavaScript and super languages L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants