JS: Update OK-style comments to $-style

This commit is contained in:
Asger F
2025-02-06 13:34:01 +01:00
parent 7e5c24a8ec
commit 9be041e27d
536 changed files with 4408 additions and 4762 deletions

View File

@@ -6,18 +6,16 @@ console.log(bitIsSet(-1, 31)); // prints 'false'
(x & 3) > 0; // this is fine
// OK
x = -1;
console.log((x | 0) > (0)); // prints 'false'
// NOT OK
console.log((x >>> 0) > 0); // prints 'true'
console.log((x >>> 0) > 0); // prints 'true' // $ Alert
// OK
console.log((x << 16 >> 16) > 0); // prints 'false'
// OK
(x & 256) > 0;
// NOT OK
(x & 0x100000000) > 0;
(x & 0x100000000) > 0; // $ Alert

View File

@@ -12,34 +12,33 @@ Rectangle.prototype.contains = function(x, y) {
y < this.y+this.height);
};
// OK
"true" == true;
// OK
f() != f(23);
// NOT OK
(function() { }) == (function() {});
(function() { }) == (function() {}); // $ Alert
// OK
x === y;
// OK
true === false;
// OK
function isNan(n) {
return n !== n;
}
// OK
function checkNaN(x) {
if (x === x) // check whether x is NaN
return false;
return true;
}
// OK (though wrong in other ways)
// OK - though wrong in other ways
function same(x, y) {
if (x === y)
return true;

View File

@@ -1,12 +1,12 @@
var duplicate = {
"key": "value", // NOT OK: duplicated on line 5
"key": "value", // $ Alert - duplicated on line 5
" key": "value",
"1": "value", // NOT OK: duplicated on line 11
"key": "value", // NOT OK: duplicated on next line
'key': "value", // NOT OK: duplicated on next line
key: "value", // NOT OK: duplicated on next line
\u006bey: "value", // NOT OK: duplicated on next line
"\u006bey": "value", // NOT OK: duplicated on next line
"1": "value", // $ Alert - duplicated on line 11
"key": "value", // $ Alert - duplicated on next line
'key': "value", // $ Alert - duplicated on next line
key: "value", // $ Alert - duplicated on next line
\u006bey: "value", // $ Alert - duplicated on next line
"\u006bey": "value", // $ Alert - duplicated on next line
"\x6bey": "value",
1: "value"
};

View File

@@ -1,6 +1,6 @@
function* foo(){
var index = 0;
while(index <= 2)
// OK
yield index++;
}

View File

@@ -20,7 +20,7 @@ var myComplicatedPropertyDescriptor = (function(k) {
})("get");
Object.defineProperty(Object.prototype, 'foo', myComplicatedPropertyDescriptor);
// OK: getters
// OK - getters
(false).should.be.ok;
(false).should;
should.prototype.be;

View File

@@ -19,7 +19,7 @@ function try2(x) {
function try3(x) {
try {
x.ordinaryProperty()
x.ordinaryProperty // NOT OK
x.ordinaryProperty // $ Alert
return x;
} catch (e) {
return false;

View File

@@ -1,83 +1,82 @@
'use strict'; // OK
'use struct'; // OK (flagged by UnknownDirective.ql)
23; // NOT OK
void(23); // OK
23, foo(); // NOT OK
foo(23, 42); // OK
foo((23, bar())); // NOT OK
foo((bar(), 23)); // OK
1,f(); // NOT OK
'use strict';
'use struct'; // OK - flagged by UnknownDirective.ql
23; // $ Alert
void(23);
23, foo(); // $ Alert
foo(23, 42);
foo((23, bar())); // $ Alert
foo((bar(), 23));
1,f(); // $ Alert
// OK
/**
* @type {function(int) : string}
*/
String.prototype.slice;
// OK
/** @typedef {(string|number)} */
goog.NumberLike;
// NOT OK
/** Useless */
/** Useless */ // $ Alert
x;
// OK (magic DOM property)
// OK - magic DOM property
elt.clientTop;
// OK (xUnit fixture)
// OK - xUnit fixture
[Fixture]
function tst() {}
// OK: bad style, but most likely intentional
// OK - bad style, but most likely intentional
(0, o.m)();
(0, o["m"])();
function tst() {
// OK: bad style, but most likely intentional
// OK - bad style, but most likely intentional
(0, eval)("42");
}
function f() {
var x;
"foo"; // NOT OK
"foo"; // $ Alert
}
try {
doSomethingDangerous();
} catch(e) {
new Error("Told you so"); // NOT OK
new SyntaxError("Why didn't you listen to me?"); // NOT OK
new Error(computeSnarkyMessage(e)); // NOT OK
new UnknownError(); // OK
new Error("Told you so"); // $ Alert
new SyntaxError("Why didn't you listen to me?"); // $ Alert
new Error(computeSnarkyMessage(e)); // $ Alert
new UnknownError();
}
function g() {
var o = {};
Object.defineProperty(o, "trivialGetter1", { get: function(){} });
o.trivialGetter1; // OK
o.trivialGetter1;
Object.defineProperty(o, "trivialNonGetter1", "foo");
o.trivialNonGetter1; // NOT OK
o.trivialNonGetter1; // $ Alert
var getterDef1 = { get: function(){} };
Object.defineProperty(o, "nonTrivialGetter1", getterDef1);
o.nonTrivialGetter1; // OK
o.nonTrivialGetter1;
var getterDef2 = { };
unknownPrepareGetter(getterDef2);
Object.defineProperty(o, "nonTrivialNonGetter1", getterDef2);
o.nonTrivialNonGetter1; // OK
o.nonTrivialNonGetter1;
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
o.nonTrivialGetter2; // OK
o.nonTrivialGetter2;
(o: empty); // OK
(o: empty);
testSomeCondition() ? o : // NOT OK
testSomeCondition() ? o : // $ Alert
doSomethingDangerous();
consume(testSomeCondition() ? o : // OK
consume(testSomeCondition() ? o :
doSomethingDangerous());
};

View File

@@ -1,4 +1,3 @@
function tst2(eval) {
// NOT OK
(0, eval)("42");
(0, eval)("42"); // $ Alert
}

View File

@@ -1,137 +1,128 @@
// NOT OK
if (typeof window !== undefined)
if (typeof window !== undefined) // $ Alert
console.log("browser");
// OK
if (typeof window === "undefined")
console.log("not a browser");
// NOT OK
if ("Hello, world".indexOf("Hello" >= 0))
if ("Hello, world".indexOf("Hello" >= 0)) // $ Alert
console.log("It's in there.");
// OK
true < 1;
// OK
undefined == null;
// NOT OK
null == 0;
null == 0; // $ Alert
// NOT OK
switch ("hi") {
switch ("hi") { // $ Alert
case 42:
}
// NOT OK
Object.toString() + "!" == undefined;
Object.toString() + "!" == undefined; // $ Alert
// NOT OK
(+f() || !g() || (h() + k())) == undefined;
(+f() || !g() || (h() + k())) == undefined; // $ Alert
// NOT OK
if (!Module['load'] == 'undefined') {
if (!Module['load'] == 'undefined') { // $ Alert
}
function f(x) {
return true;
// OK
return x === 42;
}
function g() {
var number = 0; // number
// OK
number == "0";
// NO OK
number == "zero";
number == "zero"; // $ Alert
}
// NOT OK
0 < (Math.random() > 0.5 ? void 0 : [1, 2]);
0 < (Math.random() > 0.5 ? void 0 : [1, 2]); // $ Alert
// OK
'100' < 1000;
// OK (fvsvo "OK")
// OK - fvsvo "OK"
100 > '';
// OK
new Date('foo') == 'Invalid Date';
// OK
new String('bar') == 'bar';
// OK
({ valueOf: () => true } == true);
// OK
({ valueOf: () => 42 } == 42);
// OK
({ valueOf: () => 'hi' } == 'hi');
// OK
({ valueOf: () => null } == null);
// NOT OK, but not currently flagged since we conservatively
// assume that `new Date(123)` could return any object, not necessarily a Date
// assume that `new Date(123)` could return any object, not necessarily a Date // $ Alert - but not currently flagged since we conservatively
new Date(123) == 123
function f(x1, x2, x3, x4, x5, x6){
typeof x1 === 'object' && x1 !== null; // OK
typeof x1 === 'object' && x1 !== null;
if (!x2) {
x2 = new Error();
}
typeof x2 === 'object' && x2 !== null; // NOT OK: x2 cannot be null here
typeof x2 === 'object' && x2 !== null; // $ Alert - x2 cannot be null here
if (x3) {
typeof x3 === 'object' && x3 !== null; // NOT OK: x3 cannot be null here
typeof x3 === 'object' && x3 !== null; // $ Alert - x3 cannot be null here
}
if (!x4) {
typeof x4 === 'object' && x4 !== null; // OK
typeof x4 === 'object' && x4 !== null;
}
if (!x5) {
x5 = new Error();
}
x5 !== null; // NOT OK: x2 cannot be null here
x5 !== null; // $ Alert - x2 cannot be null here
if (x6) {
x6 !== null; // NOT OK: x3 cannot be null here
x6 !== null; // $ Alert - x3 cannot be null here
}
}
function g() {
var o = {};
o < "def"; // NOT OK
o < "def"; // $ Alert
var p = { toString() { return "abc"; } };
p < "def"; // OK
p < "def";
function A() {}
var a = new A();
a < "def"; // NOT OK
a < "def"; // $ Alert
function B() {};
B.prototype = p;
var b = new B();
b < "def"; // OK
b < "def";
function C() {
this.valueOf = function() { return 42; };
}
var c = new C();
c != 23; // OK
c != 23;
null.valueOf = function() { return 42; };
null == 42; // NOT OK
null == 42; // $ Alert
true.valueOf = function() { return "foo" };
true != "bar"; // NOT OK
true != "bar"; // $ Alert
}
@@ -139,54 +130,54 @@ function h() {
var a = 42;
var b = "42";
a === "42"; // NOT OK
42 === b // NOT OK
a === b; // NOT OK
a === "42"; // $ Alert
42 === b // $ Alert
a === b; // $ Alert
}
function i() {
"foo" === undefined
undefined === "foo" // NOT OK
undefined === "foo" // $ Alert
var NaN = 0; // trick analysis to consider warning about NaN, for the purpose of testing pretty printing
NaN === "foo" // NOT OK
NaN === "foo" // $ Alert
var Infinity = 0; // trick analysis to consider warning about Infinity, for the purpose of testing pretty printing
Infinity === "foo" // NOT OK
Infinity === "foo" // $ Alert
}
function k() {
// tests for pretty printing of many types
var t1 = 42;
t1 !== null; // NOT OK
null !== t1; // NOT OK
t1 !== null; // $ Alert
null !== t1; // $ Alert
var t2 = unknown? t1: "foo";
t2 !== null; // NOT OK
null !== t2; // NOT OK
t2 !== null; // $ Alert
null !== t2; // $ Alert
var t3 = unknown? t2: undefined;
t3 !== null; // NOT OK
null !== t3; // NOT OK
t3 !== null; // $ Alert
null !== t3; // $ Alert
var t4 = unknown? t3: true;
t4 !== null; // NOT OK
null !== t4; // NOT OK
t4 !== null; // $ Alert
null !== t4; // $ Alert
var t5 = unknown? t4: function(){};
t5 !== null; // NOT OK
null !== t5; // NOT OK
t5 !== null; // $ Alert
null !== t5; // $ Alert
var t6 = unknown? t5: /t/;
t6 !== null; // NOT OK
null !== t6; // NOT OK
t6 !== null; // $ Alert
null !== t6; // $ Alert
var t7 = unknown? t6: {};
t7 !== null; // NOT OK
null !== t7; // NOT OK
t7 !== null; // $ Alert
null !== t7; // $ Alert
var t8 = unknown? t8: new Symbol();
t8 !== null; // NOT OK
null !== t8; // NOT OK
t8 !== null; // $ Alert
null !== t8; // $ Alert
}
@@ -199,22 +190,22 @@ function l() {
var t4 = unknown? 42: unknown? "foo": unknown? undefined: true;
var t5 = unknown? t4: null
t2 !== t4; // NOT OK
t4 !== t2; // NOT OK
t3 !== t4; // NOT OK
t4 !== t3; // NOT OK
t2 !== t4; // $ Alert
t4 !== t2; // $ Alert
t3 !== t4; // $ Alert
t4 !== t3; // $ Alert
t2 !== t5; // NOT OK
t5 !== t2; // NOT OK
t3 !== t5; // NOT OK
t5 !== t3; // NOT OK
t2 !== t5; // $ Alert
t5 !== t2; // $ Alert
t3 !== t5; // $ Alert
t5 !== t3; // $ Alert
}
1n == 1; // OK
1n == 1;
(function tooGeneralLocalFunctions(){
function f1(x) {
if (x === "foo") { // OK, whitelisted
if (x === "foo") { // OK - whitelisted
}
}
@@ -222,7 +213,7 @@ function l() {
function f2(x, y) {
var xy = o.q? x: y;
if (xy === "foo") { // NOT OK (not whitelisted like above)
if (xy === "foo") { // $ Alert - not whitelisted like above
}
}

View File

@@ -1,41 +1,36 @@
// NOT OK
!method in obj;
!method in obj; // $ Alert
// OK
!(method in obj);
// OK
'__proto__' in obj;
// OK
0 in obj;
// OK
('$' + key) in obj;
// NOT OK
p in null;
p in null; // $ Alert
0 in 'string'; // $ Alert
// NOT OK
0 in 'string';
// OK
p in {};
// NOT OK
console.log("Setting device's bluetooth name to '%s'" % device_name);
console.log("Setting device's bluetooth name to '%s'" % device_name); // $ Alert
// NOT OK
if (!callback || !callback instanceof Function) {
if (!callback || !callback instanceof Function) { // $ Alert
;
}
// OK
function cmp(x, y) {
return (x > y) - (x < y);
}
// OK
function cmp(x, y) {
if (x > y)
return 1;
@@ -44,48 +39,42 @@ function cmp(x, y) {
return 0;
}
// OK
function cmp(x, y) {
return (x > y) - (x < y);
}
// NOT OK
1 + void 0
1 + void 0 // $ Alert
// OK
o[true] = 42;
function f() {
var x;
// NOT OK
x -= 2;
x -= 2; // $ Alert
}
function g() {
var x = 19, y;
// NOT OK
x %= y;
x %= y; // $ Alert
}
function h() {
var x;
// NOT OK
++x;
++x; // $ Alert
}
function k() {
var name;
// NOT OK
return `Hello ${name}!`;
return `Hello ${name}!`; // $ Alert
}
function l() {
var x;
// NOT OK
x ** 2;
x ** 2; // $ Alert
}
1n + 1; // NOT OK, but not currently flagged
1n + 1; // $ MISSED: Alert
(function(){
let sum = 0;
@@ -114,10 +103,10 @@ function l() {
function m() {
var x = 19, y = "string";
x %= y; // NOT OK
x += y; // OK
x ||= y; // OK
x &&= y; // OK
x ??= y; // OK
x >>>= y; // NOT OK
x %= y; // $ Alert
x += y;
x ||= y;
x &&= y;
x ??= y;
x >>>= y; // $ Alert
}

View File

@@ -1,5 +1,5 @@
declare let cache: { [x: string]: Promise<any> };
function deleteCache(x: string) {
delete cache[x]; // OK
delete cache[x];
}

View File

@@ -5,24 +5,24 @@ async function getThing() {
function useThing() {
let thing = getThing();
if (thing === undefined) {} // NOT OK
if (thing === undefined) {} // $ Alert
if (thing == null) {} // NOT OK
if (thing == null) {} // $ Alert
something(thing ? 1 : 2); // NOT OK
something(thing ? 1 : 2); // $ Alert
for (let x in thing) { // NOT OK
for (let x in thing) { // $ Alert
something(x);
}
let obj = something();
something(obj[thing]); // NOT OK
obj[thing] = 5; // NOT OK
something(obj[thing]); // $ Alert
obj[thing] = 5; // $ Alert
something(thing + "bar"); // NOT OK
something(thing + "bar"); // $ Alert
if (something()) {
if (thing) { // NOT OK
if (thing) { // $ Alert
something(3);
}
}
@@ -31,21 +31,21 @@ function useThing() {
async function useThingCorrectly() {
let thing = await getThing();
if (thing === undefined) {} // OK
if (thing === undefined) {}
if (thing == null) {} // OK
if (thing == null) {}
return thing + "bar"; // OK
return thing + "bar";
}
async function useThingCorrectly2() {
let thing = getThing();
if (await thing === undefined) {} // OK
if (await thing === undefined) {}
if (await thing == null) {} // OK
if (await thing == null) {}
return thing + "bar"; // NOT OK
return thing + "bar"; // $ Alert
}
function getThingSync() {
@@ -55,21 +55,21 @@ function getThingSync() {
function useThingPossiblySync(b) {
let thing = b ? getThing() : getThingSync();
if (thing === undefined) {} // OK
if (thing === undefined) {}
if (thing == null) {} // OK
if (thing == null) {}
return thing + "bar"; // NOT OK - but we don't flag it
return thing + "bar"; // $ MISSED: Alert
}
function useThingInVoid() {
void getThing(); // OK
void getThing();
}
function useThing() {
if (random()) {
return getThing() ?? null; // NOT OK
return getThing() ?? null; // $ Alert
} else {
return getThing?.() ?? null; // OK
return getThing?.() ?? null;
}
}
}

View File

@@ -1,6 +1,6 @@
function total(bad) {
var sum = 0
for (var i = 0; i < bad; ++i) { // NOT OK
for (var i = 0; i < bad; ++i) { // $ Alert
sum += bad[i]
}
return sum
@@ -8,7 +8,7 @@ function total(bad) {
function total_good(good) {
var sum = 0
for (var i = 0; i < good.length; ++i) { // OK
for (var i = 0; i < good.length; ++i) {
sum += good[i]
}
return sum
@@ -17,21 +17,21 @@ function total_good(good) {
var fruits = ["banana", "pineapple"]
function mix() {
var drink = []
for (var i = 0; i < fruits; ++i) { // NOT OK
for (var i = 0; i < fruits; ++i) { // $ Alert
drink.push(fruits[i])
}
}
function mix_good() {
var drink = []
for (var i = 0; i < fruits.length; ++i) { // OK
for (var i = 0; i < fruits.length; ++i) {
drink.push(fruits[i])
}
}
function overloaded(mode, foo, bar) {
if (mode == "floo") {
return foo < bar; // OK
return foo < bar;
} else if (mode == "blar") {
return foo[bar];
} else {
@@ -41,7 +41,7 @@ function overloaded(mode, foo, bar) {
function overloaded_no_else(mode, foo, bar) {
if (mode == "floo") {
return foo < bar; // OK
return foo < bar;
}
if (mode == "blar") {
return foo[bar];
@@ -50,7 +50,7 @@ function overloaded_no_else(mode, foo, bar) {
function reassigned(index, object) {
var tmp = object.getMaximum()
if (index < tmp) { // OK
if (index < tmp) {
tmp = object.getArray()
return tmp[index]
}

View File

@@ -1,43 +1,40 @@
// use of .length to prime the query
a.length;
// NOT OK
for (var i=0; i<a.lenght; ++i);
for (var i=0; i<a.lenght; ++i); // $ Alert
// OK: 'correct' spelling 'eels' is not used anywhere
// OK - 'correct' spelling 'eels' is not used anywhere
var eles = [];
// OK: very short identifier
// OK - very short identifier
var can, cna;
// OK: only case differs
// OK - only case differs
var NASA, nasa;
// OK: whitelisted
// OK - whitelisted
var through, thru, inbetween;
// OK
var realY;
// some more priming
between, really, available, value;
// NOT OK
var lenght123, Lenght;
var lenght123, Lenght; // $ Alert
// OK
var LENght, JKLenght;
// NOT OK
Mandreel_HttpRequest_BytesAvalable;
Mandreel_HttpRequest_BytesAvalable; // $ Alert
// OK
EValue;
// OK
ReactDOMOther;
there;
// NO OK
var throught, through, throughout; // NB: we don't suggest "thought", since it isn't used anywhere
var sheat, cheat, sheath, sheet;
var throught, through, throughout; // $ Alert - NB: we don't suggest "thought", since it isn't used anywhere
var sheat, cheat, sheath, sheet; // $ Alert

View File

@@ -8,4 +8,4 @@ x & x;
// this may actually be OK, but it's not good style
pop() && pop();
foo[bar++] && foo[bar++] // OK
foo[bar++] && foo[bar++]

View File

@@ -6,8 +6,8 @@ class C extends Q {
*/
this.x = this.x; // OK - documentation
this.y = this.y; // NOT OK
this.y = this.y; // $ Alert
this.arg = this.arg; // NOT OK
this.arg = this.arg; // $ Alert
}
}

View File

@@ -1,8 +1,7 @@
function Rectangle(x, y, width, height) {
this.x = x;
this.y = y;
// NOT OK
width = width;
width = width; // $ Alert
this.height = height;
}
@@ -15,18 +14,16 @@ Rectangle.prototype = {
this.width = a/this.height;
},
foo: function() {
// OK
this.area = this.area;
}
};
// NOT OK
array[1] = array[1];
array[1] = array[1]; // $ Alert
o.x = o.x; // $ Alert
// NOT OK
o.x = o.x;
// OK
document.innerHTML = document.innerHTML;
class Point {
@@ -43,7 +40,7 @@ class Point {
this.y = 0;
}
foo() {
// OK
this.dist = this.dist;
}
}

View File

@@ -1,2 +1,2 @@
var n = 1<<40; // NOT OK
var n2 = BigInt(1) << 40n; // OK
var n = 1<<40; // $ Alert
var n2 = BigInt(1) << 40n;

View File

@@ -1,12 +1,12 @@
function foo() {
var f;
eval("f = alert");
f("Hi"); // OK: initialised by eval
f("Hi"); // OK - initialised by eval
}
function bar() {
var g;
g(); // NOT OK, but not currently flagged
g(); // $ MISSED: Alert
eval("g = alert");
}
@@ -15,10 +15,10 @@ function baz() {
function inner(b) {
if (b) {
inner(false);
g(); // OK: initialised by eval below
g(); // OK - initialised by eval below
} else {
eval("g = alert");
}
}
inner(true);
}
}

View File

@@ -5,20 +5,20 @@ namespace f {
export function inner() {}
}
f(); // OK
f.inner(); // OK
f();
f.inner();
class C {}
namespace C {
export function inner() {}
}
new C(); // OK
C.inner(); // OK
new C();
C.inner();
namespace g {
export function inner() {}
}
g(); // NOT OK
g.inner(); // OK
g(); // $ Alert
g.inner();

View File

@@ -1,13 +1,12 @@
class A extends null {
constructor() {
// OK: calls `Function.prototype`
// OK - calls `Function.prototype`
super();
}
}
class B extends 42 {
constructor() {
// NOT OK
super();
super(); // $ Alert
}
}

View File

@@ -1,5 +1,5 @@
import C from "./export_equals";
function f() {
C.staticMethod(); // OK
C.staticMethod();
}

View File

@@ -1,5 +1,5 @@
import { importExport } from "./export_import";
function test() {
let f = importExport.prop; // OK
let f = importExport.prop;
}

View File

@@ -18,7 +18,7 @@ namespace N {
var x;
x.p = 5;
var q = M.Color.Blue; // OK
var q = M.Color.Blue;
namespace M {
export const enum Color { Blue }

View File

@@ -8,10 +8,10 @@ function f(x: Base[]) {
if (x) {
y = x[0] as Sub;
}
y.field; // OK
y.field;
var z = null as Sub;
z.field; // NOT OK
z.field; // $ Alert
}
f([new Sub()]);

View File

@@ -1,6 +1,6 @@
function f() {
var y: typeof N.x // OK
var z = N.x // NOT OK (currently missed due to const enum workaround)
var y: typeof N.x
var z = N.x // $ MISSING: Alert - missed due to const enum workaround
namespace N {
export var x = 45
}

View File

@@ -5,7 +5,7 @@ class Component0 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughAutoBind}/> // OK
<div onClick={this.bound_throughAutoBind}/>
</div>
}
@@ -24,20 +24,20 @@ class Component1 extends React.Component {
render() {
var unbound3 = this.unbound3;
return <div>
<div onClick={this.unbound1}/> // NOT OK
<div onClick={this.unbound2}/> // NOT OK
<div onClick={unbound3}/> // NOT OK
<div onClick={this.bound_throughBindInConstructor}/> // OK
<div onClick={this.bound_throughDeclaration}/> // OK
<div onClick={this.unbound_butNoThis}/> // OK
<div onClick={this.unbound_butNoThis2}/> // OK
<div onClick={(e) => this.unbound_butInvokedSafely(e)}/> // OK
<div onClick={this.bound_throughBindInMethod}/> // OK
<div onClick={this.bound_throughNonSyntacticBindInConstructor}/> // OK
<div onClick={this.bound_throughBindAllInConstructor1}/> // OK
<div onClick={this.bound_throughBindAllInConstructor2}/> // OK
<div onClick={this.bound_throughDecorator_autobind}/> // OK
<div onClick={this.bound_throughDecorator_actionBound}/> // OK
<div onClick={this.unbound1}/> // $ Alert
<div onClick={this.unbound2}/> // $ Alert
<div onClick={unbound3}/> // $ Alert
<div onClick={this.bound_throughBindInConstructor}/>
<div onClick={this.bound_throughDeclaration}/>
<div onClick={this.unbound_butNoThis}/>
<div onClick={this.unbound_butNoThis2}/>
<div onClick={(e) => this.unbound_butInvokedSafely(e)}/>
<div onClick={this.bound_throughBindInMethod}/>
<div onClick={this.bound_throughNonSyntacticBindInConstructor}/>
<div onClick={this.bound_throughBindAllInConstructor1}/>
<div onClick={this.bound_throughBindAllInConstructor2}/>
<div onClick={this.bound_throughDecorator_autobind}/>
<div onClick={this.bound_throughDecorator_actionBound}/>
</div>
}
@@ -125,7 +125,7 @@ class Component2 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughClassDecorator_autobind}/> // OK
<div onClick={this.bound_throughClassDecorator_autobind}/>
</div>;
}
@@ -139,7 +139,7 @@ class Component3 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughIterator}/> // OK
<div onClick={this.bound_throughIterator}/>
</div>
}
@@ -159,7 +159,7 @@ class Component4 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughReactAutobind}/> // OK
<div onClick={this.bound_throughReactAutobind}/>
</div>
}
@@ -177,7 +177,7 @@ class Component5 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughSomeBinder}/> // OK
<div onClick={this.bound_throughSomeBinder}/>
</div>
}

View File

@@ -1,10 +1,10 @@
x.f() & 0x0A != 0; // NOT OK
x.f() & (0x0A != 0); // OK
x.f() & 0x0A != 0; // OK
x.f() & 0x0A!=0; // OK
x.f() & 0x0A != 0; // $ Alert
x.f() & (0x0A != 0);
x.f() & 0x0A != 0;
x.f() & 0x0A!=0;
x !== y & 1; // NOT OK
x !== y & 1; // $ Alert
x > 0 & x < 10; // OK
x > 0 & x < 10;
a&b==c; // NOT OK
a&b==c; // $ Alert

View File

@@ -1 +1 @@
a&b==c; // OK (minified file)
a&b==c; // OK - minified file

View File

@@ -1,6 +1,6 @@
<a href="javascript:'some-attribute-string-1'"></a> <!-- OK -->
<a href="javascript:'some-attribute-string-2'; foo();"></a> <!-- OK -->
<a href="javascript:'some-attribute-string-3'; function foo(){ 'some-function-string'; };"></a> <!-- OK --> <!-- BAD -->
<a href="javascript:'some-attribute-string-1'"></a>
<a href="javascript:'some-attribute-string-2'; foo();"></a>
<a href="javascript:'some-attribute-string-3'; function foo(){ 'some-function-string'; };"></a> <!-- OK --> <!-- $ Alert -->
<script>
'some-script-string' // BAD
'some-script-string' // $ Alert
</script>

View File

@@ -1,51 +1,51 @@
"use foo"; // NOT OK
"use strict"; // NOT OK
"use foo"; // $ Alert
"use strict"; // $ Alert
function bad() {
"'use strict'"; // NOT OK
"use strict;"; // NOT OK
"'use strict';"; // NOT OK
"'use strict;'"; // NOT OK
"use-strict"; // NOT OK
"use_strict"; // NOT OK
"uses strict"; // NOT OK
"use struct;" // NOT OK
"Use Strict"; // NOT OK
"use bar"; // NOT OK
"'use strict'"; // $ Alert
"use strict;"; // $ Alert
"'use strict';"; // $ Alert
"'use strict;'"; // $ Alert
"use-strict"; // $ Alert
"use_strict"; // $ Alert
"uses strict"; // $ Alert
"use struct;" // $ Alert
"Use Strict"; // $ Alert
"use bar"; // $ Alert
}
function ignored() {
var x = 42;
"use baz"; // OK: not a directive, positionally
"use baz"; // OK - not a directive, positionally
}
function good() {
"use strict"; // OK
"use asm"; // OK
"use babel"; // OK
"use 6to5"; // OK
"format cjs" // OK
"format esm"; // OK
"format global"; // OK
"format register"; // OK
"ngInject"; // OK
"ngNoInject"; // OK
"deps foo"; // OK
"deps bar"; // OK
"use server"; // OK
"use client"; // OK
"use strict";
"use asm";
"use babel";
"use 6to5";
"format cjs"
"format esm";
"format global";
"format register";
"ngInject";
"ngNoInject";
"deps foo";
"deps bar";
"use server";
"use client";
}
function data() {
"[0, 0, 0];"; // NOT OK
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];"; // NOT OK
"[0, 0, 0];"; // $ Alert
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];"; // $ Alert
}
function yui() {
"foo:nomunge"; // OK
"bar:nomunge, baz:nomunge,qux:nomunge"; // OK
":nomunge"; // NOT OK
"foo(), bar, baz:nomunge"; // NOT OK
"foo:nomunge";
"bar:nomunge, baz:nomunge,qux:nomunge";
":nomunge"; // $ Alert
"foo(), bar, baz:nomunge"; // $ Alert
}
function babel_typeof(obj) {

View File

@@ -7,5 +7,5 @@ var Mod1;
var Mod2;
(function (Mod2) {
Mod2.p = 42;
})(Mod2 || (Mod2 = {})); // NOT OK
})(Mod2 || (Mod2 = {})); // $ Alert
});

View File

@@ -20,5 +20,5 @@ if (typeof exports !== 'undefined') {
(function(){
var module;
if(typeof module === 'undefined'); // NOT OK
if(typeof module === 'undefined'); // $ Alert
});

View File

@@ -6,10 +6,10 @@ function getDate() {
return null;
}
console.log(date);
return date && date.getTime(); // NOT OK
return date && date.getTime(); // $ Alert
}
function isNotNullOrString(obj) {
return obj != null && obj != undefined && // NOT OK
return obj != null && obj != undefined && // $ Alert
typeof obj != 'string';
}

View File

@@ -10,95 +10,95 @@
var o_ = o;
var x_ = x;
u_ = u_ || e; // NOT OK
n_ = n_ || e; // NOT OK
o_ = o_ || e; // NOT OK
u_ = u_ || e; // $ Alert
n_ = n_ || e; // $ Alert
o_ = o_ || e; // $ Alert
x_ = x_ || e;
u && u.p; // NOT OK
n && n.p; // NOT OK
o && o.p; // NOT OK
u && u.p; // $ Alert
n && n.p; // $ Alert
o && o.p; // $ Alert
x && x.p;
u && u(); // NOT OK
n && n(); // NOT OK
o && o(); // NOT OK
u && u(); // $ Alert
n && n(); // $ Alert
o && o(); // $ Alert
x && x();
!u || u.p; // NOT OK
!n || n.p; // NOT OK
!o || o.p; // NOT OK
!u || u.p; // $ Alert
!n || n.p; // $ Alert
!o || o.p; // $ Alert
!x || x.p;
!!u && u.p; // NOT OK
!!n && n.p; // NOT OK
!!o && o.p; // NOT OK
!!u && u.p; // $ Alert
!!n && n.p; // $ Alert
!!o && o.p; // $ Alert
!!x && x.p;
u != undefined && u.p; // NOT OK
n != undefined && n.p; // NOT OK
o != undefined && o.p; // NOT OK
u != undefined && u.p; // $ Alert
n != undefined && n.p; // $ Alert
o != undefined && o.p; // $ Alert
x != undefined && x.p;
u == undefined || u.p; // NOT OK
n == undefined || n.p; // NOT OK
o == undefined || o.p; // NOT OK
u == undefined || u.p; // $ Alert
n == undefined || n.p; // $ Alert
o == undefined || o.p; // $ Alert
x == undefined || x.p;
u === undefined || u.p; // NOT OK
n === undefined || n.p; // NOT OK
o === undefined || o.p; // NOT OK
u === undefined || u.p; // $ Alert
n === undefined || n.p; // $ Alert
o === undefined || o.p; // $ Alert
x === undefined || x.p;
if (u) { // NOT OK
if (u) { // $ Alert
u.p;
}
if (n) { // NOT OK
if (n) { // $ Alert
n.p;
}
if (o) { // NOT OK
if (o) { // $ Alert
o.p;
}
if (x) {
x.p;
}
u? u():_; // NOT OK
n? n(): _; // NOT OK
o? o(): _; // NOT OK
u? u():_; // $ Alert
n? n(): _; // $ Alert
o? o(): _; // $ Alert
x? x(): _;
if (u !== undefined) { // NOT OK
if (u !== undefined) { // $ Alert
u.p;
}
if (n !== undefined) { // NOT OK
if (n !== undefined) { // $ Alert
n.p;
}
if (o !== undefined) { // NOT OK
if (o !== undefined) { // $ Alert
o.p;
}
if (x !== undefined) {
x.p;
}
if (u == undefined){} // NOT OK
if (n == undefined){} // NOT OK
if (o == undefined){} // NOT OK
if (u == undefined){} // $ Alert
if (n == undefined){} // $ Alert
if (o == undefined){} // $ Alert
if (x == undefined){}
if (u != undefined){} // NOT OK
if (n != undefined){} // NOT OK
if (o != undefined){} // NOT OK
if (u != undefined){} // $ Alert
if (n != undefined){} // $ Alert
if (o != undefined){} // $ Alert
if (x != undefined){}
if (typeof u === "undefined"){} // NOT OK
if (typeof n === "undefined"){} // NOT OK
if (typeof o === "undefined"){} // NOT OK
if (typeof u === "undefined"){} // $ Alert
if (typeof n === "undefined"){} // $ Alert
if (typeof o === "undefined"){} // $ Alert
if (typeof x === "undefined"){}
function f() { }
typeof f === "function" && f(); // NOT OK
typeof u === "function" && u(); // NOT OK
typeof f === "function" && f(); // $ Alert
typeof u === "function" && u(); // $ Alert
typeof x === "function" && x();
var empty_array = [];
@@ -111,9 +111,9 @@
var _true = true;
var _false = false;
empty_array && empty_array.pop(); // NOT OK
pseudo_empty_array && pseudo_empty_array.pop(); // NOT OK
non_empty_array && non_empty_array.pop(); // NOT OK
empty_array && empty_array.pop(); // $ Alert
pseudo_empty_array && pseudo_empty_array.pop(); // $ Alert
non_empty_array && non_empty_array.pop(); // $ Alert
empty_string && empty_string.charAt(0);
non_empty_string && non_empty_string.charAt(0);
zero && zero();
@@ -121,23 +121,23 @@
_true && _true();
_false && _false();
(u !== undefined && u !== null) && u.p; // NOT OK
u !== undefined && u !== null && u.p; // NOT OK
(u !== undefined && u !== null) && u.p; // $ Alert
u !== undefined && u !== null && u.p; // $ Alert
u != undefined && u != null; // NOT OK
u == undefined || u == null; // NOT OK
u !== undefined && u !== null; // NOT OK
!(u === undefined) && !(u === null); // NOT OK
u === undefined || u === null; // NOT OK
!(u === undefined || u === null); // NOT OK
!(u === undefined) && u !== null; // NOT OK
u != undefined && u != null; // $ Alert
u == undefined || u == null; // $ Alert
u !== undefined && u !== null; // $ Alert
!(u === undefined) && !(u === null); // $ Alert
u === undefined || u === null; // $ Alert
!(u === undefined || u === null); // $ Alert
!(u === undefined) && u !== null; // $ Alert
u !== undefined && n !== null;
u == undefined && u == null; // NOT OK
u == undefined && u == null; // $ Alert
x == undefined && x == null;
x === undefined && x === null; // NOT OK
x === undefined && x === null; // $ Alert
if (x === undefined) {
if (x === null) { // NOT OK
if (x === null) { // $ Alert
}
}
@@ -153,16 +153,16 @@
}
}
x != undefined && x != null; // NOT OK
x != undefined && x != null; // $ Alert
if (x != undefined) {
if (x != null) { // NOT OK
if (x != null) { // $ Alert
}
}
if (typeof x !== undefined);
if (typeof window !== undefined);
if (typeof x !== x);
if (typeof x !== u); // NOT OK
if (typeof x !== u); // $ Alert
if (typeof window !== "undefined");
if (typeof module !== "undefined");
@@ -174,8 +174,8 @@
u && (f(), u.p);
u && (u.p, f()); // technically not OK, but it seems like an unlikely pattern
u && !u.p; // NOT OK
u && !u(); // NOT OK
u && !u.p; // $ Alert
u && !u(); // $ Alert
function hasCallbacks(success, error) {

View File

@@ -1,7 +1,7 @@
(function(){
var v;
(function(){
if(typeof v === "undefined"){ // NOT OK
if(typeof v === "undefined"){ // $ Alert
v = 42;
}
for(var v in x){
@@ -9,10 +9,10 @@
});
});
const isFalsyObject = (v) => typeof v === 'undefined' && v !== undefined; // OK
const isFalsyObject = (v) => typeof v === 'undefined' && v !== undefined;
function f(v) {
if (typeof v === 'undefined' && v !== undefined) { // OK
if (typeof v === 'undefined' && v !== undefined) {
doSomething(v);
}
}

View File

@@ -42,14 +42,13 @@ function ok10(o, p) {
return p in o&&o[p];
}
// OK
x==y ** 2;
// NOT OK
x + x >> 1
x + x >> 1 // $ Alert
// OK
x + x >> 1
// OK (asm.js-like)
// OK - asm.js-like
x = x - 1|0;