-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is useful for extracting the defaults in order to construct equivalent configs by external scripts. This is my first non-hello-world rust code, comments and suggested tests appreciated. ## Summary We already have `ruff linter --output-format json`, this provides `ruff config x --output-format json` as well. I plan to use this to construct an equivalent config snippet to include in some managed repos, so when we update their version of ruff and it adds new lints, they get a PR that includes the commented-out new lints. Note that the no-args form of `ruff config` ignores output-format currently, but probably should obey it (although array-of-strings doesn't seem that useful, looking for input on format). ## Test Plan I could use a hand coming up with a typical way to write automated tests for this. ```sh-session (.venv) [timhatch:ruff ]$ ./target/debug/ruff config lint.select A list of rule codes or prefixes to enable. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between. When breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes. Default value: ["E4", "E7", "E9", "F"] Type: list[RuleSelector] Example usage: ``toml # On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`). select = ["E4", "E7", "E9", "F", "B", "Q"] `` (.venv) [timhatch:ruff ]$ ./target/debug/ruff config lint.select --output-format json { "Field": { "doc": "A list of rule codes or prefixes to enable. Prefixes can specify exact\nrules (like `F841`), entire categories (like `F`), or anything in\nbetween.\n\nWhen breaking ties between enabled and disabled rules (via `select` and\n`ignore`, respectively), more specific prefixes override less\nspecific prefixes.", "default": "[\"E4\", \"E7\", \"E9\", \"F\"]", "value_type": "list[RuleSelector]", "scope": null, "example": "# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).\nselect = [\"E4\", \"E7\", \"E9\", \"F\", \"B\", \"Q\"]", "deprecated": null } } ```
- Loading branch information
Showing
5 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Tests for the `ruff config` subcommand. | ||
use std::process::Command; | ||
|
||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; | ||
|
||
const BIN_NAME: &str = "ruff"; | ||
|
||
#[test] | ||
fn lint_select() { | ||
assert_cmd_snapshot!( | ||
Command::new(get_cargo_bin(BIN_NAME)).arg("config").arg("lint.select"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
A list of rule codes or prefixes to enable. Prefixes can specify exact | ||
rules (like `F841`), entire categories (like `F`), or anything in | ||
between. | ||
When breaking ties between enabled and disabled rules (via `select` and | ||
`ignore`, respectively), more specific prefixes override less | ||
specific prefixes. | ||
Default value: ["E4", "E7", "E9", "F"] | ||
Type: list[RuleSelector] | ||
Example usage: | ||
```toml | ||
# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`). | ||
select = ["E4", "E7", "E9", "F", "B", "Q"] | ||
``` | ||
----- stderr ----- | ||
"### | ||
); | ||
} | ||
|
||
#[test] | ||
fn lint_select_json() { | ||
assert_cmd_snapshot!( | ||
Command::new(get_cargo_bin(BIN_NAME)).arg("config").arg("lint.select").arg("--output-format").arg("json"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
{ | ||
"doc": "A list of rule codes or prefixes to enable. Prefixes can specify exact\nrules (like `F841`), entire categories (like `F`), or anything in\nbetween.\n\nWhen breaking ties between enabled and disabled rules (via `select` and\n`ignore`, respectively), more specific prefixes override less\nspecific prefixes.", | ||
"default": "[\"E4\", \"E7\", \"E9\", \"F\"]", | ||
"value_type": "list[RuleSelector]", | ||
"scope": null, | ||
"example": "# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).\nselect = [\"E4\", \"E7\", \"E9\", \"F\", \"B\", \"Q\"]", | ||
"deprecated": null | ||
} | ||
----- stderr ----- | ||
"### | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters