unicorn/prefer-has-check
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-has-check": "error",
},
},
];if (map.get(key)) {
// …
}map.get(key) !== undefined;new Map([[key, {}]]).get(key) !== undefined;if (map.has(key)) {
// …
}map.has(key);new Map([[key, {}]]).has(key);Examples from the ESLint documentation.
unicorn/prefer-has-check
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-has-check": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer global numeric constants over Number static properties.
Prefer identifiers over string literals in import and export specifiers.
Prefer escape sequences for irregular whitespace characters.
Prefer passing iterables directly to constructors instead of filling empty collections.
Prefer early returns over conditionals wrapping the remainder of the function body.
Prefer iterator helpers over temporary arrays from iterators.