Skip to content

Commit acee34f

Browse files
author
Esben Sparre Andreasen
committed
fixup! JS: make js/unused-local-variable flag import statements
1 parent bf3eadc commit acee34f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

javascript/ql/src/Declarations/UnusedVariable.ql

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ class ImportVarDeclProvider extends Stmt {
123123
result = this.(ImportDeclaration).getASpecifier().getLocal() or
124124
result = this.(ImportEqualsDeclaration).getId()
125125
}
126+
127+
/**
128+
* Gets an unacceptable unused variable declared by this import.
129+
*/
130+
UnusedLocal getAnUnacceptableUnusedLocal() {
131+
result = getAVarDecl().getVariable() and
132+
not whitelisted(result)
133+
}
134+
126135
}
127136

128137
/**
@@ -167,17 +176,13 @@ predicate unusedNonImports(VarDecl vd, string msg) {
167176
*/
168177
predicate unusedImports(ImportVarDeclProvider provider, string msg) {
169178
exists (string plural, string names |
170-
names = concat(UnusedLocal v |
171-
v = provider.getAVarDecl().getVariable() and
172-
not whitelisted(v) |
179+
names = strictconcat(UnusedLocal v |
180+
v = provider.getAnUnacceptableUnusedLocal() |
173181
v.getName(),
174182
", " order by v.getName()
175183
) and
176-
not names = "" and
177184
(
178-
if count(UnusedLocal v |
179-
v = provider.getAVarDecl().getVariable() and
180-
not whitelisted(v)) > 1 then
185+
if count(provider.getAnUnacceptableUnusedLocal()) > 1 then
181186
plural = "s"
182187
else
183188
plural = ""

0 commit comments

Comments
 (0)