Skip to content

Commit 60d990e

Browse files
committed
Revert "JS: Accept regressions for UnneededDefensiveProgramming"
This reverts commit 57d6d74.
1 parent d6a39ad commit 60d990e

File tree

3 files changed

+67
-67
lines changed

3 files changed

+67
-67
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ function getDate() {
66
return null;
77
}
88
console.log(date);
9-
return date && date.getTime();
9+
return date && date.getTime(); // $ Alert
1010
}
1111

1212
function isNotNullOrString(obj) {
13-
return obj != null && obj != undefined &&
14-
typeof obj != 'string';
13+
return obj != null && obj != undefined && // $ Alert
14+
typeof obj != 'string';
1515
}

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

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,95 +10,95 @@
1010
var o_ = o;
1111
var x_ = x;
1212

13-
u_ = u_ || e; // $ MISSING: Alert
14-
n_ = n_ || e; // $ MISSING: Alert
15-
o_ = o_ || e; // $ MISSING: Alert
13+
u_ = u_ || e; // $ Alert
14+
n_ = n_ || e; // $ Alert
15+
o_ = o_ || e; // $ Alert
1616
x_ = x_ || e;
1717

18-
u && u.p; // $ MISSING: Alert
19-
n && n.p; // $ MISSING: Alert
20-
o && o.p; // $ MISSING: Alert
18+
u && u.p; // $ Alert
19+
n && n.p; // $ Alert
20+
o && o.p; // $ Alert
2121
x && x.p;
2222

23-
u && u(); // $ MISSING: Alert
24-
n && n(); // $ MISSING: Alert
25-
o && o(); // $ MISSING: Alert
23+
u && u(); // $ Alert
24+
n && n(); // $ Alert
25+
o && o(); // $ Alert
2626
x && x();
2727

28-
!u || u.p; // $ MISSING: Alert
29-
!n || n.p; // $ MISSING: Alert
30-
!o || o.p; // $ MISSING: Alert
28+
!u || u.p; // $ Alert
29+
!n || n.p; // $ Alert
30+
!o || o.p; // $ Alert
3131
!x || x.p;
3232

33-
!!u && u.p; // $ MISSING: Alert
34-
!!n && n.p; // $ MISSING: Alert
35-
!!o && o.p; // $ MISSING: Alert
33+
!!u && u.p; // $ Alert
34+
!!n && n.p; // $ Alert
35+
!!o && o.p; // $ Alert
3636
!!x && x.p;
3737

38-
u != undefined && u.p; // $ MISSING: Alert
39-
n != undefined && n.p; // $ MISSING: Alert
40-
o != undefined && o.p; // $ MISSING: Alert
38+
u != undefined && u.p; // $ Alert
39+
n != undefined && n.p; // $ Alert
40+
o != undefined && o.p; // $ Alert
4141
x != undefined && x.p;
4242

43-
u == undefined || u.p; // $ MISSING: Alert
44-
n == undefined || n.p; // $ MISSING: Alert
45-
o == undefined || o.p; // $ MISSING: Alert
43+
u == undefined || u.p; // $ Alert
44+
n == undefined || n.p; // $ Alert
45+
o == undefined || o.p; // $ Alert
4646
x == undefined || x.p;
4747

48-
u === undefined || u.p; // $ MISSING: Alert
49-
n === undefined || n.p; // $ MISSING: Alert
50-
o === undefined || o.p; // $ MISSING: Alert
48+
u === undefined || u.p; // $ Alert
49+
n === undefined || n.p; // $ Alert
50+
o === undefined || o.p; // $ Alert
5151
x === undefined || x.p;
5252

53-
if (u) { // $ MISSING: Alert
53+
if (u) { // $ Alert
5454
u.p;
5555
}
56-
if (n) { // $ MISSING: Alert
56+
if (n) { // $ Alert
5757
n.p;
5858
}
59-
if (o) { // $ MISSING: Alert
59+
if (o) { // $ Alert
6060
o.p;
6161
}
6262
if (x) {
6363
x.p;
6464
}
6565

66-
u? u():_; // $ MISSING: Alert
67-
n? n(): _; // $ MISSING: Alert
68-
o? o(): _; // $ MISSING: Alert
66+
u? u():_; // $ Alert
67+
n? n(): _; // $ Alert
68+
o? o(): _; // $ Alert
6969
x? x(): _;
7070

71-
if (u !== undefined) { // $ MISSING: Alert
71+
if (u !== undefined) { // $ Alert
7272
u.p;
7373
}
74-
if (n !== undefined) { // $ MISSING: Alert
74+
if (n !== undefined) { // $ Alert
7575
n.p;
7676
}
77-
if (o !== undefined) { // $ MISSING: Alert
77+
if (o !== undefined) { // $ Alert
7878
o.p;
7979
}
8080
if (x !== undefined) {
8181
x.p;
8282
}
8383

84-
if (u == undefined){} // $ MISSING: Alert
85-
if (n == undefined){} // $ MISSING: Alert
86-
if (o == undefined){} // $ MISSING: Alert
84+
if (u == undefined){} // $ Alert
85+
if (n == undefined){} // $ Alert
86+
if (o == undefined){} // $ Alert
8787
if (x == undefined){}
8888

89-
if (u != undefined){} // $ MISSING: Alert
90-
if (n != undefined){} // $ MISSING: Alert
91-
if (o != undefined){} // $ MISSING: Alert
89+
if (u != undefined){} // $ Alert
90+
if (n != undefined){} // $ Alert
91+
if (o != undefined){} // $ Alert
9292
if (x != undefined){}
9393

94-
if (typeof u === "undefined"){} // $ MISSING: Alert
95-
if (typeof n === "undefined"){} // $ MISSING: Alert
96-
if (typeof o === "undefined"){} // $ MISSING: Alert
94+
if (typeof u === "undefined"){} // $ Alert
95+
if (typeof n === "undefined"){} // $ Alert
96+
if (typeof o === "undefined"){} // $ Alert
9797
if (typeof x === "undefined"){}
9898

9999
function f() { }
100-
typeof f === "function" && f(); // $ MISSING: Alert
101-
typeof u === "function" && u(); // $ MISSING: Alert
100+
typeof f === "function" && f(); // $ Alert
101+
typeof u === "function" && u(); // $ Alert
102102
typeof x === "function" && x();
103103

104104
var empty_array = [];
@@ -111,33 +111,33 @@
111111
var _true = true;
112112
var _false = false;
113113

114-
empty_array && empty_array.pop(); // $ MISSING: Alert
115-
pseudo_empty_array && pseudo_empty_array.pop(); // $ MISSING: Alert
116-
non_empty_array && non_empty_array.pop(); // $ MISSING: Alert
114+
empty_array && empty_array.pop(); // $ Alert
115+
pseudo_empty_array && pseudo_empty_array.pop(); // $ Alert
116+
non_empty_array && non_empty_array.pop(); // $ Alert
117117
empty_string && empty_string.charAt(0);
118118
non_empty_string && non_empty_string.charAt(0);
119119
zero && zero();
120120
neg && neg();
121121
_true && _true();
122122
_false && _false();
123123

124-
(u !== undefined && u !== null) && u.p; // $ MISSING: Alert
125-
u !== undefined && u !== null && u.p; // $ MISSING: Alert
124+
(u !== undefined && u !== null) && u.p; // $ Alert
125+
u !== undefined && u !== null && u.p; // $ Alert
126126

127-
u != undefined && u != null; // $ MISSING: Alert
128-
u == undefined || u == null; // $ MISSING: Alert
129-
u !== undefined && u !== null; // $ MISSING: Alert
130-
!(u === undefined) && !(u === null); // $ MISSING: Alert
131-
u === undefined || u === null; // $ MISSING: Alert
132-
!(u === undefined || u === null); // $ MISSING: Alert
133-
!(u === undefined) && u !== null; // $ MISSING: Alert
127+
u != undefined && u != null; // $ Alert
128+
u == undefined || u == null; // $ Alert
129+
u !== undefined && u !== null; // $ Alert
130+
!(u === undefined) && !(u === null); // $ Alert
131+
u === undefined || u === null; // $ Alert
132+
!(u === undefined || u === null); // $ Alert
133+
!(u === undefined) && u !== null; // $ Alert
134134
u !== undefined && n !== null;
135-
u == undefined && u == null; // $ MISSING: Alert
135+
u == undefined && u == null; // $ Alert
136136
x == undefined && x == null;
137137

138-
x === undefined && x === null; // $ MISSING: Alert
138+
x === undefined && x === null; // $ Alert
139139
if (x === undefined) {
140-
if (x === null) { // $ MISSING: Alert
140+
if (x === null) { // $ Alert
141141
}
142142
}
143143

@@ -153,9 +153,9 @@
153153
}
154154
}
155155

156-
x != undefined && x != null; // $ MISSING: Alert
156+
x != undefined && x != null; // $ Alert
157157
if (x != undefined) {
158-
if (x != null) { // $ MISSING: Alert
158+
if (x != null) { // $ Alert
159159
}
160160
}
161161

@@ -174,8 +174,8 @@
174174

175175
u && (f(), u.p);
176176
u && (u.p, f()); // technically not OK, but it seems like an unlikely pattern
177-
u && !u.p; // $ MISSING: Alert
178-
u && !u(); // $ MISSING: Alert
177+
u && !u.p; // $ Alert
178+
u && !u(); // $ Alert
179179

180180

181181
function hasCallbacks(success, error) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function(){
22
var v;
33
(function(){
4-
if(typeof v === "undefined"){
4+
if(typeof v === "undefined"){ // $ Alert
55
v = 42;
66
}
77
for(var v in x){

0 commit comments

Comments
 (0)