biome icon indicating copy to clipboard operation
biome copied to clipboard

feat(cli/lint): add `--rule` option

Open Conaclos opened this issue 9 months ago • 3 comments

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.

Conaclos avatar May 14 '24 16:05 Conaclos

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%

github-actions[bot] avatar May 14 '24 16:05 github-actions[bot]

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.

ematipico avatar May 15 '24 12:05 ematipico

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%

codspeed-hq[bot] avatar May 15 '24 16:05 codspeed-hq[bot]

@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 😅

ematipico avatar May 16 '24 09:05 ematipico

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

Conaclos avatar May 16 '24 10:05 Conaclos

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.

ematipico avatar May 16 '24 10:05 ematipico