When unusedExports option is used, exports that are imported with absolute paths are falsely reported as unused.
With settings:
"settings": {
"import/resolver": {
"node": {
"paths": ["src"]
}
}
}
the following should not return any linting errors:
// src/module.js
import submodule from 'submodule';
submodule();
// src/submodule.js
const submodule = () => console.log();
export default submodule;
but the submodule export is unused according to this plugin. The export is not marked as unused if the import statement is relative:
import submodule from './submodule';
(Note that an absolute path starts with /, what you're describing is a bare specifier)
The issue, I think, is that src here is not what the resolver requires: https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/node which is indeed an absolute path, starting with /. This feature isn't meant to let you do alias requires, it's meant to mimic the (long deprecated) NODE_PATH environment variable.
Outside of eslint, how are you making these specifiers resolve?
Thank you for the reply, it seems to have solved my issue. I have gotten the above settings config from some blog post and it indeed works with import/no-unresolved but not with import/no-unused-modules.
What ultimately fixed the resolving for import/no-unused-modules was changing the settings to following:
``json
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": ["node_modules", "src"]
}
}
}
````
If this is the intended usage of thesettings` it could be useful to have some references to this in the rule documentations as there seems to be some misinformation floating about in the blogosphere.
When it comes to resolving outside of eslint, it is done with webpack in this project.
In that case, you should use the webpack resolver, not just the node resolver (and then not include "src" in the node resolver at all)
That, of course, would be the best option in this case and after testing the webpack resolver it worked as intended. I will close this issue as it was only based on misunderstanding of the settings.