# no-impossible-length-comparison

Rule `unicorn/no-impossible-length-comparison`. Disallow impossible comparisons against `.length` or `.size`.

- Source: unicorn
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #926 by reach, #1181 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-impossible-length-comparison` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-impossible-length-comparison.md) |

## Code examples

### Incorrect: the rule reports this

```js
if (array.length < 0) {}
```

```js
if (string.length === -1) {}
```

```js
if (set.size <= -1) {}
```

### Correct: the rule accepts this

```js
if (array.length === 0) {}
```

```js
if (array.length > 0) {}
```

```js
if (set.size >= 1) {}
```

Examples from the ESLint documentation.

## Enable it

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

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-impossible-length-comparison": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-global-object-property-assignment](https://lintradar.dev/rules/unicorn/no-global-object-property-assignment.md): Disallow assigning properties on the global object.
- [unicorn/no-incomplete-accessor-override](https://lintradar.dev/rules/unicorn/no-incomplete-accessor-override.md): Disallow class accessors that hide an inherited getter or setter.
- [unicorn/no-exports-in-scripts](https://lintradar.dev/rules/unicorn/no-exports-in-scripts.md): Disallow exports in scripts.
- [unicorn/no-ineffective-csp-directives](https://lintradar.dev/rules/unicorn/no-ineffective-csp-directives.md): Disallow ineffective CSP directives in `<meta>` elements.
- [unicorn/no-error-property-assignment](https://lintradar.dev/rules/unicorn/no-error-property-assignment.md): Disallow assigning to built-in error properties.
- [unicorn/no-invalid-boolean-attribute-value](https://lintradar.dev/rules/unicorn/no-invalid-boolean-attribute-value.md): Disallow invalid values for HTML boolean attributes.

---

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