mirror of https://github.com/astral-sh/ruff
Expand target name for better rule documentation (#9302)
This commit is contained in:
parent
465f835cf9
commit
5d5f56d563
|
|
@ -38,8 +38,8 @@ use crate::importer::{ImportRequest, Importer};
|
|||
/// ## References
|
||||
#[violation]
|
||||
pub struct ReimplementedOperator {
|
||||
target: &'static str,
|
||||
operator: &'static str,
|
||||
target: FunctionLikeKind,
|
||||
}
|
||||
|
||||
impl Violation for ReimplementedOperator {
|
||||
|
|
@ -48,7 +48,14 @@ impl Violation for ReimplementedOperator {
|
|||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ReimplementedOperator { operator, target } = self;
|
||||
format!("Use `operator.{operator}` instead of defining a {target}")
|
||||
match target {
|
||||
FunctionLikeKind::Function => {
|
||||
format!("Use `operator.{operator}` instead of defining a function")
|
||||
}
|
||||
FunctionLikeKind::Lambda => {
|
||||
format!("Use `operator.{operator}` instead of defining a lambda")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
@ -129,10 +136,10 @@ impl FunctionLike<'_> {
|
|||
}
|
||||
|
||||
/// Return the display kind of the function-like node.
|
||||
fn kind(&self) -> &'static str {
|
||||
fn kind(&self) -> FunctionLikeKind {
|
||||
match self {
|
||||
Self::Lambda(_) => "lambda",
|
||||
Self::Function(_) => "function",
|
||||
Self::Lambda(_) => FunctionLikeKind::Lambda,
|
||||
Self::Function(_) => FunctionLikeKind::Function,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,6 +178,12 @@ fn get_operator(expr: &Expr, params: &ast::Parameters) -> Option<&'static str> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum FunctionLikeKind {
|
||||
Lambda,
|
||||
Function,
|
||||
}
|
||||
|
||||
/// Return the name of the `operator` implemented by the given unary expression.
|
||||
fn unary_op(expr: &ast::ExprUnaryOp, params: &ast::Parameters) -> Option<&'static str> {
|
||||
let [arg] = params.args.as_slice() else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue