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

Add --output-format to ruff config CLI #11438

Merged
merged 3 commits into from
May 16, 2024

Conversation

thatch
Copy link
Contributor

@thatch thatch commented May 15, 2024

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.

(.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
  }
}

This is useful for extracting the defaults in order to construct equivalent
configs by external scripts.
Copy link
Contributor

github-actions bot commented May 15, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh
Copy link
Member

This looks reasonable to me. Let me see if I can get the no-args form working, then can merge.

@charliermarsh charliermarsh added the cli Related to the command-line interface label May 16, 2024
@charliermarsh charliermarsh changed the title Add output-format to config in cli Add --output-format to ruff config CLI May 16, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) May 16, 2024 02:09
auto-merge was automatically disabled May 16, 2024 02:17

Base branch was modified

@charliermarsh charliermarsh merged commit 27da223 into astral-sh:main May 16, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants