From c88200f50c547519f06f3532602b07a0a053df85 Mon Sep 17 00:00:00 2001 From: Tom Kuson Date: Tue, 19 Sep 2023 15:41:09 +0100 Subject: [PATCH] Add documentation --- .../flake8_pyi/rules/non_empty_stub_body.rs | 21 +++++++++++++++++++ scripts/check_docs_formatted.py | 1 + 2 files changed, 22 insertions(+) diff --git a/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs b/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs index 2432df8faf79f..86f2a42ae8b71 100644 --- a/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs +++ b/crates/ruff/src/rules/flake8_pyi/rules/non_empty_stub_body.rs @@ -7,6 +7,27 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; use crate::registry::Rule; +/// ## What it does +/// Checks for non-empty function stub bodies. +/// +/// ## Why is this bad? +/// Stub files are meant to be used as a reference for the interface of a +/// module, and should not contain any implementation details. Thus, the +/// body of a stub function should be empty. +/// +/// ## Example +/// ```python +/// def double(x: int) -> int: +/// return x * 2 +/// ``` +/// +/// Use instead: +/// ```python +/// def double(x: int) -> int: ... +/// ``` +/// +/// ## References +/// - [PEP 484 – Type Hints: Stub Files](https://www.python.org/dev/peps/pep-0484/#stub-files) #[violation] pub struct NonEmptyStubBody; diff --git a/scripts/check_docs_formatted.py b/scripts/check_docs_formatted.py index f08723eb5ba51..bc6f93010cafa 100755 --- a/scripts/check_docs_formatted.py +++ b/scripts/check_docs_formatted.py @@ -57,6 +57,7 @@ "no-indented-block-comment", "no-space-after-block-comment", "no-space-after-inline-comment", + "non-empty-stub-body", "one-blank-line-after-class", "over-indentation", "over-indented",