-
Notifications
You must be signed in to change notification settings - Fork 888
New rule: no-duplicate-imports #2869
Comments
[new-rule] `no-duplicate-imports` Fixes: #2869
Why should this cause a linting error? If they're impossible to merge then that's not an error. |
@chances can you provide examples when they cannot be merged? In most cases it may be causes by copy/paste or bugs in auto-imports. |
That's a quote from my PR. Here the example: import foo from 'foo';
import foo2 from 'foo'; // cannot be combined with preceding import
import * as bar from 'bar';
import {baz} from 'bar'; // cannot be combined with preceding import If you find something like that in your code, it should be refactored anyway. |
@ajafff, how is it recommended to refactor those cases? Right now I have a case where I need both It seems like it'd make more sense for non-fixable instances to be treated by the rule as valid. |
Cases mentioned above looks like lazy copy/paste. Both cases can be normalized with hands and I don't see reason to leave them as separate imports. @buu700 if |
As mentioned, I need to use both
Not the end of the world, but in this case I'm not sure it's obvious that the rule helped more than harmed. |
You could use a local alias: import * as bar from 'bar';
import baz = bar.baz; |
Yeah, I considered that as well, but I think the version of this that triggers the error still isn't obviously worse than any of the alternatives. Usually when a lint rule fails there's a direct or recommended fix that's a clear improvement, but in this case it seems like all the possible workarounds are just to avoid triggering it on a technicality. Maybe this could be allowed via an option similar to |
[new-rule] `no-duplicate-imports` Fixes: palantir#2869
Are there any plans to implement autofix for this rule? |
@GabeAtWork no, but only because nobody has filed a issue asking for it. Good idea! We should discuss in a separate issue in case their are off edge cases to hammer out. |
Just like http://eslint.org/docs/rules/no-duplicate-imports
bad:
good:
The text was updated successfully, but these errors were encountered: