Skip to content

Commit

Permalink
fix(linter): rule no-constant-binary-expression do not look into `g…
Browse files Browse the repository at this point in the history
…lobals` (#9145)
  • Loading branch information
Sysix committed Feb 15, 2025
1 parent 97cc1c8 commit 490c77d
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ impl NoConstantBinaryExpression {
Expression::CallExpression(call_expr) => {
if let Expression::Identifier(ident) = &call_expr.callee {
return ["Boolean", "String", "Number"].contains(&ident.name.as_str())
&& ctx.is_reference_to_global_variable(ident);
&& ctx
.scopes()
.root_unresolved_references()
.contains_key(ident.name.as_str());
}
false
}
Expand Down Expand Up @@ -291,13 +294,16 @@ impl NoConstantBinaryExpression {
},
Expression::CallExpression(call_expr) => {
if let Expression::Identifier(ident) = &call_expr.callee {
if ident.name == "String"
|| ident.name == "Number" && ctx.is_reference_to_global_variable(ident)
let unresolved_references = ctx.scopes().root_unresolved_references();
if (ident.name == "String" || ident.name == "Number")
&& unresolved_references.contains_key(ident.name.as_str())
{
return true;
}

if ident.name == "Boolean" && ctx.is_reference_to_global_variable(ident) {
if ident.name == "Boolean"
&& unresolved_references.contains_key(ident.name.as_str())
{
return call_expr
.arguments
.iter()
Expand Down Expand Up @@ -339,7 +345,10 @@ impl NoConstantBinaryExpression {
Expression::NewExpression(call_expr) => {
if let Expression::Identifier(ident) = &call_expr.callee {
return ctx.env_contains_var(ident.name.as_str())
&& ctx.is_reference_to_global_variable(ident);
&& ctx
.scopes()
.root_unresolved_references()
.contains_key(ident.name.as_str());
}
false
}
Expand Down

0 comments on commit 490c77d

Please sign in to comment.