Merge pull request #3166 from erik-krogh/DeadLocal

Approved by asgerf
This commit is contained in:
semmle-qlci 2020-04-03 09:36:20 +01:00 коммит произвёл GitHub
Родитель 604731ba6b 45797dc729
Коммит dc774e0eac
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 19 добавлений и 8 удалений

Просмотреть файл

@ -63,8 +63,10 @@ where
(
// To avoid confusion about the meaning of "definition" and "declaration" we avoid
// the term "definition" when the alert location is a variable declaration.
if dead instanceof VariableDeclarator
if
dead instanceof VariableDeclarator and
not exists(SsaImplicitInit init | init.getVariable().getSourceVariable() = v) // the variable is dead at the hoisted implicit initialization.
then msg = "The initial value of " + v.getName() + " is unused, since it is always overwritten."
else msg = "This definition of " + v.getName() + " is useless, since its value is never read."
else msg = "The value assigned to " + v.getName() + " here is unused."
)
select dead, msg

Просмотреть файл

@ -1,12 +1,13 @@
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
| overload.ts:10:12:10:14 | baz | The value assigned to baz here is unused. |
| tst2.js:26:9:26:14 | x = 23 | The initial value of x is unused, since it is always overwritten. |
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |
| tst3.js:2:1:2:36 | exports ... a: 23 } | This definition of exports is useless, since its value is never read. |
| tst3b.js:2:18:2:36 | exports = { a: 23 } | This definition of exports is useless, since its value is never read. |
| tst.js:6:2:6:7 | y = 23 | This definition of y is useless, since its value is never read. |
| tst2.js:28:9:28:14 | x = 42 | The value assigned to x here is unused. |
| tst3.js:2:1:2:36 | exports ... a: 23 } | The value assigned to exports here is unused. |
| tst3b.js:2:18:2:36 | exports = { a: 23 } | The value assigned to exports here is unused. |
| tst.js:6:2:6:7 | y = 23 | The value assigned to y here is unused. |
| tst.js:13:6:13:11 | a = 23 | The initial value of a is unused, since it is always overwritten. |
| tst.js:13:14:13:19 | a = 42 | This definition of a is useless, since its value is never read. |
| tst.js:13:14:13:19 | a = 42 | The value assigned to a here is unused. |
| tst.js:45:6:45:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
| tst.js:51:6:51:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
| tst.js:132:7:132:13 | {x} = o | The initial value of x is unused, since it is always overwritten. |
| tst.js:162:6:162:14 | [x] = [0] | The initial value of x is unused, since it is always overwritten. |
| tst.js:172:7:172:17 | nSign = foo | The value assigned to nSign here is unused. |

Просмотреть файл

@ -166,3 +166,11 @@ function v() {
x;
y;
});
(function() {
if (something()) {
var nSign = foo;
} else {
console.log(nSign);
}
})()