Skip to content

linter: unicorn/explicit-length-check doesn't consider optional properties #23480

Description

@elusiveunit

What version of Oxlint are you using?

1.70.0

What command did you run?

oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

export default defineConfig({
	plugins: ['unicorn'],
	options: {
		typeAware: true,
	},
	rules: {
		'unicorn/explicit-length-check': 'warn',
	},
});

What happened?

test.ts

interface Thing {
	list?: number[];
}
const foo: Thing = {};
const hasList = Boolean(foo.list?.length);

Output from npx oxlint:

  ⚠ unicorn(explicit-length-check): Use `.length > 0` when checking length is not zero.
   ╭─[test.ts:5:25]
 4 │ const foo: Thing = {};
 5 │ const hasList = Boolean(foo.list?.length);
   ·                         ────────────────
   ╰────
  help: Replace `foo.list?.length` with `foo.list?.length > 0`.

The suggested replacement is not valid: 'foo.list.length' is possibly 'undefined'. ts(18048).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions