# no-useless-length-check

Disallow length checks duplicated by the guarded array operation

`every` returns true for an empty array, and `some` returns false.
Separate length guards duplicate these results.
Instead, you SHOULD use the array operation directly.

- Category: suspicious
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function allPositive(values: int32[]): boolean {
    return values.length === 0 || values.every((value) => value > 0);
}
```

## Accepted

```ds title="main.ds"
function allPositive(values: int32[]): boolean {
    return values.every((value) => value > 0);
}
```

## Prior art

- [eslint-plugin-unicorn · no-useless-length-check](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-length-check.md)

[language/linter/src/rules/suspicious/no_useless_length_check.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_useless_length_check.rs#L8)
