mirror of https://github.com/astral-sh/ruff
Move compare to helpers file (#2131)
From discussion on https://github.com/charliermarsh/ruff/pull/2123 I didn't originally have a helpers file so I put the function in both places but now that a helpers file exists it seems logical for it to be there.
This commit is contained in:
parent
d645a19e0a
commit
ff63da9f52
|
|
@ -1,3 +1,19 @@
|
||||||
|
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
||||||
|
|
||||||
|
use crate::ast::helpers::{create_expr, unparse_expr};
|
||||||
|
use crate::source_code::Stylist;
|
||||||
|
|
||||||
pub fn is_ambiguous_name(name: &str) -> bool {
|
pub fn is_ambiguous_name(name: &str) -> bool {
|
||||||
name == "l" || name == "I" || name == "O"
|
name == "l" || name == "I" || name == "O"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
|
||||||
|
unparse_expr(
|
||||||
|
&create_expr(ExprKind::Compare {
|
||||||
|
left: Box::new(left.clone()),
|
||||||
|
ops: ops.to_vec(),
|
||||||
|
comparators: comparators.to_vec(),
|
||||||
|
}),
|
||||||
|
stylist,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,11 @@ use rustpython_ast::Constant;
|
||||||
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
||||||
|
|
||||||
use crate::ast::helpers;
|
use crate::ast::helpers;
|
||||||
use crate::ast::helpers::{create_expr, unparse_expr};
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::fix::Fix;
|
use crate::fix::Fix;
|
||||||
use crate::registry::Diagnostic;
|
use crate::registry::Diagnostic;
|
||||||
use crate::source_code::Stylist;
|
use crate::rules::pycodestyle::helpers::compare;
|
||||||
use crate::violations;
|
use crate::violations;
|
||||||
|
|
||||||
/// E711, E712
|
/// E711, E712
|
||||||
|
|
@ -193,14 +192,3 @@ pub fn literal_comparisons(
|
||||||
|
|
||||||
checker.diagnostics.extend(diagnostics);
|
checker.diagnostics.extend(diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
|
|
||||||
unparse_expr(
|
|
||||||
&create_expr(ExprKind::Compare {
|
|
||||||
left: Box::new(left.clone()),
|
|
||||||
ops: ops.to_vec(),
|
|
||||||
comparators: comparators.to_vec(),
|
|
||||||
}),
|
|
||||||
stylist,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
use rustpython_ast::Unaryop;
|
use rustpython_ast::Unaryop;
|
||||||
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
||||||
|
|
||||||
use crate::ast::helpers::{create_expr, unparse_expr};
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::fix::Fix;
|
use crate::fix::Fix;
|
||||||
use crate::registry::Diagnostic;
|
use crate::registry::Diagnostic;
|
||||||
use crate::source_code::Stylist;
|
use crate::rules::pycodestyle::helpers::compare;
|
||||||
use crate::violations;
|
use crate::violations;
|
||||||
|
|
||||||
/// E713, E714
|
/// E713, E714
|
||||||
|
|
@ -67,14 +66,3 @@ pub fn not_tests(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare(left: &Expr, ops: &[Cmpop], comparators: &[Expr], stylist: &Stylist) -> String {
|
|
||||||
unparse_expr(
|
|
||||||
&create_expr(ExprKind::Compare {
|
|
||||||
left: Box::new(left.clone()),
|
|
||||||
ops: ops.to_vec(),
|
|
||||||
comparators: comparators.to_vec(),
|
|
||||||
}),
|
|
||||||
stylist,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue