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/lint): add the --rule option #2860

Merged
merged 3 commits into from
May 16, 2024
Merged

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented May 14, 2024

Summary

Fix #58

This PR adds a new option --rule on the biome lint command.
The option allows executing a given rule on a set of files.
The configuration is taken into account.
Only the severity is overridden to its default, i.e. error for recommended rules and warn for other rules.
This ensures that the rule is not off.
The rule is executed even if recommended is disabled.
However, the rule is not executed if the linter is disabled in the configuration.

To implement this feature, I introduced a new type RuleCode that references a rule with static string slices.
This allows passing the rule group/name without cloning it.
I modified Rules::matches_diagnostic_code to return static string slices. It acts as a static string interner.
I also added methods to set the severity level of a given rule.

The argument of the rule option is passed as parameters in the different calls.

Test Plan

I added tests.

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Tooling Area: internal tools A-LSP Area: language server protocol A-Changelog Area: changelog labels May 14, 2024
@@ -311,6 +311,7 @@ impl Session {
path: biome_path.clone(),
categories,
max_diagnostics: u64::MAX,
rule: None,
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I set rule to None because I do not have access to this data. I am not sure about the consequences. Maybe it only affects the LSP. Since the CLI is the only one using the rule option, it's probably OK.

@Conaclos Conaclos requested review from a team May 14, 2024 16:54
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 13439 13439 0
Failed 4205 4205 0
Panics 2 2 0
Coverage 76.16% 76.16% 0.00%

@ematipico
Copy link
Member

ematipico commented May 15, 2024

You use the following phrase inside the doc comments, but what does that mean? I believe it requires more explanation. The phrase is too opaque.

The configuration is taken into account.

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.

A believe we can make this option more powerful by running rules that belong to a single group too.

CHANGELOG.md Outdated Show resolved Hide resolved
crates/biome_cli/src/execute/mod.rs Outdated Show resolved Hide resolved
crates/biome_configuration/src/linter/mod.rs Outdated Show resolved Hide resolved
crates/biome_configuration/src/linter/mod.rs Outdated Show resolved Hide resolved
crates/biome_configuration/src/linter/rules.rs Outdated Show resolved Hide resolved
crates/biome_service/src/file_handlers/json.rs Outdated Show resolved Hide resolved
crates/biome_service/src/file_handlers/javascript.rs Outdated Show resolved Hide resolved
@Conaclos Conaclos force-pushed the conaclos/cli-rule-option branch 3 times, most recently from 249a08b to cc05d50 Compare May 15, 2024 13:02
@github-actions github-actions bot added the A-Linter Area: linter label May 15, 2024
Copy link

codspeed-hq bot commented May 15, 2024

CodSpeed Performance Report

Merging #2860 will improve performances by 6.09%

Comparing conaclos/cli-rule-option (2b9c194) with main (78d70d2)

Summary

⚡ 1 improvements
✅ 98 untouched benchmarks

Benchmarks breakdown

Benchmark main conaclos/cli-rule-option Change
pure.css[uncached] 25.8 ms 24.4 ms +6.09%

CHANGELOG.md Outdated Show resolved Hide resolved
@Conaclos Conaclos force-pushed the conaclos/cli-rule-option branch 4 times, most recently from fcbfe35 to cde089f Compare May 15, 2024 21:29
@Conaclos Conaclos changed the title feat(cli/lint): add --rule option feat(cli/lint): add the --rule option May 15, 2024
@Conaclos Conaclos merged commit 3d74b9f into main May 16, 2024
16 checks passed
@Conaclos Conaclos deleted the conaclos/cli-rule-option branch May 16, 2024 09:30
@ematipico
Copy link
Member

@Conaclos you forgot to address

taking the configurations file into account

It's still somewhere inside the doc comments and in the description of the PR. Could you please make sure to follow up? I still find that phrase opaque. I truly don't understand what it means 😅

@Conaclos
Copy link
Member Author

Conaclos commented May 16, 2024

It's still somewhere inside the doc comments and in the description of the PR. Could you please make sure to follow up? I still find that phrase opaque. I truly don't understand what it means 😅

I made the following changes:

Run only the given rule taking the configurations into account

Then I changed to:

Run only the given rule taking the rule options in the configuration file into account

And so:

Run only the given rule or rule group taking the configuration file into account

I am unsure how to address your concern

@ematipico
Copy link
Member

ematipico commented May 16, 2024

What I don't understand is what "taking the configuration file into account" mean. It's very generic. I know you explained that in some comments, it would great to use that explanation here:

The severity of groups and rules configured in the configuration file won't change.

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.

📎 Implement biome lint --rule=<rule-name>
2 participants