Skip to content

Commit

Permalink
Fix: checking right-side of default value assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
erindepew committed Oct 17, 2017
1 parent 3d0af1f commit b0c134e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/rules/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ module.exports = {
// e.g.: const { no_camelcased = false } = bar;
} else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {

if (node.parent.parent.type === "ObjectPattern") {
node.parent.parent.properties.forEach(property => {
if (property.value.right && property.value.right.type === "Identifier" && isUnderscored(property.value.right.name)) {
report(node);
}
});
}

// "never" check properties
if (properties === "never") {
return;
Expand Down
53 changes: 45 additions & 8 deletions tests/lib/rules/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ ruleTester.run("camelcase", rule, {
},
{
code: "const { no_camelcased } = bar;",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "const { no_camelcased = false } = bar;",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo({ no_camelcased }) {};",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo({ no_camelcased = 'default value' }) {};",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "function foo({ no_camelcased: camelCased }) {};",
Expand Down Expand Up @@ -355,6 +355,43 @@ ruleTester.run("camelcase", rule, {
type: "Identifier"
}
]
},
{
code: " const no_camelcased = 0; function foo({ camelcased_value = no_camelcased}) {}",
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'no_camelcased' is not in camel case.",
type: "Identifier"
},
{
message: "Identifier 'camelcased_value' is not in camel case.",
type: "Identifier"
}
]
},
{
code: "const { bar: no_camelcased } = foo;",
options: [{ properties: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'no_camelcased' is not in camel case.",
type: "Identifier"
}
]
},
{
code: "function foo({ value_1: my_default }) {}",
options: [{ properties: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'my_default' is not in camel case.",
type: "Identifier"
}
]
}
]
});

0 comments on commit b0c134e

Please sign in to comment.