# no-collection-size-mischeck

Rule `sonarjs/no-collection-size-mischeck`. Collection size and array length comparisons should make sense

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
if (someSet.size >= 0) {...} // Noncompliant

if (someMap.size < 0) {...} // Noncompliant

const result = someArray.length >= 0;  // Noncompliant
```

### Correct: the rule accepts this

```js
if (someSet.size > 0) {...}

if (someMap.size == 0) {...}

const result = someArray.length > 0;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-collection-size-mischeck": "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-code-after-done](https://lintradar.dev/rules/sonarjs/no-code-after-done.md): Tests should not execute any code after "done()" is called
- [sonarjs/no-control-regex](https://lintradar.dev/rules/sonarjs/no-control-regex.md): Regular expressions should not contain control characters
- [sonarjs/no-clear-text-protocols](https://lintradar.dev/rules/sonarjs/no-clear-text-protocols.md): Clear-text protocols should not be used
- [sonarjs/no-dead-store](https://lintradar.dev/rules/sonarjs/no-dead-store.md): Unused assignments should be removed
- [sonarjs/no-case-label-in-switch](https://lintradar.dev/rules/sonarjs/no-case-label-in-switch.md): "switch" statements should not contain non-case labels
- [sonarjs/no-debounce-throttle-in-render](https://lintradar.dev/rules/sonarjs/no-debounce-throttle-in-render.md): Lodash and Underscore.js debounced or throttled functions should not be recreated on every React render

---

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