Skip to content

False positives: local variables/parameters matching browser API names are flagged #688

@Akshay090

Description

@Akshay090

Problem

The compat/compat rule produces false positives when local variable or parameter names happen to collide with browser API names. Two related issues:

1. Arrow function / function expression parameters not recognized as local declarations

The Identifier visitor tracks locally declared names to suppress false positives when a name shadows a browser global. However, it only checks these parent node types: Property, FunctionDeclaration, VariableDeclarator, ClassDeclaration, ImportDefaultSpecifier, ImportSpecifier, ImportDeclaration.

Missing: ArrowFunctionExpression and FunctionExpression.

This means callback parameters that share a name with a browser API are flagged:

// Flagged as "scheduler is not supported in Safari 26.2"
// but 'scheduler' here is a domain object, not Window.scheduler
schedulers.map(scheduler => scheduler.name);

// Same issue with function expressions
items.map(function(fetch) { return fetch.toString(); });

2. Early-return guard pattern not recognized as feature detection

The existing isInsideIfStatement check only suppresses errors for API usage inside an if block. The common early-return guard pattern is not detected:

function setup() {
  if (!('serviceWorker' in navigator)) {
    return; // early exit if API unavailable
  }
  // This usage is safe but still flagged:
  navigator.serviceWorker.register('/sw.js');
}

Impact

In a large codebase, these false positives can produce dozens of spurious errors, particularly when domain entities share names with newer browser APIs (e.g. scheduler matching the Prioritized Task Scheduling API Window.scheduler).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions