Skip to content

linter: no-restricted-globals: false positive when file has both global and local variable with the same name #20807

@ahmedelgabri

Description

@ahmedelgabri

What version of Oxlint are you using?

1.57.0

What command did you run?

oxlint -c .oxlintrc.json

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "rules": {
    "eslint/no-restricted-globals": ["error", {"name": "location", "message": "Use router."}]
  }
}

What happened?

no-restricted-globals incorrectly flags a local variable when the same file also contains an unresolved global reference with the same name.

The rule checks root_unresolved_references().contains_key(&ident.name) which matches by name (string), not by specific ReferenceId. So if any reference named location is unresolved (the global), all references named location get flagged -- including correctly resolved local variables.

Minimal reproduction

Bug case -- oxlint reports 2 errors, ESLint reports 1 error:

const globalPath = location.pathname // global (should be flagged)

function test(history: {location: {pathname: string}}) {
  const {location} = history
  return location.pathname // local (should NOT be flagged) -- false positive
}
export {test, globalPath}

Clean case -- removing the global reference, oxlint correctly reports 0 errors:

function test(history: {location: {pathname: string}}) {
  const {location} = history
  return location.pathname // correctly NOT flagged
}
export {test}

Expected behavior

Only location on line 1 should be flagged (unresolved global reference). The destructured const {location} = history on line 4 creates a local binding -- references to it on line 5 should not be flagged.

ESLint handles this correctly.

Root cause

In no_restricted_globals.rs line 97:

if ctx.scoping().root_unresolved_references().contains_key(&ident.name) {

This checks if any reference with the name "location" is unresolved, not whether this specific IdentifierReference is unresolved.

Environment

  • oxlint 1.57.0
  • Tested on macOS, Node 24.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions