Skip to content

Commit

Permalink
Check that all rules have descriptions (#4315)
Browse files Browse the repository at this point in the history
  • Loading branch information
calumy committed May 9, 2023
1 parent 8dea47a commit 03f141f
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`{}`).
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
///
Expand Down
11 changes: 11 additions & 0 deletions scripts/check_docs_formatted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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") :]

Expand Down

0 comments on commit 03f141f

Please sign in to comment.