From 03f141f53d5c859eebf3201257c3916ecedcfb5e Mon Sep 17 00:00:00 2001 From: Calum Young <32770960+calumy@users.noreply.github.com> Date: Tue, 9 May 2023 17:53:23 +0100 Subject: [PATCH] Check that all rules have descriptions (#4315) --- .../rules/function_call_argument_default.rs | 2 +- .../rules/reuse_of_groupby_generator.rs | 2 +- .../rules/unnecessary_list_call.rs | 2 +- .../rules/unnecessary_list_comprehension_dict.rs | 2 +- .../rules/unnecessary_list_comprehension_set.rs | 2 +- .../rules/unnecessary_literal_dict.rs | 2 +- .../rules/unnecessary_literal_set.rs | 2 +- .../rules/unnecessary_literal_within_dict_call.rs | 2 +- .../rules/unnecessary_literal_within_list_call.rs | 2 +- .../rules/unnecessary_literal_within_tuple_call.rs | 2 +- .../rules/unnecessary_subscript_reversal.rs | 2 +- .../rules/unordered_body_content_in_model.rs | 2 +- .../rules/mutable_defaults_in_dataclass_fields.rs | 4 ++-- scripts/check_docs_formatted.py | 11 +++++++++++ 14 files changed, 25 insertions(+), 14 deletions(-) diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs index 55343a345f..bdc1a1b43d 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs @@ -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. diff --git a/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs b/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs index 3e53f7d205..c6622737d5 100644 --- a/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs +++ b/crates/ruff/src/rules/flake8_bugbear/rules/reuse_of_groupby_generator.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 066791f4e7..ef978a8c10 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -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 diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index 08882b27a0..9a350298e6 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index a47e044f80..89489406fd 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index 6d0002034b..826967fb95 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -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 (`{}`). /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 366788adbd..0f8a57793e 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index f97dcc6914..c225e8aeb7 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -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`. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index e76c96b6f2..f0eed3dcc1 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index eb3b2bb4a3..0e99bc30fb 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -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. /// diff --git a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs index 26a66120dd..16493ec3f7 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_subscript_reversal.rs @@ -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. diff --git a/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs b/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs index f09996c5e7..dc10ad5b45 100644 --- a/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs +++ b/crates/ruff/src/rules/flake8_django/rules/unordered_body_content_in_model.rs @@ -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: /// diff --git a/crates/ruff/src/rules/ruff/rules/mutable_defaults_in_dataclass_fields.rs b/crates/ruff/src/rules/ruff/rules/mutable_defaults_in_dataclass_fields.rs index 628326ad6b..cacb2238e5 100644 --- a/crates/ruff/src/rules/ruff/rules/mutable_defaults_in_dataclass_fields.rs +++ b/crates/ruff/src/rules/ruff/rules/mutable_defaults_in_dataclass_fields.rs @@ -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. /// diff --git a/scripts/check_docs_formatted.py b/scripts/check_docs_formatted.py index 49c7741aa4..b6e5c0d213 100755 --- a/scripts/check_docs_formatted.py +++ b/scripts/check_docs_formatted.py @@ -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") :]