mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(linter): replace ast "compare by hash" to "compare by content" (#5602)
relates #5600
This commit is contained in:
parent
20d006838e
commit
4e748b5930
2 changed files with 6 additions and 6 deletions
|
|
@ -4,10 +4,11 @@ use oxc_ast::{
|
|||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::cmp::ContentEq;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_syntax::operator::LogicalOperator;
|
||||
|
||||
use crate::{ast_util::calculate_hash, context::LintContext, rule::Rule, AstNode};
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
|
||||
fn no_dupe_else_if_diagnostic(first_test: Span, second_test: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::warn("duplicate conditions in if-else-if chains")
|
||||
|
|
@ -154,7 +155,7 @@ fn is_equal<'a, 'b>(a: &'a Expression<'b>, b: &'a Expression<'b>) -> bool {
|
|||
|| (is_equal(&a.left, &b.right) && is_equal(&a.right, &b.left))
|
||||
}
|
||||
|
||||
(a, b) => calculate_hash(a) == calculate_hash(b),
|
||||
(a, b) => a.content_eq(b),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::cmp::ContentEq;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
|
||||
use crate::{ast_util::calculate_hash, context::LintContext, rule::Rule, AstNode};
|
||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||
|
||||
fn no_self_compare_diagnostic(span: Span, span1: Span) -> OxcDiagnostic {
|
||||
OxcDiagnostic::warn("Disallow comparisons where both sides are exactly the same")
|
||||
|
|
@ -44,10 +45,8 @@ impl Rule for NoSelfCompare {
|
|||
if !binary_expr.operator.is_compare() && !binary_expr.operator.is_equality() {
|
||||
return;
|
||||
}
|
||||
let left = calculate_hash(&binary_expr.left);
|
||||
let right = calculate_hash(&binary_expr.right);
|
||||
|
||||
if left == right {
|
||||
if binary_expr.left.content_eq(&binary_expr.right) {
|
||||
ctx.diagnostic(no_self_compare_diagnostic(
|
||||
binary_expr.left.span(),
|
||||
binary_expr.right.span(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue