Skip to content

Commit

Permalink
fix: false positive in camelcase with combined options
Browse files Browse the repository at this point in the history
Fixes #15572
  • Loading branch information
snitin315 committed Feb 6, 2022
1 parent 355b23d commit 3ba9883
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/camelcase.js
Expand Up @@ -161,7 +161,7 @@ module.exports = {
switch (parent.type) {
case "Property":
return (
parent.parent.type === "ObjectPattern" &&
(parent.parent.type === "ObjectPattern" || parent.parent.type === "ObjectExpression") &&
parent.value === valueNode &&
!parent.computed &&
parent.key.type === "Identifier" &&
Expand Down Expand Up @@ -311,6 +311,7 @@ module.exports = {
* It looks unnecessary because declarations are reported.
*/
for (const reference of variable.references) {

if (reference.init) {
continue; // Skip the write references of initializers.
}
Expand Down
49 changes: 49 additions & 0 deletions tests/lib/rules/camelcase.js
Expand Up @@ -407,6 +407,35 @@ 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 foo = ({ some_property }) => {
console.log(some_property)
};
function bar({ some_property }) {
console.log(some_property)
};
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [{ messageId: "notCamelCase", data: { name: "some_property" } }]
},

// https://github.com/eslint/eslint/issues/15572
{
code: `
const { some_property } = obj;
doSomething({ some_property });
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [{ messageId: "notCamelCase", data: { name: "some_property" } }]
}
],
invalid: [
Expand Down Expand Up @@ -1416,6 +1445,26 @@ 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" } }]
},
{
code: `
const { some_property } = obj;
doSomething({ [some_property]: "bar" });
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [{ messageId: "notCamelCase", data: { name: "some_property" } }]
}
]
});

0 comments on commit 3ba9883

Please sign in to comment.