Skip to content

Commit 653c900

Browse files
authored
Merge pull request github#4987 from erik-krogh/defensiveFunctions
Approved by esbena
2 parents 209fe8d + c51e951 commit 653c900

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The query "Unneeded defensive code" (`js/unneeded-defensive-code`) no longer flags uses of function parameters.

javascript/ql/src/Expressions/UnneededDefensiveProgramming.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ where
5151
or
5252
// too benign in practice
5353
e instanceof DefensiveExpressionTest::DefensiveInit
54+
or
55+
// functions might be written overly general
56+
e.getALocalSource() instanceof DataFlow::ParameterNode
5457
)
5558
select e, "This guard always evaluates to " + cv + "."

javascript/ql/test/query-tests/Expressions/UnneededDefensiveProgramming/tst.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,11 @@
176176
u && (u.p, f()); // technically not OK, but it seems like an unlikely pattern
177177
u && !u.p; // NOT OK
178178
u && !u(); // NOT OK
179+
180+
181+
function hasCallbacks(success, error) {
182+
if (success) success()
183+
if (error) error()
184+
}
185+
hasCallbacks(() => {}, null);
179186
});

0 commit comments

Comments
 (0)