Document the options used by more rules (#22198)

Summary
--

While analyzing our rules, I wanted to know which of them use
configuration options but noticed that some of them were not documented
(or at least not documented in a separate `## Options` section).

I had Claude generate an initial list of candidate rules, but it
contained a lot of false positives that I filtered out, and I ended up
adding all of these sections myself. I'm not claiming that the options
lists are exhaustive (as in the rules may use additional options beyond
what I found), but this will at least help with my goal of determining
whether or not a rule is configurable at all and also hopefully be
helpful in general.

I mostly just tacked on an `## Options` section without any commentary,
but I added a couple lines of explanation when I felt that the meaning
of the options wasn't obvious from the context.

I also noticed a bit of variation in the `flake8-simplify` rules from
doing this. Some of them offer a diagnostic but no fix depending on the
resulting line length of the suggestion, while others offer neither. I'm
not sure we need to do anything different here, but it seemed worth
mentioning.

Test Plan
--

Docs tests to make sure the links are right
This commit is contained in:
Brent Westbrook
2025-12-26 11:24:49 -05:00
committed by GitHub
parent 9693375e10
commit c842de5c4c
33 changed files with 199 additions and 0 deletions

View File

@@ -351,6 +351,10 @@ impl Violation for MissingReturnTypePrivateFunction {
/// def __init__(self, x: int) -> None:
/// self.x = x
/// ```
///
/// ## Options
///
/// - `lint.flake8-annotations.mypy-init-return`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
pub(crate) struct MissingReturnTypeSpecialMethod {
@@ -399,6 +403,10 @@ impl Violation for MissingReturnTypeSpecialMethod {
/// def bar() -> int:
/// return 1
/// ```
///
/// ## Options
///
/// - `lint.flake8-annotations.suppress-none-returning`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
pub(crate) struct MissingReturnTypeStaticMethod {
@@ -447,6 +455,10 @@ impl Violation for MissingReturnTypeStaticMethod {
/// def bar(cls) -> int:
/// return 1
/// ```
///
/// ## Options
///
/// - `lint.flake8-annotations.suppress-none-returning`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
pub(crate) struct MissingReturnTypeClassMethod {

View File

@@ -58,6 +58,10 @@ use crate::checkers::ast::Checker;
/// logging.exception("Something went wrong")
/// ```
///
/// ## Options
///
/// - `lint.logger-objects`
///
/// ## References
/// - [Python documentation: The `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement)
/// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy)

View File

@@ -58,6 +58,14 @@ use crate::checkers::ast::Checker;
/// return square(self.value)
/// ```
///
/// ## Options
///
/// This rule only applies to regular methods, not static or class methods. You can customize how
/// Ruff categorizes methods with the following options:
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
///
/// ## References
/// - [Python documentation: `functools.lru_cache`](https://docs.python.org/3/library/functools.html#functools.lru_cache)
/// - [Python documentation: `functools.cache`](https://docs.python.org/3/library/functools.html#functools.cache)

View File

@@ -32,6 +32,10 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// bar(i)
/// ```
///
/// ## Options
///
/// - `lint.dummy-variable-rgx`
///
/// ## References
/// - [PEP 8: Naming Conventions](https://peps.python.org/pep-0008/#naming-conventions)
#[derive(ViolationMetadata)]

View File

@@ -47,6 +47,10 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// raise RuntimeError(msg)
/// RuntimeError: 'Some value' is incorrect
/// ```
///
/// ## Options
///
/// - `lint.flake8-errmsg.max-string-length`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.183")]
pub(crate) struct RawStringInException;

View File

@@ -43,6 +43,10 @@ use crate::{Fix, FixAvailability, Violation};
///
/// ## Fix safety
/// The fix is always marked as unsafe, as it changes runtime behavior.
///
/// ## Options
///
/// - `lint.logger-objects`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.12.0")]
pub(crate) struct ExcInfoOutsideExceptHandler;

View File

@@ -30,6 +30,10 @@ use crate::checkers::ast::Checker;
/// ```python
/// logging.error("...")
/// ```
///
/// ## Options
///
/// - `lint.logger-objects`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.2.0")]
pub(crate) struct ExceptionWithoutExcInfo;

View File

@@ -42,6 +42,10 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## Fix safety
/// The fix, if available, will always be marked as unsafe, as it changes runtime behavior.
///
/// ## Options
///
/// - `lint.logger-objects`
///
/// [The documentation]: https://docs.python.org/3/library/logging.html#logging.exception
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.9.5")]

View File

@@ -32,6 +32,10 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// formatter automatically removes unnecessary escapes, making the rule
/// redundant.
///
/// ## Options
///
/// - `lint.flake8-quotes.inline-quotes`
///
/// [formatter]: https://docs.astral.sh/ruff/formatter
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.88")]

View File

@@ -55,6 +55,12 @@ use crate::rules::flake8_return::visitor::{ReturnVisitor, Stack};
/// ## Fix safety
/// This rule's fix is marked as unsafe for cases in which comments would be
/// dropped from the `return` statement.
///
/// ## Options
///
/// This rule ignores functions marked as properties.
///
/// - `lint.pydocstyle.property-decorators`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.154")]
pub(crate) struct UnnecessaryReturnNone;

View File

@@ -44,6 +44,15 @@ use crate::{FixAvailability, Violation};
/// pass
/// ```
///
/// ## Options
///
/// The rule will consult these two settings when deciding if a fix can be provided:
///
/// - `lint.pycodestyle.max-line-length`
/// - `indent-width`
///
/// Lines that would exceed the configured line length will not be fixed automatically.
///
/// ## References
/// - [Python documentation: The `with` statement](https://docs.python.org/3/reference/compound_stmts.html#the-with-statement)
#[derive(ViolationMetadata)]

View File

@@ -42,6 +42,15 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ...
/// ```
///
/// ## Options
///
/// The rule will consult these two settings when deciding if a fix can be provided:
///
/// - `lint.pycodestyle.max-line-length`
/// - `indent-width`
///
/// Lines that would exceed the configured line length will not be fixed automatically.
///
/// ## References
/// - [Python documentation: The `if` statement](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement)
/// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations)

View File

@@ -50,6 +50,14 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// value = foo.get("bar", 0)
/// ```
///
/// ## Options
///
/// The rule will avoid flagging cases where using the resulting `dict.get` call would exceed the
/// configured line length, as determined by these options:
///
/// - `lint.pycodestyle.max-line-length`
/// - `indent-width`
///
/// ## References
/// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict)
#[derive(ViolationMetadata)]

View File

@@ -55,6 +55,11 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// Ternary operators can also make it harder to measure [code coverage]
/// with tools that use line profiling.
///
/// ## Options
///
/// - `lint.pycodestyle.max-line-length`
/// - `indent-width`
///
/// ## References
/// - [Python documentation: Conditional expressions](https://docs.python.org/3/reference/expressions.html#conditional-expressions)
///

View File

@@ -40,6 +40,14 @@ use crate::{Edit, Fix, FixAvailability, Violation};
///
/// This fix is always marked as unsafe because it might remove comments.
///
/// ## Options
///
/// The rule will avoid flagging cases where using the builtin function would exceed the configured
/// line length, as determined by these options:
///
/// - `lint.pycodestyle.max-line-length`
/// - `indent-width`
///
/// ## References
/// - [Python documentation: `any`](https://docs.python.org/3/library/functions.html#any)
/// - [Python documentation: `all`](https://docs.python.org/3/library/functions.html#all)

View File

@@ -30,6 +30,12 @@ use rustc_hash::FxHashMap;
/// import foo
/// import bar
/// ```
///
/// ## Options
///
/// This rule ignores dummy variables, as determined by:
///
/// - `lint.dummy-variable-rgx`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.171")]
pub(crate) struct RedefinedWhileUnused {

View File

@@ -18,6 +18,12 @@ use crate::checkers::ast::Checker;
/// bar: int
/// ```
///
/// ## Options
///
/// This rule ignores dummy variables, as determined by:
///
/// - `lint.dummy-variable-rgx`
///
/// ## References
/// - [PEP 484 Type Hints](https://peps.python.org/pep-0484/)
#[derive(ViolationMetadata)]

View File

@@ -35,6 +35,11 @@ use crate::checkers::ast::Checker;
/// pass
/// ```
///
/// ## Options
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
///
/// [PEP 8]: https://peps.python.org/pep-0008/#function-and-method-arguments
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.6.0")]

View File

@@ -36,6 +36,10 @@ use crate::rules::pyflakes::cformat::CFormatSummary;
/// logging.error("%s error occurred: %s", type(e), e)
/// raise
/// ```
///
/// ## Options
///
/// - `lint.logger-objects`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.252")]
pub(crate) struct LoggingTooFewArgs;
@@ -74,6 +78,10 @@ impl Violation for LoggingTooFewArgs {
/// logging.error("%s error occurred: %s", type(e), e)
/// raise
/// ```
///
/// ## Options
///
/// - `lint.logger-objects`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.252")]
pub(crate) struct LoggingTooManyArgs;

View File

@@ -24,6 +24,12 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// from concurrent import futures
/// ```
///
/// ## Options
///
/// This rule will not trigger on imports required by the `isort` configuration.
///
/// - `lint.isort.required-imports`
///
/// ## References
/// - [Python documentation: Submodules](https://docs.python.org/3/reference/import.html#submodules)
#[derive(ViolationMetadata)]

View File

@@ -49,6 +49,13 @@ use crate::rules::flake8_unused_arguments::rules::is_not_implemented_stub_with_v
/// print("Greetings friend!")
/// ```
///
/// ## Options
///
/// The rule will not trigger on methods that are already marked as static or class methods.
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
///
/// [override]: https://docs.python.org/3/library/typing.html#typing.override
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "v0.0.286")]

View File

@@ -32,6 +32,10 @@ use crate::checkers::ast::Checker;
/// def purr_volume(self, volume): ...
/// ```
///
/// ## Options
///
/// - `lint.pydocstyle.property-decorators`
///
/// ## References
/// - [Python documentation: `property`](https://docs.python.org/3/library/functions.html#property)
#[derive(ViolationMetadata)]

View File

@@ -27,6 +27,12 @@ use crate::checkers::ast::Checker;
/// _, b, a = (1, 2, 3)
/// print(a) # 3
/// ```
///
/// ## Options
///
/// The rule ignores assignments to dummy variables, as specified by:
///
/// - `lint.dummy-variable-rgx`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.5.0")]
pub(crate) struct RedeclaredAssignedName {

View File

@@ -48,6 +48,12 @@ use crate::checkers::ast::Checker;
/// f = path2.open()
/// print(f.readline()) # prints a line from path2
/// ```
///
/// ## Options
///
/// The rule ignores assignments to dummy variables, as specified by:
///
/// - `lint.dummy-variable-rgx`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.252")]
pub(crate) struct RedefinedLoopName {

View File

@@ -45,6 +45,11 @@ use crate::checkers::ast::Checker;
/// supercls = cls.__mro__[-1]
/// return supercls
/// ```
///
/// ## Options
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.6.0")]
pub(crate) struct SelfOrClsAssignment {

View File

@@ -42,6 +42,14 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## Fix safety
/// This rule's fix is marked as unsafe, as migrating from `@singledispatch` to
/// `@singledispatchmethod` may change the behavior of the code.
///
/// ## Options
///
/// This rule applies to regular, static, and class methods. You can customize how Ruff categorizes
/// methods with the following options:
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.6.0")]
pub(crate) struct SingledispatchMethod;

View File

@@ -46,6 +46,14 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// original_speak = super().speak() # Correct: `super().speak()`
/// return f"{original_speak} But as a dog, it barks!"
/// ```
///
/// ## Options
///
/// This rule applies to regular, static, and class methods. You can customize how Ruff categorizes
/// methods with the following options:
///
/// - `lint.pep8-naming.classmethod-decorators`
/// - `lint.pep8-naming.staticmethod-decorators`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.5.0")]
pub(crate) struct SuperWithoutBrackets;

View File

@@ -33,6 +33,13 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ```python
/// import numpy
/// ```
///
/// ## Options
///
/// The rule will emit a diagnostic but not a fix if the import is required by the `isort`
/// configuration option:
///
/// - `lint.isort.required-imports`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.156")]
pub(crate) struct UselessImportAlias {

View File

@@ -45,6 +45,12 @@ pub(crate) enum MockReference {
/// from unittest import mock
/// ```
///
/// ## Options
///
/// This rule will not trigger if the `mock` import is required by the `isort` configuration.
///
/// - `lint.isort.required-imports`
///
/// ## References
/// - [Python documentation: `unittest.mock`](https://docs.python.org/3/library/unittest.mock.html)
/// - [PyPI: `mock`](https://pypi.org/project/mock/)

View File

@@ -43,6 +43,12 @@ use crate::{AlwaysFixableViolation, Fix};
/// str(1) # `"1"` with the import, `1` without
/// ```
///
/// ## Options
///
/// This rule will not trigger on imports required by the `isort` configuration.
///
/// - `lint.isort.required-imports`
///
/// ## References
/// - [Python documentation: The Python Standard Library](https://docs.python.org/3/library/index.html)
#[derive(ViolationMetadata)]

View File

@@ -58,6 +58,10 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// This fix will always change the behavior of the program and, despite the precautions detailed
/// above, this may be undesired. As such the fix is always marked as unsafe.
///
/// ## Options
///
/// - `lint.logger-objects`
///
/// [logging]: https://docs.python.org/3/howto/logging-cookbook.html#using-particular-formatting-styles-throughout-your-application
/// [gettext]: https://docs.python.org/3/library/gettext.html
/// [FastAPI path]: https://fastapi.tiangolo.com/tutorial/path-params/

View File

@@ -49,6 +49,10 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// `logger.error`), since the rule is prone to false positives when detecting
/// logger-like calls outside of the `logging` module.
///
/// ## Options
///
/// - `lint.logger-objects`
///
/// ## References
/// - [Python documentation: `logging.exception`](https://docs.python.org/3/library/logging.html#logging.exception)
#[derive(ViolationMetadata)]

View File

@@ -33,6 +33,10 @@ use crate::rules::tryceratops::helpers::LoggerCandidateVisitor;
/// except ValueError:
/// logger.exception("Found an error")
/// ```
///
/// ## Options
///
/// - `lint.logger-objects`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.250")]
pub(crate) struct VerboseLogMessage;