Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check destructuring for "no-shadow-restricted-names" (fixes #10467) #10470

Merged
merged 4 commits into from Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rules/no-shadow-restricted-names.js
Expand Up @@ -44,7 +44,13 @@ module.exports = {

return {
VariableDeclarator(node) {
checkForViolation(node.id);
if (node.id.type === "Identifier") {
checkForViolation(node.id);
} else if (node.id.type === "ArrayPattern") {
node.id.elements.map(checkForViolation);
} else if (node.id.type === "ObjectPattern") {
node.id.properties.map(prop => checkForViolation(prop.value));
}
},
ArrowFunctionExpression(node) {
[].map.call(node.params, checkForViolation);
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/no-shadow-restricted-names.js
Expand Up @@ -89,6 +89,21 @@ ruleTester.run("no-shadow-restricted-names", rule, {
{ message: "Shadowing of global property 'eval'.", type: "Identifier" },
{ message: "Shadowing of global property 'eval'.", type: "Identifier" }
]
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add some more tests like:

var undefined = "foo";
var foo = bar, undefined = bar;

Copy link
Member Author

@g-plane g-plane Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between the existing tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, my apologies! I didn't notice it was already there!

{
code: "var [undefined] = [1]",
parserOptions: { ecmaVersion: 6 },
errors: [
{ message: "Shadowing of global property 'undefined'.", type: "Identifier" }
]
},
{
code: "var {undefined} = obj; var {foo: undefined} = obj;",
parserOptions: { ecmaVersion: 6 },
errors: [
{ message: "Shadowing of global property 'undefined'.", type: "Identifier" },
{ message: "Shadowing of global property 'undefined'.", type: "Identifier" }
]
}
]
});