Skip to content

Commit

Permalink
Remove pylint::helpers::CmpOpExt (#13189)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Sep 1, 2024
1 parent bf620dc commit d3b6e8f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
32 changes: 1 addition & 31 deletions crates/ruff_linter/src/rules/pylint/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt;

use ruff_python_ast as ast;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{visitor, Arguments, CmpOp, Expr, Stmt};
use ruff_python_ast::{visitor, Arguments, Expr, Stmt};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::{ScopeKind, SemanticModel};
use ruff_text_size::TextRange;
Expand Down Expand Up @@ -57,34 +55,6 @@ pub(super) fn in_dunder_method(
true
}

/// A wrapper around [`CmpOp`] that implements `Display`.
#[derive(Debug)]
pub(super) struct CmpOpExt(CmpOp);

impl From<&CmpOp> for CmpOpExt {
fn from(cmp_op: &CmpOp) -> Self {
CmpOpExt(*cmp_op)
}
}

impl fmt::Display for CmpOpExt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let representation = match self.0 {
CmpOp::Eq => "==",
CmpOp::NotEq => "!=",
CmpOp::Lt => "<",
CmpOp::LtE => "<=",
CmpOp::Gt => ">",
CmpOp::GtE => ">=",
CmpOp::Is => "is",
CmpOp::IsNot => "is not",
CmpOp::In => "in",
CmpOp::NotIn => "not in",
};
write!(f, "{representation}")
}
}

/// Visitor to track reads from an iterable in a loop.
#[derive(Debug)]
pub(crate) struct SequenceIndexVisitor<'a> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::rules::pylint::helpers::CmpOpExt;

/// ## What it does
/// Checks for comparisons between constants.
Expand Down Expand Up @@ -45,8 +44,7 @@ impl Violation for ComparisonOfConstant {
} = self;

format!(
"Two constants compared in a comparison, consider replacing `{left_constant} {} {right_constant}`",
CmpOpExt::from(op)
"Two constants compared in a comparison, consider replacing `{left_constant} {op} {right_constant}`",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ruff_python_ast::{CmpOp, Expr};
use ruff_text_size::Ranged;

use crate::checkers::ast::Checker;
use crate::rules::pylint::helpers::CmpOpExt;

/// ## What it does
/// Checks for operations that compare a name to itself.
Expand Down Expand Up @@ -66,7 +65,7 @@ pub(crate) fn comparison_with_itself(
let actual = format!(
"{} {} {}",
checker.locator().slice(left),
CmpOpExt::from(op),
op,
checker.locator().slice(right)
);
checker.diagnostics.push(Diagnostic::new(
Expand Down Expand Up @@ -114,7 +113,7 @@ pub(crate) fn comparison_with_itself(
let actual = format!(
"{} {} {}",
checker.locator().slice(left),
CmpOpExt::from(op),
op,
checker.locator().slice(right)
);
checker.diagnostics.push(Diagnostic::new(
Expand Down

0 comments on commit d3b6e8f

Please sign in to comment.