diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index e4761466902..6bb1838a72e 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -146,7 +146,7 @@ module.exports = { /** * Checks if a given binding identifier uses the original name as-is. - * - If it's in object destructuring or object expression, the original name is its property name. + * - If it's in object destructuring, the original name is its property name. * - If it's in import declaration, the original name is its exported name. * @param {ASTNode} node The `Identifier` node to check. * @returns {boolean} `true` if the identifier uses the original name as-is. @@ -161,7 +161,7 @@ module.exports = { switch (parent.type) { case "Property": return ( - (parent.parent.type === "ObjectPattern" || parent.parent.type === "ObjectExpression") && + parent.parent.type === "ObjectPattern" && parent.value === valueNode && !parent.computed && parent.key.type === "Identifier" && diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 79c237ce202..3a47a1b4b2d 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -407,35 +407,6 @@ ruleTester.run("camelcase", rule, { code: "class C { snake_case; #snake_case; #snake_case2() {} }", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 2022 } - }, - - // Combinations of `properties` and `ignoreDestructring` - { - code: ` - const { some_property } = obj; - - const bar = { some_property }; - - obj.some_property = 10; - - const xyz = { some_property: obj.some_property }; - - const foo = ({ some_property }) => { - console.log(some_property) - }; - `, - options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 } - }, - - // https://github.com/eslint/eslint/issues/15572 - { - code: ` - const { some_property } = obj; - doSomething({ some_property }); - `, - options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 } } ], invalid: [ @@ -1445,78 +1416,6 @@ ruleTester.run("camelcase", rule, { options: [{ properties: "always" }], parserOptions: { ecmaVersion: 2022 }, errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }] - }, - - // Combinations of `properties` and `ignoreDestructring` - { - code: ` - const { some_property } = obj; - doSomething({ some_property }); - `, - options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [ - { - messageId: "notCamelCase", - data: { name: "some_property" }, - line: 3, - column: 27 - } - ] - }, - { - code: ` - const { some_property } = obj; - doSomething({ some_property }); - doSomething({ [some_property]: "bar" }); - `, - options: [{ properties: "never", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [ - { - messageId: "notCamelCase", - data: { name: "some_property" }, - line: 4, - column: 28 - } - ] - }, - { - code: ` - const { some_property } = obj; - - const bar = { some_property }; - - obj.some_property = 10; - - const xyz = { some_property: obj.some_property }; - - const foo = ({ some_property }) => { - console.log(some_property) - }; - `, - options: [{ properties: "always", ignoreDestructuring: true }], - parserOptions: { ecmaVersion: 2022 }, - errors: [ - { - messageId: "notCamelCase", - data: { name: "some_property" }, - line: 4, - column: 27 - }, - { - messageId: "notCamelCase", - data: { name: "some_property" }, - line: 6, - column: 17 - }, - { - messageId: "notCamelCase", - data: { name: "some_property" }, - line: 8, - column: 27 - } - ] } ] });