diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index 0b81685625a..f7faeacede3 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -110,11 +110,24 @@ export default class ExternalModule { .map(name => `'${name}'`) .join(', ')} and '${unused.slice(-1)}' are`; + const importersSet = new Set(); + for (const name of unused) { + const {importers, dynamicImporters} = this.declarations[name].module; + + if (Array.isArray(importers)) importers.forEach(v => importersSet.add(v)); + if (Array.isArray(dynamicImporters)) dynamicImporters.forEach(v => importersSet.add(v)); + } + + const importersArray = Array.from(importersSet); + + const importerList = ' in' + importersArray.map(s => `\n\t${s};`); + this.options.onwarn({ code: 'UNUSED_EXTERNAL_IMPORT', - message: `${names} imported from external module '${this.id}' but never used`, + message: `${names} imported from external module '${this.id}' but never used${importerList}`, names: unused, - source: this.id + source: this.id, + sources: importersArray }); } } diff --git a/test/function/samples/unused-import/_config.js b/test/function/samples/unused-import/_config.js index 4d9d8219063..2961ff4fe62 100644 --- a/test/function/samples/unused-import/_config.js +++ b/test/function/samples/unused-import/_config.js @@ -1,3 +1,5 @@ +const path = require('path'); + module.exports = { description: 'warns on unused imports ([#595])', options: { @@ -13,7 +15,10 @@ module.exports = { code: 'UNUSED_EXTERNAL_IMPORT', source: 'external', names: ['notused', 'neverused'], - message: `'notused' and 'neverused' are imported from external module 'external' but never used` + message: `'notused' and 'neverused' are imported from external module 'external' but never used in\n\t${path.resolve(__dirname, './main.js')};`, + sources: [ + path.resolve(__dirname, './main.js') + ] } ] };