Skip to content

Commit

Permalink
fix: false negative with onlyDeclarations in id-match
Browse files Browse the repository at this point in the history
Fixes #15123
  • Loading branch information
snitin315 committed Dec 16, 2021
1 parent 981fb48 commit 10215e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/rules/id-match.js
Expand Up @@ -238,6 +238,13 @@ module.exports = {
}
}

// For https://github.com/eslint/eslint/issues/15123
if (parent.parent && parent.parent.type === "ObjectExpression") {
if (checkProperties && parent.key === node && isInvalid(name)) {
report(node);
}
}

// never check properties or always ignore destructuring
if (!checkProperties || (ignoreDestructuring && isInsideObjectPattern(node))) {
return;
Expand Down
27 changes: 26 additions & 1 deletion tests/lib/rules/id-match.js
Expand Up @@ -774,7 +774,32 @@ ruleTester.run("id-match", rule, {
type: "PrivateIdentifier"
}
]
}
},

// https://github.com/eslint/eslint/issues/15123
{
code: `
const foo = {
foo_one: 1,
bar_one: 2,
fooBar: 3
};
`,
options: ["^[^_]+$", {
properties: true,
onlyDeclarations: true
}],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
message: "Identifier 'foo_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
},
{
message: "Identifier 'bar_one' does not match the pattern '^[^_]+$'.",
type: "Identifier"
}
]
}
]
});

0 comments on commit 10215e6

Please sign in to comment.