import-js / eslint-plugin-import

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

Proposal: Warn on importing from a filename for which a directory also exists #919

Open msikma opened 7 years ago

msikma commented 7 years ago

For example, let's say I have the following files:

| something/
|-- index.js
| something.js
| main.js

Inside main.js, I have the following code:

import { helpfulFunction } from './something';

// do something with helpfulFunction()

This is a little dangerous, because did I mean ./something or ./something/? I don't think code should be split up like this—in this case, I would take the contents of something.js and move them to something/index.js and just import from there. A warning would be helpful to track down cases like this.

jwarby commented 5 months ago

This would also be great for cases where you originally had Foo.js but decided to break it up into a folder like Foo/index.js, Foo/bar.js but forgot to remove the original file.

One of our devs had a case like this recently but fortunately we got a rough pointer to the issue because we use knip too, which told us the Foo/* files were unused - it still took a little while for us to realise what had actually happened though (originally thought knip was giving us a false positive), so a rule in this plugin to catch this scenario feels like it'd be a good fit for the plugin and a useful feature!