unicorn/no-mismatched-map-key
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-mismatched-map-key": "error",
},
},
];Disallow checking a Map key before accessing a different key.
const value = map.has(key) ? map.get(anotherKey) : fallback;if (!map.has(key)) {
map.set(anotherKey, value);
}const value = map.has(key) ? map.get(key) : fallback;if (!map.has(key)) {
map.set(key, value);
}Examples from the ESLint documentation.
unicorn/no-mismatched-map-key
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-mismatched-map-key": "error",
},
},
];Oxlint does not have this rule.
nursery/noMismatchedMapKey
nursery · since 2.6.5
{
"linter": {
"rules": {
"nursery": {
"noMismatchedMapKey": "error"
}
}
}
}Do not use a for loop that can be replaced with a for-of loop.
Disallow simple recursive function calls that can be replaced with a loop.
Enforce consistent labels on tuple type elements.
Prefer early continues over conditionals wrapping the remainder of the loop body.
Enforce consistent JSON file reads before JSON.parse().
Prefer Iterator.zip() over parallel-array indexing.