biome icon indicating copy to clipboard operation
biome copied to clipboard

📎 Implement `biome lint --rule=<rule-name>`

Open Conaclos opened this issue 1 year ago • 5 comments

Description

Executing biome lint --rule=<rule-name> should only run the rule with name <rule-name>, otherwise it will throw an error. See rome#4747 for more context.

EDIT: --rule=<rule-name> should override the config, i.e. run <rule-name> even if the rule is disabled in the config. However, the rule options and severity level should be taken into account.

If the option is combined with --summary (e.g. biome lint --summary --rule=<rule-name>) we should restrict the summary to <rule-name>. See #57 for more details about the --summary option.

An example:

$ biome lint --rule useSingleCaseStatement src

src/services/types.ts:1121:5 lint/nursery/useNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ⚠ This property name should be in camelCase.
  
  > 1121 │     InsertSpaceAfterConstructor?: boolean;
         │     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  
  ℹ The name could be renamed to `insertSpaceAfterConstructor`.


$ biome lint --summary --rule useSingleCaseStatement src

Rule name                          Diagnostics
nursery/useSingleCaseStatement        1

Possible extensions

  • Multi rule filtering (keeping diagnostics of a given set of rules)
  • reverse filtering, i.e. keeping all diagnostics except the diagnostics of a given rule

Conaclos avatar Aug 23 '23 21:08 Conaclos

I believe the description is misleading. Or maybe I didn't understand.

I would expect that Biome will run the codebase only against the rule passed by CLI, I wouldn't expect to run all rules and then filter the result.

Did I misunderstand the proposal?

ematipico avatar Sep 03 '23 07:09 ematipico

Updated :)

Conaclos avatar Sep 03 '23 10:09 Conaclos

Can this option be paired with --apply and --apply-unsafe?

ematipico avatar Sep 03 '23 13:09 ematipico

Can this option be paired with --apply and --apply-unsafe?

I don't see any blocker :) Composability is great.

Conaclos avatar Sep 03 '23 13:09 Conaclos

This could also be good to expose this option in the playground. Someone testing the rule in the playground could then focus on the behavior of the rule without triggering other rules. This could allow also adding a Try this rule on every rule's page.

Conaclos avatar Sep 29 '23 16:09 Conaclos