Feature Request: Auto-detection of side-effect only modules in no-unassigned-imports
#1,313 opened on Mar 31, 2019
Repository metrics
- Stars
- (4,946 stars)
- PR merge metrics
- (Avg merge 138d 22h) (3 merged PRs in 30d)
Description
I'd like to request that no-unassigned-imports have the ability to scan import targets and ignore any which do not export anything. I have a number of custom elements which are side-effects only and have no default or named exports. Example:
customElements.define('my-element', class extends HTMLElement {
/* constructor, methods, properties of `<my-element>` go here */
});
Right now for web projects I simply disable import/no-unassigned-imports, it would be nice if I could let it run with an option to allow all non-exporting modules yet still throw an error if import './something-that-exports.js'; is found.
I'm not very experienced with eslint plugins but I'm willing to try implementing if you would accept the feature (full testing will be included). It looks like I should be able to use ExportMap to determine if the module being imported has any ESM exports. Probably this auto-detect functionality needs to be enabled by an option so import './cjs-module-that-exports.js'; will still report errors by default? The option would be for use in 'pure ESM' projects (initially anyways, maybe it can be expanded later to support scanning for CJS exports).