Skip to content

Commit

Permalink
refactor: improve CLI docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 15, 2024
1 parent cd94ba6 commit 249a08b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
18 changes: 8 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### New features

- Introduce a new valued oprion `--rule` for `biome lint` ([#58](https://github.com/biomejs/biome/issues/58)).
- Add a new option `--rule` to the command `biome lint` ([#58](https://github.com/biomejs/biome/issues/58)).

This new option allows you to execute a single rule.
This is convenient to test a rule or apply the code fixes of a single rule.
This new option allows you to execute a single rule. This option is convenient to test a rule or apply the code fixes of a single rule.

For example, you can execute the `style/useNamingConvention` rule on a set of files:

```shell
biome lint --rule=style/useNamingConvention index,js
biome lint --rule=style/useNamingConvention src/index.js src/main.js
```

And the napply its code fixes:
If the rule has code action (autofix), you can use `--apply` to apply the fix:

```shell
biome lint --rule=style/useNamingConvention --apply index,js
biome lint --rule=style/useNamingConvention --apply index.js src/main.js
```

The option takes the rule configuration into account.

The severity level of the executed rule is always set to its default,
The option takes the rule options set in the Biome configuration file into account.
Only, the severity level of the rule is overriden by its default value,
i.e. `error` for a recommended rule or `warn` otherwise.

The option is compatible with other options such as `--apply` and `--reporter`.
The option is compatible with other options such as `--apply`, `--apply-unsafe` and `--reporter`.

Contributed by @Conaclos

Expand Down
3 changes: 2 additions & 1 deletion crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ pub enum BiomeCommand {
#[bpaf(external, hide_usage)]
cli_options: CliOptions,

/// Execute only this rule taking into account its configurations.
/// Run only the given rule taking into account the options set in the configurations files.
/// The severity level of the rule is set to its default.
#[bpaf(long("rule"), argument("NAME"))]
rule: Option<RuleCode>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Available positional items:
Available options:
--apply Apply safe fixes, formatting and import sorting
--apply-unsafe Apply safe fixes and unsafe fixes, formatting and import sorting
--rule=NAME Execute only this rule taking into account its configurations.
--rule=NAME Run only the given rule taking into account the options set in the configurations
files. The severity level of the rule is set to its default.
--stdin-file-path=PATH Use this option when you want to format code piped from `stdin`, and
print the output to `stdout`.
The file doesn't need to exist on disk, what matters is the extension of
Expand Down
4 changes: 0 additions & 4 deletions crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ pub(crate) fn lint(params: LintParams) -> LintResults {
rule_filter_list.push(RuleFilter::Rule("correctness", "noInitializerWithDefinite"));
rule_filter_list.push(RuleFilter::Rule("correctness", "noSuperWithoutExtends"));
rule_filter_list.push(RuleFilter::Rule("nursery", "noSuperWithoutExtends"));
if let Some(rule) = params.rule {
rule_filter_list.clear();
rule_filter_list.push(rule.into())
}
rule_filter_list
};

Expand Down

0 comments on commit 249a08b

Please sign in to comment.