Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| UP045 | 5834 | 5834 | 0 | 0 | 0 |
| FA102 | 2916 | 2916 | 0 | 0 | 0 |
| UP006 | 2219 | 2219 | 0 | 0 | 0 |
| C408 | 1387 | 1387 | 0 | 0 | 0 |
| UP037 | 1130 | 1130 | 0 | 0 | 0 |
| UP007 | 902 | 902 | 0 | 0 | 0 |
| UP035 | 798 | 798 | 0 | 0 | 0 |
| RUF100 | 671 | 671 | 0 | 0 | 0 |
| FA100 | 484 | 484 | 0 | 0 | 0 |
| RET504 | 457 | 457 | 0 | 0 | 0 |
| B008 | 446 | 446 | 0 | 0 | 0 |
| BLE001 | 345 | 345 | 0 | 0 | 0 |
| SIM117 | 300 | 300 | 0 | 0 | 0 |
| RUF012 | 185 | 185 | 0 | 0 | 0 |
| SIM102 | 178 | 178 | 0 | 0 | 0 |
| RUF059 | 173 | 173 | 0 | 0 | 0 |
| TRY002 | 122 | 122 | 0 | 0 | 0 |
| I001 | 120 | 120 | 0 | 0 | 0 |
| TRY300 | 116 | 116 | 0 | 0 | 0 |
| PERF401 | 109 | 109 | 0 | 0 | 0 |
| PLR0402 | 86 | 86 | 0 | 0 | 0 |
| RUF022 | 84 | 84 | 0 | 0 | 0 |
| C419 | 78 | 78 | 0 | 0 | 0 |
| PYI036 | 73 | 73 | 0 | 0 | 0 |
| DTZ001 | 68 | 68 | 0 | 0 | 0 |
| SIM118 | 66 | 66 | 0 | 0 | 0 |
| TRY004 | 66 | 66 | 0 | 0 | 0 |
| TRY201 | 65 | 65 | 0 | 0 | 0 |
| RUF015 | 63 | 63 | 0 | 0 | 0 |
| SIM115 | 60 | 60 | 0 | 0 | 0 |
| FLY002 | 59 | 59 | 0 | 0 | 0 |
| PYI063 | 56 | 56 | 0 | 0 | 0 |
| B018 | 52 | 52 | 0 | 0 | 0 |
| B006 | 47 | 47 | 0 | 0 | 0 |
| RUF010 | 45 | 45 | 0 | 0 | 0 |
| PIE790 | 44 | 44 | 0 | 0 | 0 |
| PYI034 | 42 | 42 | 0 | 0 | 0 |
| S110 | 40 | 40 | 0 | 0 | 0 |
| PLR1714 | 35 | 35 | 0 | 0 | 0 |
| RUF013 | 33 | 33 | 0 | 0 | 0 |
| B010 | 32 | 32 | 0 | 0 | 0 |
| SIM114 | 32 | 32 | 0 | 0 | 0 |
| PLR1704 | 30 | 30 | 0 | 0 | 0 |
| G201 | 30 | 30 | 0 | 0 | 0 |
| SIM103 | 30 | 30 | 0 | 0 | 0 |
| B009 | 30 | 30 | 0 | 0 | 0 |
| DTZ005 | 29 | 29 | 0 | 0 | 0 |
| C401 | 27 | 27 | 0 | 0 | 0 |
| RET501 | 27 | 27 | 0 | 0 | 0 |
| C402 | 27 | 27 | 0 | 0 | 0 |
| PERF402 | 26 | 26 | 0 | 0 | 0 |
| PIE804 | 26 | 26 | 0 | 0 | 0 |
| PYI032 | 26 | 26 | 0 | 0 | 0 |
| PYI041 | 23 | 23 | 0 | 0 | 0 |
| LOG015 | 21 | 21 | 0 | 0 | 0 |
| UP032 | 21 | 21 | 0 | 0 | 0 |
| PLC0414 | 21 | 21 | 0 | 0 | 0 |
| PLW1510 | 19 | 19 | 0 | 0 | 0 |
| B015 | 19 | 19 | 0 | 0 | 0 |
| UP012 | 19 | 19 | 0 | 0 | 0 |
| UP030 | 19 | 19 | 0 | 0 | 0 |
| PLW1508 | 18 | 18 | 0 | 0 | 0 |
| PLR1711 | 18 | 18 | 0 | 0 | 0 |
| PT031 | 18 | 18 | 0 | 0 | 0 |
| C403 | 18 | 18 | 0 | 0 | 0 |
| PT014 | 17 | 17 | 0 | 0 | 0 |
| C405 | 17 | 17 | 0 | 0 | 0 |
| PIE807 | 17 | 17 | 0 | 0 | 0 |
| PYI055 | 17 | 17 | 0 | 0 | 0 |
| C413 | 16 | 16 | 0 | 0 | 0 |
| S102 | 16 | 16 | 0 | 0 | 0 |
| PYI066 | 15 | 15 | 0 | 0 | 0 |
| PLW0602 | 14 | 14 | 0 | 0 | 0 |
| PYI019 | 14 | 14 | 0 | 0 | 0 |
| F403 | 14 | 0 | 14 | 0 | 0 |
| PYI016 | 13 | 13 | 0 | 0 | 0 |
| UP004 | 13 | 13 | 0 | 0 | 0 |
| E402 | 13 | 0 | 13 | 0 | 0 |
| PIE808 | 11 | 11 | 0 | 0 | 0 |
| PIE810 | 11 | 11 | 0 | 0 | 0 |
| PERF102 | 11 | 11 | 0 | 0 | 0 |
| C417 | 10 | 10 | 0 | 0 | 0 |
| PLC0208 | 10 | 10 | 0 | 0 | 0 |
| B017 | 10 | 10 | 0 | 0 | 0 |
| UP009 | 10 | 10 | 0 | 0 | 0 |
| SIM201 | 9 | 9 | 0 | 0 | 0 |
| C414 | 9 | 9 | 0 | 0 | 0 |
| PYI059 | 9 | 9 | 0 | 0 | 0 |
| SIM101 | 8 | 8 | 0 | 0 | 0 |
| UP034 | 8 | 8 | 0 | 0 | 0 |
| D419 | 8 | 8 | 0 | 0 | 0 |
| TRY401 | 8 | 8 | 0 | 0 | 0 |
| TRY203 | 8 | 8 | 0 | 0 | 0 |
| PLR0133 | 8 | 8 | 0 | 0 | 0 |
| E712 | 8 | 0 | 8 | 0 | 0 |
| B023 | 7 | 7 | 0 | 0 | 0 |
| PLR1722 | 7 | 7 | 0 | 0 | 0 |
| PLC0206 | 7 | 7 | 0 | 0 | 0 |
| UP024 | 7 | 7 | 0 | 0 | 0 |
| C400 | 7 | 7 | 0 | 0 | 0 |
| B026 | 7 | 7 | 0 | 0 | 0 |
| FURB177 | 7 | 7 | 0 | 0 | 0 |
| G202 | 7 | 7 | 0 | 0 | 0 |
| LOG014 | 7 | 7 | 0 | 0 | 0 |
| PLW0127 | 6 | 6 | 0 | 0 | 0 |
| PLR2044 | 6 | 6 | 0 | 0 | 0 |
| PLW0120 | 6 | 6 | 0 | 0 | 0 |
| RUF018 | 6 | 6 | 0 | 0 | 0 |
| RUF023 | 6 | 6 | 0 | 0 | 0 |
| FURB167 | 5 | 5 | 0 | 0 | 0 |
| PERF403 | 5 | 5 | 0 | 0 | 0 |
| EXE001 | 5 | 5 | 0 | 0 | 0 |
| PIE800 | 5 | 5 | 0 | 0 | 0 |
| UP036 | 5 | 5 | 0 | 0 | 0 |
| PLR1733 | 5 | 5 | 0 | 0 | 0 |
| TC004 | 5 | 5 | 0 | 0 | 0 |
| PLR0124 | 5 | 5 | 0 | 0 | 0 |
| SIM905 | 5 | 5 | 0 | 0 | 0 |
| SIM210 | 4 | 4 | 0 | 0 | 0 |
| DTZ007 | 4 | 4 | 0 | 0 | 0 |
| FURB136 | 4 | 4 | 0 | 0 | 0 |
| DTZ011 | 4 | 4 | 0 | 0 | 0 |
| PTH124 | 4 | 4 | 0 | 0 | 0 |
| PLE0704 | 3 | 3 | 0 | 0 | 0 |
| LOG009 | 3 | 3 | 0 | 0 | 0 |
| TC005 | 3 | 3 | 0 | 0 | 0 |
| UP031 | 3 | 3 | 0 | 0 | 0 |
| FURB188 | 3 | 3 | 0 | 0 | 0 |
| B020 | 3 | 3 | 0 | 0 | 0 |
| PYI030 | 3 | 3 | 0 | 0 | 0 |
| B033 | 3 | 3 | 0 | 0 | 0 |
| N999 | 3 | 3 | 0 | 0 | 0 |
| PIE796 | 2 | 2 | 0 | 0 | 0 |
| FURB129 | 2 | 2 | 0 | 0 | 0 |
| EXE002 | 2 | 2 | 0 | 0 | 0 |
| DTZ004 | 2 | 2 | 0 | 0 | 0 |
| SIM113 | 2 | 2 | 0 | 0 | 0 |
| PLE1205 | 2 | 2 | 0 | 0 | 0 |
| PLR1730 | 2 | 2 | 0 | 0 | 0 |
| PLW0128 | 2 | 2 | 0 | 0 | 0 |
| PIE794 | 2 | 2 | 0 | 0 | 0 |
| YTT103 | 2 | 2 | 0 | 0 | 0 |
| UP010 | 2 | 2 | 0 | 0 | 0 |
| SIM211 | 2 | 2 | 0 | 0 | 0 |
| PLC0205 | 2 | 2 | 0 | 0 | 0 |
| UP028 | 2 | 2 | 0 | 0 | 0 |
| PLC0105 | 2 | 2 | 0 | 0 | 0 |
| SIM223 | 2 | 2 | 0 | 0 | 0 |
| PYI061 | 2 | 2 | 0 | 0 | 0 |
| PYI025 | 2 | 2 | 0 | 0 | 0 |
| UP018 | 2 | 2 | 0 | 0 | 0 |
| FURB105 | 2 | 2 | 0 | 0 | 0 |
| FURB157 | 1 | 1 | 0 | 0 | 0 |
| PLW1509 | 1 | 1 | 0 | 0 | 0 |
| PLW0133 | 1 | 1 | 0 | 0 | 0 |
| PLW0211 | 1 | 1 | 0 | 0 | 0 |
| UP014 | 1 | 1 | 0 | 0 | 0 |
| RUF007 | 1 | 1 | 0 | 0 | 0 |
| S112 | 1 | 1 | 0 | 0 | 0 |
| B012 | 1 | 1 | 0 | 0 | 0 |
| PLW0642 | 1 | 1 | 0 | 0 | 0 |
| B013 | 1 | 1 | 0 | 0 | 0 |
| YTT301 | 1 | 1 | 0 | 0 | 0 |
| DTZ006 | 1 | 1 | 0 | 0 | 0 |
| B039 | 1 | 1 | 0 | 0 | 0 |
| UP011 | 1 | 1 | 0 | 0 | 0 |
| DTZ901 | 1 | 1 | 0 | 0 | 0 |
| FURB163 | 1 | 1 | 0 | 0 | 0 |
| PLW0129 | 1 | 1 | 0 | 0 | 0 |
| B030 | 1 | 1 | 0 | 0 | 0 |
| RUF051 | 1 | 1 | 0 | 0 | 0 |
| LOG001 | 1 | 1 | 0 | 0 | 0 |
| DTZ002 | 1 | 1 | 0 | 0 | 0 |
| RUF019 | 1 | 1 | 0 | 0 | 0 |
| PLR1736 | 1 | 1 | 0 | 0 | 0 |
| DTZ003 | 1 | 1 | 0 | 0 | 0 |
| PYI044 | 1 | 1 | 0 | 0 | 0 |
| FURB122 | 1 | 1 | 0 | 0 | 0 |
| PYI006 | 1 | 1 | 0 | 0 | 0 |
| PYI045 | 1 | 1 | 0 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
| In [preview](https://docs.astral.sh/ruff/preview/), Ruff enables an expanded set of default rules | ||
| that includes rules from the `B`, `UP`, and `RUF` categories, as well as many more. If you give the | ||
| new defaults a try, feel free to leave feedback in the [GitHub | ||
| discussion](https://github.com/astral-sh/ruff/discussions/23203), where you can also find the new | ||
| rule set listed in full. | ||
|
|
There was a problem hiding this comment.
I'm not totally sold on including this, especially in the README (but this is how the top of our Rules page is generated). I'd be happy just to put something like this in the release notes instead, but I'm curious what others think.
There was a problem hiding this comment.
I like including this, but should probably also say something along the lines of "and this will be the default set in a future minor release"
There was a problem hiding this comment.
To me that's kind of implied by referencing preview, but I don't feel too strongly.
There was a problem hiding this comment.
I like it here, and I agree with you that "in a future minor" is implicit. (In fact - if people don't like them in preview, then they won't be stabilized in a future minor!)
|
I think there are a few too many ecosystem results to verify them all manually, but I wanted to at least address a few of the top rules:
Those are a few high level thoughts. I'm working on a script to check a sample of the diagnostics directly just to rule out some obvious false positives. I think this is otherwise ready for review! |
amyreese
left a comment
There was a problem hiding this comment.
I'm also curious: how many of the rules that are currently default will get disabled by default in preview mode? Is that worth calling out somewhere?
|
I'm pretty happy with the ecosystem results. It looks like prefect only recently (PrefectHQ/prefect#19273) dropped Python 3.9 support, which explains why they have so many Similarly, chameleon and qdrant-client do not declare versions, so we default them to an older Python version and thus report FA102. I guess we could consider defaulting to the latest Python version for this rule instead of the oldest since the semantics are reversed from most rules that use C408 is one case where the results might be changing my mind. I think this came up in an earlier discussion, but I kind of like to use the RUF100 also seems somewhat troubling. The examples I checked for prefect were blanket noqas, so it's not even possible to configure around them with The prefect hits for B008 also look like false positives, but they're in functions decorated with decorators from typer and fastapi, so I think it's reasonable. And they can be fixed by configuring lint.flake8-bugbear.extend-immutable-calls. It looks like PIE796 technically has 2 false positives of this form: class Store(Enum):
overwrite = object()
write = object()
skip = object()
^ PIE796: Enum contains duplicate value: `object()`
def handle(self, getter: Callable[[], str], path: str) -> None:but I guess it's probably better to use There's a strange false positive for B030 in setuptools: try:
parsed = self.parsers.get(option_name, lambda x: x)(value)
except (Exception,) * self.ignore_option_errors:
^ B030: `except` handlers should only be exception classes or tuples of exception classes
returnI assume A couple other rules looked more pedantic to me today, but I don't want to second guess too many of the rules. Hopefully we're about to get some feedback on them anyway! I'm leaning toward moving ahead with this set, with the possible exception of C408. |
I think only a handful of the E rules were removed, but I can double check and try to work that in somewhere! |
Rather than turn off RUF100 (I think that would be a huge miss) maybe we should narrow RUF100 to not fire on blanket noqa, and have a separate code for that? We could combine that with narrowing RUF100 to not overlap with RUF102? |
|
Maybe C408 could similarly be narrowed to only fire on |
|
I like those suggestions. It does make some sense to me to leave these rules in the default set and potentially update their behavior instead of removing them. |
That could be effected by keeping the rule as is but defaulting |
On second thought, I think this will be too verbose to work in smoothly. For reference, these are the removed rules: so it is mostly |
Could be worth documenting somewhere and reference it in the changelog at the same time. My main consideration would be the UX of users expecting those rules to be enabled, or unexpectedly getting RUF100 for any existing |
|
I'd be open to suggestions for where to document it! I just think it feels out of place in the README/top of the Rules page, but that's the main place where we discuss the defaults. And it's now documented here in the PR, which is linked from the release notes, at least. I could also add it to the body of the discussion and/or the changelog itself if nothing else. |
dylwil3
left a comment
There was a problem hiding this comment.
Amazing! Thanks for all the analysis and discussion that went into this
| In [preview](https://docs.astral.sh/ruff/preview/), Ruff enables an expanded set of default rules | ||
| that includes rules from the `B`, `UP`, and `RUF` categories, as well as many more. If you give the | ||
| new defaults a try, feel free to leave feedback in the [GitHub | ||
| discussion](https://github.com/astral-sh/ruff/discussions/23203), where you can also find the new | ||
| rule set listed in full. | ||
|
|
There was a problem hiding this comment.
I like it here, and I agree with you that "in a future minor" is implicit. (In fact - if people don't like them in preview, then they won't be stabilized in a future minor!)
We also don't have to feel too bad about modifying this default set while it's still in preview. |
Summary
This PR adds the new default rule set in preview. This ended up being pretty non-invasive because the
DEFAULT_SELECTORSare only used in one place wherepreviewisn't set to the default value offalse.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.Script
Test Plan
A new CLI test showing the preview default rules. I filtered down the snapshot to just the
linter.rules.enabledsection, 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:I also tested in the playground.