Commit 222574a
authored
Expand the default rule set (#23385)
## Summary
This PR adds the new default rule set in preview. This ended up being
pretty non-invasive because the `DEFAULT_SELECTORS` are only used in one
place where `preview` isn't set to the default value of `false`.
I've currently listed each rule with a separate `RuleSelector`, which I
generated with the script below. I thought about trying to be more
clever by finding the smallest set of prefix selectors that yield the
same rule set, but I figured this would be the easiest way to add and
remove rules in the future anyway.
<details><summary>Script</summary>
<p>
```py
import json
import subprocess
import tomllib
from pathlib import Path
from string import ascii_uppercase
RULES = {
rule["code"]: rule["linter"]
for rule in json.loads(
subprocess.run(
["ruff", "rule", "--all", "--output-format=json"],
check=True,
text=True,
capture_output=True,
).stdout
)
}
for code, linter in RULES.items():
if linter == "Ruff-specific rules":
RULES[code] = "Ruff"
def kebab_to_pascal(s: str) -> str:
return "".join(part.title() for part in s.split("-"))
rules = tomllib.loads(Path("proposal.toml").read_text())["lint"]["select"]
for rule in rules:
linter = kebab_to_pascal(RULES[rule])
suffix = rule.lstrip(ascii_uppercase)
prefix = "_"
match linter:
case "Flake8Comprehensions":
suffix = suffix.removeprefix("4")
case "Pycodestyle":
prefix = ""
suffix = rule
case "Flake8Gettext":
linter = "Flake8GetText"
case "Pep8Naming":
linter = "PEP8Naming"
case "Pylint":
prefix = ""
suffix = rule.removeprefix("PL")
case "Flake8Debugger":
suffix = suffix.removeprefix("10")
print(
" " * 4,
f"RuleSelector::rule(RuleCodePrefix::{linter}("
f"codes::{linter}::{prefix}{suffix})),"
f" // {rule}",
sep="",
)
```
</p>
</details>
## Test Plan
A new CLI test showing the preview default rules. I filtered down the
snapshot to just the `linter.rules.enabled` section, which isn't
strictly necessary but was a lot shorter. I also tested manually in VS
Code to make sure I didn't miss wiring up the preview defaults in the
server:
<img width="681" height="340" alt="image"
src="https://github.com/user-attachments/assets/9f7a0cd4-968e-40d6-abf0-dfbfa496531d"
/>
I also tested in the playground.1 parent 1465b5d commit 222574a
File tree
7 files changed
+878
-7
lines changed- crates
- ruff_linter/src
- settings
- ruff_workspace/src
- ruff/tests
- cli
- scripts
7 files changed
+878
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
325 | 331 | | |
326 | 332 | | |
327 | 333 | | |
| |||
0 commit comments