Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document flake8-unused-arguments #4147

Merged
merged 7 commits into from
Apr 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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