sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`unicorn/explicit-length-check` does not report when optional chaining

troywoy opened this issue · comments

When an optional chain is involved, such as data?.length, the code is not correctly flagged by unicorn/explicit-length-check.

// Does not error with "Use `.length > 0` when checking length is not zero.eslint(unicorn/explicit-length-check)"
if (data?.length) {
  ...
}

Issue was previously discussed here: #1263

codesandbox reproduction: https://codesandbox.io/p/devbox/h45722?file=%2Fsrc%2Findex.tsx%3A9%2C18