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.
Disallow duplicate adjacent branches in if chains.
Prefer early continues over conditionals wrapping the remainder of the loop body.
Disallow break and optionally continue in nested loops and switches inside loops.
Prefer else if over adjacent if statements with related conditions.