Skip to content

Document rule acceptance guidelines - #27910

Merged
ntBre merged 13 commits into
brent/category-docsfrom
brent/rule-acceptance-guidelines
Aug 27, 2026
Merged

ntBre merged 13 commits into
brent/category-docsfrom
brent/rule-acceptance-guidelines

Conversation

@ntBre

@ntBre ntBre commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR includes the contributor-facing documentation for the new categories, as well as updated
rule acceptance guidelines built atop them.

I think we could also update our rule request template based on some of these guidelines, but I'll save that for a follow-up once these are solidified.

Test Plan

Future rule requests

@ntBre ntBre added the documentation Improvements or additions to public-facing documentation label Aug 19, 2026
Comment thread CONTRIBUTING.md
statements, like imports) or `analyze/expression.rs` (if your rule is based on analyzing
expressions, like function calls).

1. Map the violation struct to a rule code in `crates/ruff_linter/src/codes.rs` (e.g., `B011`).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should we drop this requirement yet? 😮

It feels like probably not, but it also seems awkward to have to choose both a category and a linter group. This macro also generates a ton of Rule code that we'll have to generate some other way if we stop requiring this mapping.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can today? We can remove it once our rule infrastructure supports it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is related to what I mentioned for my plan this week. I'm looking into what it would take to support this, but we definitely can't drop this from the docs yet.

Comment thread CONTRIBUTING.md Outdated
### Example: Adding a new lint rule
### Proposing a new lint rule

A proposal for a new lint rule in Ruff should include the following components:

@MichaReiser MichaReiser Aug 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are a lot of requirements for proposing a new rule. I think i'd set this as a bar for a PR, or for a rule to be accepted. But I don't think we should enforce this when users open an issue with a rule idea. Even for an issue, that's probably more than I'd ask for.

I think, for an accepted rule, we should have a proposed name, a category, and a draft of What it does, why this is bad, and maybe an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with you that it's a lot to ask. We do get a lot of very brief rule requests that linger with needs-decision Awaiting a decision from a maintainer , though. I wasn't thinking that we'd instantly close any requests without all this information, but I think the more information provided, the more seriously we can consider a request.

Maybe the name, category, and other sections you mention are a better sweet spot, though.

What do you think about the proposed diagnostic? I thought that was kind of a fun way to capture a lot about the proposed rule without requiring too much work.

I'd also like to find somewhere else to put all of these optional sections, if we remove them here. I don't think we currently have a canonical list of typical documentation sections. Maybe I could better clarify that all of these requirements should be met by the time a rule is added and note which parts can be deferred for the implementation PR. That would help with the ecosystem circularity too.

I guess we don't want to discourage too many people from opening rule requests, but I kind of don't mind documenting the "ideal" process, assuming that most people won't read or follow it anyway.

I added a note trying to clarify this for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you on needs-decision and I'd love to reduce the number of issues labeled with needs-decision. What if it's more a two-stage process. You can still open issues with very brief descriptions. We take an initial look to decide whether this roughly fits into Ruff and, if so, mark it as needs-design and ask for someone to fill out our template (we can link to this very specific guide). Requests that never make it past needs-design can be closed after , unless we think this is a rule we should add.

What do you think about the proposed diagnostic? I thought that was kind of a fun way to capture a lot about the proposed rule without requiring too much work.

I think it's a very nice idea because it also raises questions around the rule's span and how to convey the problem. But I don't think I'd make it a requirement for a rule to be accepted. It's a nice bonus. It's something that we can also iterate on in the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an initial note about a brief issue being okay, mentioning the needs-design step, and further separating out the parts needed for the design proposal and implementation.

Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment thread CONTRIBUTING.md Outdated
Comment on lines +313 to +337
almost always a mistake, but in some narrow cases beyond Ruff's understanding, it may be
intentional, in which case a `noqa` or `ruff: ignore` comment should be used. Such suppression
comments should essentially never be reasonable for a `correctness` lint but are fine for
`suspicious` lints.

At a high level, the steps involved in adding a new lint rule are as follows:
The final branch of the flow chart deals with stylistic lints, which are again somewhat subjective
to differentiate between because changes that make code simpler often also make the code faster and
more idiomatic. Thus, the question prompts you to consider the _primary_ improvement. Rules that
primarily make code simpler are `complexity` lints, those that primarily make code faster or use
less memory are `performance` lints, and those that primarily make code more idiomatic are `style`.

1. Determine a name for the new rule as per our [rule naming convention](#rule-naming-convention)
(e.g., `AssertFalse`, as in, "allow `assert False`").
#### Other guidelines

Following these steps should generally ensure that a rule is a good fit for Ruff. A couple of
additional things to watch out for are:

- Rules that conflict with other tools, or especially other rules

Although we have many existing `formatting` rules that overlap and even conflict with our
formatter, we are not eager to add more. Similarly, we should avoid rules that mainly support
type checker usage, when type checkers themselves emit similar diagnostics. Most clearly, we
should avoid rules that overlap or conflict with other lint rules. This often suggests that the
existing rule should instead be made configurable to toggle between the two behaviors.

Checking both the input and output examples from your rule proposal with `ALL` rules selected in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could link to multiplay here. @AlexWaygood do we have a public link?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiplay is a public repo! https://github.com/astral-sh/multiplay

multiplay is still not hosted anywhere, so you do have to clone the repo and then run it locally, though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about adding pre-configured Ruff and ty playground links here at least. I'll give that a try since multiplay isn't hosted anywhere.

Comment thread CONTRIBUTING.md Outdated
Comment on lines +344 to +345
libraries, but this niche should be filled by plugins in the near future. Most Ruff rules should
apply to Python language features or to functionality from the standard library.

@MichaReiser MichaReiser Aug 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy explicitly is open to widely used third party libraries. I do think this makes sense, similar to ty supporting attrs etc. But I agree, I wouldn't count airflow as one such library because it's very specific. But libraries that are so widely used that you find them in almost every application, having suspicious and correctness rules for those seems valuable to most of our users.

I'd feel more hesitant from adding deprecation rules for third party libraries. That feels like a good use for plugins

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all of that. Does this read as too firm? I tried to make this whole #### Other guidelines section read as general guidance with room for exceptions, but that may not come across clearly enough.

I intended it to be somewhat firm but may have gone too far.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does sound to me that rule requests for third-party libraries would always be reject. Our stance here might also change once we support plugins

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to soften this and also removed the mention of plugins for now.

@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch 2 times, most recently from 96dc01c to bae1566 Compare August 20, 2026 13:59
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from bae1566 to 268fbc2 Compare August 20, 2026 14:55
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from a545fa3 to 62615d4 Compare August 20, 2026 18:43
@astral-sh-bot

astral-sh-bot Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from 62615d4 to 6cf340f Compare August 20, 2026 19:01
@ntBre
ntBre marked this pull request as ready for review August 20, 2026 19:10
@MichaReiser
MichaReiser self-requested a review August 21, 2026 06:49
Comment thread CONTRIBUTING.md Outdated

#### Other guidelines

Following these steps should generally ensure that a rule is a good fit for Ruff. A couple of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't see much in here that explains when Ruff would accept a rule, it's much more about the mechanics of how to add one. What criteria would you (the Ruff maintainers) use to decide whether or not to accept a rule? This guideline offers some special cases but not a general set of principles on which to base the decision.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see what you mean, but I guess my thinking was if you've followed these steps and come up with:

  • a good name
  • a suitable category
  • convincing "what it does" and especially "why is this bad" docs

and not violated any of these special cases (or made a case for why your rule is an exception), then we'd accept the rule. I don't think the goal is to set a super high bar, just standardize some of the things we look for and make sure we have enough information for an acceptance decision. That's part of why I didn't actually end up using "Rule Acceptance Guidelines" directly in the docs.

One of the goals of the new categories is actually to make it easier to add rules without having to worry so much about their linter codes.

@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from 6cf340f to 8d745ad Compare August 21, 2026 17:12
@codspeed

codspeed Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 60 untouched benchmarks
⏩ 150 skipped benchmarks1


Comparing brent/rule-acceptance-guidelines (e20dedb) with brent/category-docs (0f847a5)2

Open in CodSpeed

Footnotes

  1. 150 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on brent/category-docs (5518fd2) during the generation of this report, so b8fc8be was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from 8d745ad to 58a4878 Compare August 21, 2026 17:45
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch 2 times, most recently from 0a21c1b to eb3e945 Compare August 25, 2026 18:51
Comment thread docs/rule-proposals.md Outdated
Comment on lines +141 to +146
Note that "useless" in the context of a `correctness` rule should be indicative of a mistake. For
example, `useless-exception-statement` (`PLW0133`) flags exceptions that are constructed and never
raised, suggesting that the user forgot to raise or otherwise use them. In contrast, code that is
merely unnecessary but still working as intended may be a better fit for `complexity`, such as
`useless-try-except` (`TRY203`). As described above, if the code is probably not intentional but may
be in certain cases, `suspicious` can also be a good fit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this note about "useless" vs "unnecessary" in light of our discussions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I like this. I wonder if we should also mention style.

@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from eb3e945 to 79d0963 Compare August 25, 2026 21:05
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from 79d0963 to b3e39de Compare August 26, 2026 18:57
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from b3e39de to 81f28bb Compare August 26, 2026 22:48
@ntBre
ntBre force-pushed the brent/rule-acceptance-guidelines branch from 81f28bb to e20dedb Compare August 27, 2026 13:20
@ntBre
ntBre merged commit 29c8e5b into main Aug 27, 2026
49 checks passed
@ntBre
ntBre deleted the brent/rule-acceptance-guidelines branch August 27, 2026 15:26
sharkdp pushed a commit that referenced this pull request Aug 31, 2026
Summary
--

This PR includes the contributor-facing documentation for the new
categories, as well as updated
rule acceptance guidelines built atop them.

I think we could also update our rule request template based on some of
these guidelines, but I'll save that for a follow-up once these are
solidified.

Test Plan
--

Future rule requests

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to public-facing documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants