Skip to content

Commit

Permalink
fix(linter): rule prefer-object-spreads do not look into globals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Feb 15, 2025
1 parent 9214661 commit 6d15153
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/oxc_linter/src/rules/eslint/prefer_object_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,21 @@ impl Rule for PreferObjectSpread {
return;
};

let unresolved_references = ctx.scopes().root_unresolved_references();

match callee.object().get_inner_expression() {
Expression::Identifier(ident) => {
if ident.name != "Object" || !ctx.is_reference_to_global_variable(ident) {
if ident.name != "Object"
|| !unresolved_references.contains_key(ident.name.as_str())
{
return;
}
}
Expression::StaticMemberExpression(member_expr) => {
if let Expression::Identifier(ident) = member_expr.object.get_inner_expression() {
if ident.name != "globalThis" || !ctx.is_reference_to_global_variable(ident) {
if ident.name != "globalThis"
|| !unresolved_references.contains_key(ident.name.as_str())
{
return;
}
} else {
Expand Down

0 comments on commit 6d15153

Please sign in to comment.