Skip to content

Commit

Permalink
refactor(eqeqeq) rename eq_eq_eq to eqeqeq (#1151)
Browse files Browse the repository at this point in the history
From #1146

---------

Co-authored-by: Boshen <boshenc@gmail.com>
  • Loading branch information
camc314 and Boshen committed Nov 5, 2023
1 parent 28a9574 commit b81d79b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod deepscan {
mod eslint {
pub mod array_callback_return;
pub mod constructor_super;
pub mod eq_eq_eq;
pub mod eqeqeq;
pub mod for_direction;
pub mod getter_return;
pub mod no_array_constructor;
Expand Down Expand Up @@ -174,7 +174,7 @@ oxc_macros::declare_all_lint_rules! {
deepscan::uninvoked_array_callback,
eslint::array_callback_return,
eslint::constructor_super,
eslint::eq_eq_eq,
eslint::eqeqeq,
eslint::for_direction,
eslint::getter_return,
eslint::no_array_constructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use crate::{context::LintContext, fixer::Fix, rule::Rule, AstNode};
#[derive(Debug, Error, Diagnostic)]
#[error("eslint(eqeqeq): Expected {1} and instead saw {0}")]
#[diagnostic(severity(warning), help("Prefer {1} operator"))]
struct EqEqEqDiagnostic(&'static str, &'static str, #[label] pub Span);
struct EqeqeqDiagnostic(&'static str, &'static str, #[label] pub Span);

#[derive(Debug, Default, Clone)]
pub struct EqEqEq {
pub struct Eqeqeq {
compare_type: CompareType,
null_type: NullType,
}
Expand All @@ -36,11 +36,11 @@ declare_oxc_lint!(
/// let b = false
/// a == b
/// ```
EqEqEq,
Eqeqeq,
pedantic
);

impl Rule for EqEqEq {
impl Rule for Eqeqeq {
fn from_configuration(value: serde_json::Value) -> Self {
let obj1 = value.get(0);
let obj2 = value.get(1);
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Rule for EqEqEq {
// There are some uncontrolled cases to auto fix.
// In ESlint, `null >= null` will be auto fixed to `null > null` which is also wrong.
// So I just report it.
ctx.diagnostic(EqEqEqDiagnostic(
ctx.diagnostic(EqeqeqDiagnostic(
operator,
&operator[0..operator.len() - 1],
binary_expr.span,
Expand Down Expand Up @@ -104,15 +104,15 @@ impl Rule for EqEqEq {
// If the comparison is a `typeof` comparison or both sides are literals with the same type, then it's safe to fix.
if is_type_of_binary_bool || are_literals_and_same_type_bool {
ctx.diagnostic_with_fix(
EqEqEqDiagnostic(operator, preferred_operator, binary_expr.span),
EqeqeqDiagnostic(operator, preferred_operator, binary_expr.span),
|| {
let start = binary_expr.left.span().end;
let end = binary_expr.right.span().start;
Fix::new(preferred_operator_with_padding, Span { start, end })
},
);
} else {
ctx.diagnostic(EqEqEqDiagnostic(operator, preferred_operator, binary_expr.span));
ctx.diagnostic(EqeqeqDiagnostic(operator, preferred_operator, binary_expr.span));
}
}
}
Expand Down Expand Up @@ -237,5 +237,5 @@ fn test() {
("a == b", "a == b", None),
];

Tester::new(EqEqEq::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Tester::new(Eqeqeq::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
---
source: crates/oxc_linter/src/tester.rs
expression: eq_eq_eq
expression: eqeqeq
---
eslint(eqeqeq): Expected > and instead saw >=
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1null >= 1
· ─────────
╰────
help: Prefer > operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1typeof foo == 'undefined'
· ─────────────────────────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected !== and instead saw !=
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1'hello' != 'world'
· ──────────────────
╰────
help: Prefer !== operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
10 == 0
· ──────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1true == true
· ────────────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1foo == null
· ───────────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1a == b
· ──────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1foo == true
· ───────────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected !== and instead saw !=
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1bananas != 1
· ────────────
╰────
help: Prefer !== operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1value == undefined
· ──────────────────
╰────
help: Prefer === operator

eslint(eqeqeq): Expected === and instead saw ==
╭─[eq_eq_eq.tsx:1:1]
╭─[eqeqeq.tsx:1:1]
1null == null
· ────────────
╰────
Expand Down

0 comments on commit b81d79b

Please sign in to comment.