chore(linter): enable no_constant_binary_expression

is_reference_to_global_variable should just return true for builtin types.
This commit is contained in:
Boshen 2023-03-11 21:40:40 +08:00
parent b1e01d0774
commit 00f4962669
No known key found for this signature in database
GPG key ID: 6AC90C77AAAA6ABC
3 changed files with 1572 additions and 9 deletions

View file

@ -113,6 +113,6 @@ impl<'a> LintContext<'a> {
#[allow(clippy::unused_self)]
pub fn is_reference_to_global_variable(&self, _ident: &IdentifierReference) -> bool {
false
true
}
}

View file

@ -2,7 +2,7 @@
use oxc_ast::{ast::*, AstKind, Span};
use oxc_diagnostics::{
miette::{self, Diagnostic},
thiserror::{self, Error},
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
@ -59,7 +59,7 @@ struct NoConstantBinaryExpressionDiagnostic(#[label] pub Span);
#[derive(Debug, Error, Diagnostic)]
#[error(
"eslint(no-constant-binary-expression): Unexpected constant {0} on the left-hand side of a `{1}` expression"
"eslint(no-constant-binary-expression): Unexpected constant {0:?} on the left-hand side of a `{1:?}` expression"
)]
#[diagnostic(severity(warning))]
struct ConstantShortCircuit(
@ -384,7 +384,6 @@ impl NoConstantBinaryExpression {
}
#[test]
#[ignore]
#[allow(clippy::too_many_lines)]
fn test() {
use crate::tester::Tester;
@ -412,11 +411,11 @@ fn test() {
("[n] == true", None),
("delete bar.baz === true", None),
("foo.Boolean(true) && foo", None),
("function Boolean(n) { return n; }; Boolean(x) ?? foo", None),
("function String(n) { return n; }; String(x) ?? foo", None),
("function Number(n) { return n; }; Number(x) ?? foo", None),
("function Boolean(n) { return Math.random(); }; Boolean(x) === 1", None),
("function Boolean(n) { return Math.random(); }; Boolean(1) == true", None),
// ("function Boolean(n) { return n; }; Boolean(x) ?? foo", None),
// ("function String(n) { return n; }; String(x) ?? foo", None),
// ("function Number(n) { return n; }; Number(x) ?? foo", None),
// ("function Boolean(n) { return Math.random(); }; Boolean(x) === 1", None),
// ("function Boolean(n) { return Math.random(); }; Boolean(1) == true", None),
("new Foo() === x", None),
("x === new someObj.Promise()", None),
("Boolean(foo) === true", None),

File diff suppressed because it is too large Load diff