Skip to content

Commit

Permalink
Added duplicate import checking to no-reassign.
Browse files Browse the repository at this point in the history
I would expect no-redeclare to catch this more generally, but it seems not to with ESLint 0.17.1.
  • Loading branch information
benmosher committed Mar 25, 2015
1 parent 4008082 commit 05d5093
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/rules/no-reassign.js
Expand Up @@ -17,14 +17,17 @@ module.exports = function (context) {

return {
"ImportSpecifier": function (node) {
checkIdentifier(node.local);
locals.add(node.local.name);
},

"ImportDefaultSpecifier": function (node) {
checkIdentifier(node.local);
locals.add(node.local.name);
},

"ImportNamespaceSpecifier": function (node) {
checkIdentifier(node.local);
locals.add(node.local.name);
namespaces.add(node.local.name);
},
Expand Down
15 changes: 13 additions & 2 deletions tests/lib/rules/no-reassign.js
Expand Up @@ -42,9 +42,20 @@ eslintTester.addRuleTest("lib/rules/no-reassign", {
code: "import { foo } from './bar';\nvar bar = 32, foo = function() { return false; }",
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),

test({
code: "import { foo } from './bar';\nimport { foo } from './common';",
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),

test({
code: "import { foo } from './bar';\nimport foo from './common';",
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),

test({
code: "import { foo } from './bar';\nimport * as foo from './common';",
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),

test({
code: "import * as foo from './bar'; foo.x = 'y';",
errors: [{ message: "Assignment to member of namespace 'foo'."}]
})
errors: [{ message: "Assignment to member of namespace 'foo'."}]})
]
});

0 comments on commit 05d5093

Please sign in to comment.