mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Check that all rules have descriptions (#4315)
This commit is contained in:
parent
8dea47afc1
commit
03f141f53d
14 changed files with 25 additions and 14 deletions
|
@ -16,7 +16,7 @@ use crate::rules::flake8_bugbear::rules::mutable_argument_default::is_mutable_fu
|
|||
/// ## What it does
|
||||
/// Checks for function calls in default function arguments.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// Any function call that's used in a default argument will only be performed
|
||||
/// once, at definition time. The returned value will then be reused by all
|
||||
/// calls to the function, which can lead to unexpected behaviour.
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for multiple usage of the generator returned from
|
||||
/// `itertools.groupby()`.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// Using the generator more than once will do nothing on the second usage.
|
||||
/// If that data is needed later, it should be stored as a list.
|
||||
///
|
||||
|
|
|
@ -11,7 +11,7 @@ use super::helpers;
|
|||
/// ## What it does
|
||||
/// Checks for unnecessary `list` calls around list comprehensions.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It is redundant to use a `list` call around a list comprehension.
|
||||
///
|
||||
/// ## Examples
|
||||
|
|
|
@ -11,7 +11,7 @@ use super::helpers;
|
|||
/// ## What it does
|
||||
/// Checks for unnecessary list comprehensions.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list comprehension inside a call to `dict`,
|
||||
/// since there is an equivalent comprehension for this type.
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::helpers;
|
|||
/// ## What it does
|
||||
/// Checks for unnecessary list comprehensions.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list comprehension inside a call to `set`,
|
||||
/// since there is an equivalent comprehension for this type.
|
||||
///
|
||||
|
|
|
@ -11,7 +11,7 @@ use super::helpers;
|
|||
/// ## What it does
|
||||
/// Checks for unnecessary `list` or `tuple` literals.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list or tuple literal within a call to `dict`.
|
||||
/// It can be rewritten as a dict literal (`{}`).
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::helpers;
|
|||
/// Checks for `set` calls that take unnecessary `list` or `tuple` literals
|
||||
/// as arguments.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list or tuple literal within a call to `set`.
|
||||
/// Instead, the expression can be rewritten as a set literal.
|
||||
///
|
||||
|
|
|
@ -29,7 +29,7 @@ impl fmt::Display for DictKind {
|
|||
/// Checks for `dict` calls that take unnecessary `dict` literals or `dict`
|
||||
/// comprehensions as arguments.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to wrap a `dict` literal or comprehension within a `dict`
|
||||
/// call, since the literal or comprehension syntax already returns a `dict`.
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::helpers;
|
|||
/// Checks for `list` calls that take unnecessary list or tuple literals as
|
||||
/// arguments.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list or tuple literal within a `list()` call,
|
||||
/// since there is a literal syntax for these types.
|
||||
///
|
||||
|
|
|
@ -12,7 +12,7 @@ use super::helpers;
|
|||
/// Checks for `tuple` calls that take unnecessary list or tuple literals as
|
||||
/// arguments.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to use a list or tuple literal within a `tuple()` call,
|
||||
/// since there is a literal syntax for these types.
|
||||
///
|
||||
|
|
|
@ -10,7 +10,7 @@ use super::helpers;
|
|||
/// ## What it does
|
||||
/// Checks for unnecessary subscript reversal of iterable.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// It's unnecessary to reverse the order of an iterable when passing it
|
||||
/// into `reversed()`, `set()` or `sorted()` functions as they will change
|
||||
/// the order of the elements again.
|
||||
|
|
|
@ -13,7 +13,7 @@ use super::helpers;
|
|||
/// Checks for the order of Model's inner classes, methods, and fields as per
|
||||
/// the [Django Style Guide].
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// The [Django Style Guide] specifies that the order of Model inner classes,
|
||||
/// attributes and methods should be as follows:
|
||||
///
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::checkers::ast::Checker;
|
|||
/// Checks for mutable default values in dataclasses without the use of
|
||||
/// `dataclasses.field`.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// Mutable default values share state across all instances of the dataclass,
|
||||
/// while not being obvious. This can lead to bugs when the attributes are
|
||||
/// changed in one instance, as those changes will unexpectedly affect all
|
||||
|
@ -66,7 +66,7 @@ impl Violation for MutableDataclassDefault {
|
|||
/// ## What it does
|
||||
/// Checks for function calls in dataclass defaults.
|
||||
///
|
||||
/// ## Why is it bad?
|
||||
/// ## Why is this bad?
|
||||
/// Function calls are only performed once, at definition time. The returned
|
||||
/// value is then reused by all instances of the dataclass.
|
||||
///
|
||||
|
|
|
@ -85,6 +85,17 @@ def format_file(
|
|||
with file.open() as f:
|
||||
contents = f.read()
|
||||
|
||||
if file.parent.name == "rules":
|
||||
# Check contents contains "What it does" section
|
||||
if "## What it does" not in contents:
|
||||
print(f"Docs for `{file.name}` are missing the `What it does` section.")
|
||||
return 1
|
||||
|
||||
# Check contents contains "Why is this bad?" section
|
||||
if "## Why is this bad?" not in contents:
|
||||
print(f"Docs for `{file.name}` are missing the `Why is this bad?` section.")
|
||||
return 1
|
||||
|
||||
# Remove everything before the first example
|
||||
contents = contents[contents.find("## Example") :]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue