Skip to content

Commit 05d5093

Browse files
committed
Added duplicate import checking to no-reassign.
I would expect no-redeclare to catch this more generally, but it seems not to with ESLint 0.17.1.
1 parent 4008082 commit 05d5093

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/rules/no-reassign.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ module.exports = function (context) {
1717

1818
return {
1919
"ImportSpecifier": function (node) {
20+
checkIdentifier(node.local);
2021
locals.add(node.local.name);
2122
},
2223

2324
"ImportDefaultSpecifier": function (node) {
25+
checkIdentifier(node.local);
2426
locals.add(node.local.name);
2527
},
2628

2729
"ImportNamespaceSpecifier": function (node) {
30+
checkIdentifier(node.local);
2831
locals.add(node.local.name);
2932
namespaces.add(node.local.name);
3033
},

tests/lib/rules/no-reassign.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,20 @@ eslintTester.addRuleTest("lib/rules/no-reassign", {
4242
code: "import { foo } from './bar';\nvar bar = 32, foo = function() { return false; }",
4343
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),
4444

45+
test({
46+
code: "import { foo } from './bar';\nimport { foo } from './common';",
47+
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),
48+
49+
test({
50+
code: "import { foo } from './bar';\nimport foo from './common';",
51+
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),
52+
53+
test({
54+
code: "import { foo } from './bar';\nimport * as foo from './common';",
55+
errors: [{ message: "Reassignment of local imported name 'foo'." }]}),
56+
4557
test({
4658
code: "import * as foo from './bar'; foo.x = 'y';",
47-
errors: [{ message: "Assignment to member of namespace 'foo'."}]
48-
})
59+
errors: [{ message: "Assignment to member of namespace 'foo'."}]})
4960
]
5061
});

0 commit comments

Comments
 (0)