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 --only and --skip options #2947

Merged
merged 9 commits into from
May 24, 2024
Merged

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented May 22, 2024

Summary

This PR renames --rule into --only and adds a new option --skip.
These two options can be repeated and used together.
When used together, --skip takes precedence over --only (like --ignore takes precedence over include).

For example, the following command executes only the suspicious/noDebugger rule and all the rules of the style group, but skips the style/useNamingConvention rule.

biome lint --only=suspicious/noDebugger --only=style --skip=style/useNamingConvention

Using skip on a group, skip all rules in the group.
Conversely, using --only on a group, enable all rules of the group - even the ones explicitly disabled in the configuration.

Limitations

Using --only disables the diagnostics about unused suppression comments.
Ideally, we should also filter these diagnostics according to the enabled rules.
However, I don't know how to filter them based on that criteria.

Test Plan

I added tests and updated previous tests.

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter A-Tooling Area: internal tools A-LSP Area: language server protocol A-Changelog Area: changelog labels May 22, 2024
@Conaclos Conaclos force-pushed the conaclos/rule-filter branch 2 times, most recently from 49770f2 to ad1ba1a Compare May 22, 2024 15:38
@Conaclos Conaclos changed the title feat(cli): Implement --only and --skip feat(cli): add --only and --skip options May 22, 2024
@Conaclos Conaclos requested review from a team May 22, 2024 15:40
Copy link

codspeed-hq bot commented May 22, 2024

CodSpeed Performance Report

Merging #2947 will not alter performance

Comparing conaclos/rule-filter (0221b06) with conaclos/rule-filter (3ba4a5f)

Summary

✅ 92 untouched benchmarks

@Conaclos Conaclos force-pushed the conaclos/rule-filter branch 2 times, most recently from c4a40f8 to fb2a514 Compare May 22, 2024 16:29
@github-actions github-actions bot removed the A-Linter Area: linter label May 23, 2024
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 593 593 0
Failed 69 69 0
Panics 0 0 0
Coverage 89.58% 89.58% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13441 13441 0
Failed 4205 4205 0
Panics 0 0 0
Coverage 76.17% 76.17% 0.00%

@Conaclos Conaclos force-pushed the conaclos/rule-filter branch 2 times, most recently from 046715a to 0c1eddf Compare May 23, 2024 11:35
@ematipico
Copy link
Member

When used together, --skip overrides --only.

I gave my explanation on Discord, I will copy it too here:

Regarding the precedence, I think we should be consistent with what we have already. --only and --skip can be seen as the pair ignore/include, where skip -> ignore and only -> include . We document that ignore takes precedence over include, so we should do the same here.

crates/biome_cli/src/commands/mod.rs Outdated Show resolved Hide resolved
crates/biome_service/src/file_handlers/javascript.rs Outdated Show resolved Hide resolved
crates/biome_service/src/file_handlers/json.rs Outdated Show resolved Hide resolved
xtask/codegen/src/generate_configuration.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added the A-Linter Area: linter label May 23, 2024
@Conaclos Conaclos force-pushed the conaclos/rule-filter branch from ed03882 to 34c9a13 Compare May 23, 2024 14:44
..AnalysisFilter::default()
}
pub fn match_rule<R: Rule>(&self) -> bool {
self.enabled_rules.map_or(true, |enabled_rules| {
Copy link
Member Author

@Conaclos Conaclos May 23, 2024

Choose a reason for hiding this comment

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

We don't need to call match_group because this check is already handled in filter.match_rule. Thus, I removed this useless check.

Comment on lines 847 to 855
.iter()
.any(|filter| filter.match_group::<G>())
!disabled_rules.iter().any(|filter| {
matches!(filter, RuleFilter::Group(_)) && filter.match_group::<G>()
Copy link
Member Author

@Conaclos Conaclos May 23, 2024

Choose a reason for hiding this comment

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

The implementation of match_group was bogus.

@Conaclos Conaclos requested a review from ematipico May 23, 2024 14:48
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.

Great work @Conaclos! This is going to be a great feature 🔥

crates/biome_analyze/src/lib.rs Show resolved Hide resolved
crates/biome_analyze/src/lib.rs Show resolved Hide resolved
xtask/codegen/src/generate_configuration.rs Show resolved Hide resolved
@Conaclos Conaclos force-pushed the conaclos/rule-filter branch from d79109b to 0221b06 Compare May 24, 2024 12:13
@Conaclos Conaclos merged commit 49f6530 into main May 24, 2024
16 checks passed
@Conaclos Conaclos deleted the conaclos/rule-filter branch May 24, 2024 12:13
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-Linter Area: linter A-LSP Area: language server protocol A-Project Area: project A-Tooling Area: internal tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants