Skip to content

Commit

Permalink
Fix: handle destructuring with defaults in camelcase rule (fixes esli…
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbal authored and erindepew committed Nov 30, 2017
1 parent 58216b6 commit 09b4e09
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/rules/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ module.exports = {
report(node);
}

// Properties have their own rules
} else if (node.parent.type === "Property") {
// Properties have their own rules, and
// AssignmentPattern nodes can be treated like Properties:
// e.g.: const { no_camelcased = false } = bar;
} else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {

// "never" check properties
if (properties === "never") {
Expand Down
54 changes: 54 additions & 0 deletions tests/lib/rules/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ ruleTester.run("camelcase", rule, {
{
code: "import { no_camelcased as camelCased, anoterCamelCased } from \"external-module\";",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: "const { no_camelcased } = bar;",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
},
{
code: "const { no_camelcased = false } = bar;",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
},
{
code: "function foo({ no_camelcased }) {};",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
},
{
code: "function foo({ no_camelcased = 'default value' }) {};",
parserOptions: { ecmaVersion: 6 },
options: [{ properties: "never" }]
},
{
code: "function foo({ no_camelcased: camelCased }) {};",
parserOptions: { ecmaVersion: 6 }
}
],
invalid: [
Expand Down Expand Up @@ -212,6 +236,16 @@ ruleTester.run("camelcase", rule, {
}
]
},
{
code: "var { category_id = 1 } = query;",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'category_id' is not in camel case.",
type: "Identifier"
}
]
},
{
code: "import no_camelcased from \"external-module\";",
parserOptions: { ecmaVersion: 6, sourceType: "module" },
Expand Down Expand Up @@ -301,6 +335,26 @@ ruleTester.run("camelcase", rule, {
type: "Identifier"
}
]
},
{
code: "function foo({ no_camelcased }) {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'no_camelcased' is not in camel case.",
type: "Identifier"
}
]
},
{
code: "function foo({ no_camelcased = 'default value' }) {};",
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "Identifier 'no_camelcased' is not in camel case.",
type: "Identifier"
}
]
}
]
});

0 comments on commit 09b4e09

Please sign in to comment.