From 39ed75f6434e16ba5cda0d8a05b97c120f6b1f0e Mon Sep 17 00:00:00 2001 From: Calum Young <32770960+calumy@users.noreply.github.com> Date: Sat, 29 Apr 2023 20:17:50 +0100 Subject: [PATCH] Document `flake8-unused-arguments` (#4147) --- .../rules/flake8_unused_arguments/rules.rs | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/crates/ruff/src/rules/flake8_unused_arguments/rules.rs b/crates/ruff/src/rules/flake8_unused_arguments/rules.rs index f67b362775..ae2f505a2d 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/rules.rs +++ b/crates/ruff/src/rules/flake8_unused_arguments/rules.rs @@ -16,6 +16,24 @@ use crate::checkers::ast::Checker; use super::helpers; use super::types::Argumentable; +/// ## What it does +/// Checks for the presence of unused arguments in function definitions. +/// +/// ## Why is this bad? +/// An argument that is defined but not used is likely a mistake, and should +/// be removed to avoid confusion. +/// +/// ## Example +/// ```python +/// def foo(bar, baz): +/// return bar * 2 +/// ``` +/// +/// Use instead: +/// ```python +/// def foo(bar): +/// return bar * 2 +/// ``` #[violation] pub struct UnusedFunctionArgument { pub name: String, @@ -29,6 +47,25 @@ impl Violation for UnusedFunctionArgument { } } +/// ## What it does +/// Checks for the presence of unused arguments in instance method definitions. +/// +/// ## Why is this bad? +/// An argument that is defined but not used is likely a mistake, and should +/// be removed to avoid confusion. +/// +/// ## Example +/// ```python +/// class MyClass: +/// def my_method(self, arg1, arg2): +/// print(arg1) +/// ``` +/// +/// Use instead: +/// ```python +/// class MyClass: +/// def my_method(self, arg1): +/// ``` #[violation] pub struct UnusedMethodArgument { pub name: String, @@ -42,6 +79,34 @@ impl Violation for UnusedMethodArgument { } } +/// ## What it does +/// Checks for the presence of unused arguments in class method definitions. +/// +/// ## Why is this bad? +/// An argument that is defined but not used is likely a mistake, and should +/// be removed to avoid confusion. +/// +/// ## Example +/// ```python +/// class MyClass: +/// @classmethod +/// def my_method(self, arg1, arg2): +/// print(arg1) +/// +/// def other_method(self): +/// self.my_method("foo", "bar") +/// ``` +/// +/// Use instead: +/// ```python +/// class MyClass: +/// @classmethod +/// def my_method(self, arg1): +/// print(arg1) +/// +/// def other_method(self): +/// self.my_method("foo", "bar") +/// ``` #[violation] pub struct UnusedClassMethodArgument { pub name: String, @@ -55,6 +120,34 @@ impl Violation for UnusedClassMethodArgument { } } +/// ## What it does +/// Checks for the presence of unused arguments in static method definitions. +/// +/// ## Why is this bad? +/// An argument that is defined but not used is likely a mistake, and should +/// be removed to avoid confusion. +/// +/// ## Example +/// ```python +/// class MyClass: +/// @staticmethod +/// def my_static_method(self, arg1, arg2): +/// print(arg1) +/// +/// def other_method(self): +/// self.my_static_method("foo", "bar") +/// ``` +/// +/// Use instead: +/// ```python +/// class MyClass: +/// @static +/// def my_static_method(self, arg1): +/// print(arg1) +/// +/// def other_method(self): +/// self.my_static_method("foo", "bar") +/// ``` #[violation] pub struct UnusedStaticMethodArgument { pub name: String, @@ -68,6 +161,25 @@ impl Violation for UnusedStaticMethodArgument { } } +/// ## What it does +/// Checks for the presence of unused arguments in lambda expression +/// definitions. +/// +/// ## Why is this bad? +/// An argument that is defined but not used is likely a mistake, and should +/// be removed to avoid confusion. +/// +/// ## Example +/// ```python +/// my_list = [1, 2, 3, 4, 5] +/// squares = map(lambda x, y: x**2, my_list) +/// ``` +/// +/// Use instead: +/// ```python +/// my_list = [1, 2, 3, 4, 5] +/// squares = map(lambda x: x**2, my_list) +/// ``` #[violation] pub struct UnusedLambdaArgument { pub name: String,