# no-globals-shadowing

Rule `sonarjs/no-globals-shadowing`. Special identifiers should not be bound or assigned

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1274 by reach, #575 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-globals-shadowing` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2137/) |

## Code examples

### Incorrect: the rule reports this

```js
eval = 17; // Noncompliant
arguments++; // Noncompliant
++eval; // Noncompliant
var obj = { set p(arguments) { } }; // Noncompliant
var eval; // Noncompliant
try { } catch (arguments) { } // Noncompliant
function x(eval) { } // Noncompliant
function arguments() { } // Noncompliant
var y = function eval() { }; // Noncompliant
var f = new Function("arguments", "return 17;"); // Noncompliant

function fun() {
  if (arguments.length == 0) { // Compliant
    // do something
  }
}
```

### Correct: the rule accepts this

```js
result = 17;
args++;
++result;
var obj = { set p(arg) { } };
var result;
try { } catch (args) { }
function x(arg) { }
function args() { }
var y = function fun() { };
var f = new Function("args", "return 17;");

function fun() {
  if (arguments.length == 0) {
    // do something
  }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-globals-shadowing": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-global-this](https://lintradar.dev/rules/sonarjs/no-global-this.md): The global "this" object should not be used
- [sonarjs/no-gratuitous-expressions](https://lintradar.dev/rules/sonarjs/no-gratuitous-expressions.md): Boolean expressions should not be gratuitous
- [sonarjs/no-forced-browser-interaction](https://lintradar.dev/rules/sonarjs/no-forced-browser-interaction.md): Forced browser interactions should not bypass actionability checks
- [sonarjs/no-hardcoded-ip](https://lintradar.dev/rules/sonarjs/no-hardcoded-ip.md): IP addresses should not be hardcoded
- [sonarjs/no-floating-point-equality](https://lintradar.dev/rules/sonarjs/no-floating-point-equality.md): Floating point numbers should not be tested for equality
- [sonarjs/no-hardcoded-passwords](https://lintradar.dev/rules/sonarjs/no-hardcoded-passwords.md): Credentials should not be hard-coded

---

Web page: https://lintradar.dev/rules/sonarjs/no-globals-shadowing. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
