sindresorhus/eslint-plugin-unicorn

Rule proposal: `prefer-map-has`

Closed

#1,329 opened on Jun 3, 2021

 (8 comments) (5 reactions) (0 assignees)JavaScript (468 forks)user submission
help wantednew ruletypes

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

When checking existence, should prefer Map#has() over Map#get().

Fail

if (map.get(foo));

Pass

if (map.has(foo));

I think better ship this with prefer-map together, so user can notice this problem when we fix object.foo to map.get(foo) in prefer-map.

Contributor guide