Skip to content

Commit

Permalink
Document flake8-unused-arguments (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
calumy authored Apr 29, 2023
1 parent 8f61eae commit 39ed75f
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions crates/ruff/src/rules/flake8_unused_arguments/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 39ed75f

Please sign in to comment.