import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.48k stars 1.56k forks source link

Rule proposal: no-duplicate-named #598

Open jfmengels opened 7 years ago

jfmengels commented 7 years ago

I just noticed the the following is considered to be valid syntax by both espree and babel-eslint.

import {a, a, b as a, c as a} from 'foo';

We should add a rule that forbids:

To discuss:

I'm pretty sure we had a rule to forbid import {b as a} from 'foo' when a is also a named export of that module, but I don't remember which one. If we don't, let me know, and I'll create an issue, because that sounds like a nice style issue to have. That might fill the role of the last to discuss item?

I propose the name no-duplicate-named, but I'm open to better names :)

ntdb commented 7 years ago

I might take a crack at this.

no-named-as-default seems to be the closest existing rule to the one you're describing. It prevents the use of a named export's name when importing the default export. Docs. Perhaps that rule could be generalized for the case you're describing?

jfmengels commented 7 years ago

That'd be great @ntdb! Just wait on a :+1: from @benmosher maybe?

Yes, no-named-as-default is very close. I think we can copy most of the logic inside it, but it should be a separate rule, as it would be an unwarranted breaking change IMO (an the name would be misleading).

ljharb commented 6 years ago

@ntdb any chance you'd be able to still make this PR?