# no-primitive-wrappers

Rule `sonarjs/no-primitive-wrappers`. Wrapper objects should not be used for primitive types

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1305 by reach, #606 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
let x = new Number("0");
if (x) {
  alert('hi');  // Shows 'hi'.
}
```

### Correct: the rule accepts this

```js
let x = Number("0");
if (x) {
  alert('hi');
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-primitive-wrappers": "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-parameter-reassignment](https://lintradar.dev/rules/sonarjs/no-parameter-reassignment.md): Initial values of parameters, caught exceptions, and loop variables should not be ignored
- [sonarjs/no-redundant-assignments](https://lintradar.dev/rules/sonarjs/no-redundant-assignments.md): Assignments should not be redundant
- [sonarjs/no-os-command-from-path](https://lintradar.dev/rules/sonarjs/no-os-command-from-path.md): OS commands should not rely on PATH resolution
- [sonarjs/no-redundant-boolean](https://lintradar.dev/rules/sonarjs/no-redundant-boolean.md): Boolean literals should not be used in comparisons
- [sonarjs/no-nested-functions](https://lintradar.dev/rules/sonarjs/no-nested-functions.md): Functions should not be nested too deeply
- [sonarjs/no-redundant-jump](https://lintradar.dev/rules/sonarjs/no-redundant-jump.md): Jump statements should not be redundant

---

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