From 127f524337f92dd72d36e71e646c91c9715ad444 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 6 Jan 2022 20:00:33 +0530 Subject: [PATCH] feat: false negative with `property` option in `id-match` (#15474) Fixes #15443 --- lib/rules/id-match.js | 2 +- tests/lib/rules/id-match.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index 977e66a26ad..8713a5f9f8b 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -250,7 +250,7 @@ module.exports = { } // never check properties or always ignore destructuring - if (!checkProperties || (ignoreDestructuring && isInsideObjectPattern(node))) { + if ((!checkProperties && !parent.computed) || (ignoreDestructuring && isInsideObjectPattern(node))) { return; } diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js index de66d8b8d55..7e469bd4d5b 100644 --- a/tests/lib/rules/id-match.js +++ b/tests/lib/rules/id-match.js @@ -894,6 +894,26 @@ ruleTester.run("id-match", rule, { type: "Identifier" } ] + }, + + // https://github.com/eslint/eslint/issues/15443 + { + code: ` + const foo = { + [a]: 1, + }; + `, + options: ["^[^a]", { + properties: false, + onlyDeclarations: false + }], + parserOptions: { ecmaVersion: 2022 }, + errors: [ + { + message: "Identifier 'a' does not match the pattern '^[^a]'.", + type: "Identifier" + } + ] } ] });