Skip to content

Commit f1f69ef

Browse files
authored
Merge pull request #2589 from esbena/js/ignore-duplicate-params-for-empty-functions
Approved by erik-krogh
2 parents 9b361f1 + 9279bfc commit f1f69ef

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
| **Query** | **Expected impact** | **Change** |
2727
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
2828
| Clear-text logging of sensitive information (`js/clear-text-logging`) | More results | More results involving `process.env` and indirect calls to logging methods are recognized. |
29+
| Duplicate parameter names (`js/duplicate-parameter-name`) | Fewer results | This query now recognizes additional parameters that reasonably can have duplicated names. |
2930
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false positive results | This query now recognizes additional cases where a single replacement is likely to be intentional. |
3031
| Unbound event handler receiver (`js/unbound-event-handler-receiver`) | Fewer false positive results | This query now recognizes additional ways event handler receivers can be bound. |
3132
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations. |

javascript/ql/src/Declarations/UniqueParameterNames.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ where
3636
i < j and
3737
j = max(int k | parmBinds(f, k, _, name) | k) and
3838
not isDummy(p) and
39+
// ignore functions without bodies or empty bodies
40+
f.hasBody() and
41+
exists(f.getABodyStmt()) and
3942
// duplicate parameters in strict mode functions are flagged by the 'Syntax error' rule
4043
not f.isStrict()
4144
select p, "This parameter has the same name as $@ of the same function.", q, "another parameter"

javascript/ql/test/query-tests/Declarations/UniqueParameterNames/tst.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function f(
22
x,
33
x, // NOT OK
44
\u0078 // NOT OK
5-
) {}
5+
) { return; }
66

77
this.addPropertyListener(prop.name, function(_, _, _, a) {
88
proxy.delegate = a.dao;
@@ -12,3 +12,10 @@ this.addPropertyListener(prop.name, function(_, _, _, a) {
1212
function f(x, y, x) {
1313
'use strict';
1414
}
15+
16+
function f(
17+
x,
18+
x // OK: empty function
19+
) { }
20+
21+
(a, a) => a + a; // OK: for strict mode functions, duplicate parameter names are a syntax error
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
| arrows.js:1:5:1:5 | Error: Argument name clash | Error: Argument name clash |
12
| tst.js:2:12:2:12 | Error: Unterminated string constant | Error: Unterminated string constant |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(a, a) => a + a;

0 commit comments

Comments
 (0)