Feature Request: Auto-detection of side-effect only modules in no-unassigned-imports
#1313 aperta il 31 mar 2019
Metriche repository
- Star
- (4946 star)
- Metriche merge PR
- (Merge medio 138g 22h) (3 PR mergiate in 30 g)
Descrizione
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).