New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add to UNUSED_EXTERNAL_IMPORT
warning information about the origin of the problem
#4054
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,11 +110,27 @@ export default class ExternalModule { | |||||||||||||||||||||||||||||
.map(name => `'${name}'`) | ||||||||||||||||||||||||||||||
.join(', ')} and '${unused.slice(-1)}' are`; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const importersSet = new Set<string>() | ||||||||||||||||||||||||||||||
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) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let importerList = '' | ||||||||||||||||||||||||||||||
if (importersArray.length > 0) { | ||||||||||||||||||||||||||||||
cawa-93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how appropriate to use Lines 9 to 22 in a4a3b8a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the other usages, sources should be reasonable. |
||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the types, these checks should not be needed. This is also reflected in the coverage right now. Or do you see a scenario where there might be an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During my previous experiments there was a situation when
dynamicImporters
wasundefined
. I assume that the types are not quite correct. Therefore, for reinsurance, I added a check.