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

@@ -1,50 +1,50 @@
angular.module('myModule', [])
.controller('MyController', function($scope) {
$scope.$on('destroy', cleanup); // BAD
$scope.$on('destroy', cleanup); // $ Alert
})
.controller('MyController', ["$scope", function(s) {
s.$on('destroy', cleanup); // BAD
s.$on('destroy', cleanup); // $ Alert
}])
.controller('MyController', function($scope) {
var destroy = 'destroy';
$scope.$on(destroy, cleanup); // BAD
$scope.$on(destroy, cleanup); // $ Alert
})
.controller('MyController', function($scope) {
$scope.$on('$destroy', cleanup); // GOOD
$scope.$on('$destroy', cleanup);
})
.controller('MyController', function($scope) {
$scope.$emit('foo');
$scope.$on('foo', cleanup); // GOOD
$scope.$on('foo', cleanup);
})
.controller('MyController', function($scope) {
$scope.$on('bar', cleanup); // BAD
$scope.$on('bar', cleanup); // $ Alert
})
.controller('MyController', function($scope) {
$scope.$on('$locationChangeStart', cleanup); // OK
$scope.$on('$locationChangeStart', cleanup);
})
.controller('MyController', function($scope) {
$scope.$on('lib1.foo', cleanup); // OK
$scope.$on('lib1.foo', cleanup);
})
.controller('MyController', function($scope) {
$scope.$on('lib2:foo', cleanup); // OK
$scope.$on('lib2:foo', cleanup);
})
.controller('MyController', function($scope) {
$scope.$on('onClick', cleanup); // OK
$scope.$on('onClick', cleanup);
})
.controller('MyController', function($scope) {
function f($scope){
$scope.$emit('probablyFromUserCode1')
}
$scope.$on('probablyFromUserCode1', cleanup); // OK
$scope.$on('probablyFromUserCode1', cleanup);
})
.controller('MyController', function($scope) {
function f($scope){
var scope = $scope;
scope.$emit('probablyFromUserCode2')
}
$scope.$on('probablyFromUserCode2', cleanup); // OK
$scope.$on('probablyFromUserCode2', cleanup);
})
.controller('MyController', function($scope) {
$scope.$on('event-from-AngularJS-expression', cleanup); // GOOD
$scope.$on('event-from-AngularJS-expression', cleanup);
})
;

View File

@@ -1,36 +1,36 @@
angular.module('app1', [])
.run(['dep1', 'dep2', 'dep3', function(dep1, dep3, dep2) {}]); // NOT OK
.run(['dep1', 'dep2', 'dep3', function(dep1, dep3, dep2) {}]); // $ Alert
angular.module('app2')
.directive('mydirective', [ '$compile', function($compile, $http) { // NOT OK
.directive('mydirective', [ '$compile', function($compile, $http) { // $ Alert
// ...
}]);
angular.module('app1', [])
.run(['dep1', 'dep2', 'dep3', function(dep1, dep2, dep3) {}]); // OK
.run(['dep1', 'dep2', 'dep3', function(dep1, dep2, dep3) {}]);
angular.module('app2')
.directive('mydirective', [ '$compile', '$http', function($compile, $http) { // OK
.directive('mydirective', [ '$compile', '$http', function($compile, $http) {
// ...
}]);
angular.module('app3', [])
.run(function(dep1, dep3) {}); // OK
.run(function(dep1, dep3) {});
angular.module('app4')
.directive('mydirective', function($compile, $http) { // OK
.directive('mydirective', function($compile, $http) {
// ...
});
angular.module('app5')
.directive('mydirective', [ 'fully.qualified.name', function(name) { // OK
.directive('mydirective', [ 'fully.qualified.name', function(name) {
// ...
}])
angular.module('app6')
.directive('mydirective', function() {
return {
link: function (scope, element, attrs) { // OK
link: function (scope, element, attrs) {
}
};
});

View File

@@ -1,17 +1,17 @@
angular.module('app', [])
.config(function($sceProvider) {
$sceProvider.enabled(false); // BAD
$sceProvider.enabled(false); // $ Alert
})
.config(['otherProvider', function($sceProvider) {
$sceProvider.enabled(false); // OK
$sceProvider.enabled(false);
}])
.config(['$sceProvider', function(x) {
x.enabled(false); // BAD
x.enabled(false); // $ Alert
}])
.config(function($sceProvider) {
$sceProvider.enabled(true); // OK
$sceProvider.enabled(true);
})
.config(function($sceProvider) {
var x = false;
$sceProvider.enabled(x); // BAD
$sceProvider.enabled(x); // $ Alert
});

View File

@@ -11,68 +11,68 @@ angular.module('myModule', [])
;
angular.module('myModule2', [])
.controller('c0', function(factoryId){}) // OK
.controller('c1', function(serviceId){}) // OK
.controller('c2', function(valueId){}) // OK
.controller('c3', function(constantId){}) // OK
.controller('c4', function(providerId){}) // OK
.controller('c5', function($http){}) // OK
.controller('c6', function($provider){}) // NOT OK
.controller('c7', function($scope){}) // OK
.controller('c8', function($compile){}) // OK
.controller('c9', function(UNKNOWN){}) // OK
.controller('c10', function(providerIdProvider){}) // NOT OK
.controller('c11', function(providerIdProvider, UNKNOWN){}) // NOT OK, but only one error
.controller('c12', function($provide){}) // OK (special case)
.controller('c13', function(providerId2Provider){}) // NOT OK
.controller('c0', function(factoryId){})
.controller('c1', function(serviceId){})
.controller('c2', function(valueId){})
.controller('c3', function(constantId){})
.controller('c4', function(providerId){})
.controller('c5', function($http){})
.controller('c6', function($provider){}) // $ Alert
.controller('c7', function($scope){})
.controller('c8', function($compile){})
.controller('c9', function(UNKNOWN){})
.controller('c10', function(providerIdProvider){}) // $ Alert
.controller('c11', function(providerIdProvider, UNKNOWN){}) // $ Alert - but only one error
.controller('c12', function($provide){}) // OK - special case
.controller('c13', function(providerId2Provider){}) // $ Alert
.factory('s0', function(factoryId){}) // OK
.factory('s1', function(serviceId){}) // OK
.factory('s2', function(valueId){}) // OK
.factory('s3', function(constantId){}) // OK
.factory('s4', function(providerId){}) // OK
.factory('s5', function($http){}) // OK
.factory('s6', function($provider){}) // NOT OK
.factory('s7', function($scope){}) // NOT OK
.factory('s8', function($compile){}) // OK
.factory('s9', function(UNKNOWN){}) // OK
.factory('s10', function(providerIdProvider){}) // NOT OK
.factory('s11', function(providerIdProvider, UNKNOWN){}) // NOT OK, but only one error
.factory('s12', function($provide){}) // OK (special case)
.factory('s13', function(providerId2Provider){}) // NOT OK
.factory('s0', function(factoryId){})
.factory('s1', function(serviceId){})
.factory('s2', function(valueId){})
.factory('s3', function(constantId){})
.factory('s4', function(providerId){})
.factory('s5', function($http){})
.factory('s6', function($provider){}) // $ Alert
.factory('s7', function($scope){}) // $ Alert
.factory('s8', function($compile){})
.factory('s9', function(UNKNOWN){})
.factory('s10', function(providerIdProvider){}) // $ Alert
.factory('s11', function(providerIdProvider, UNKNOWN){}) // $ Alert - but only one error
.factory('s12', function($provide){}) // OK - special case
.factory('s13', function(providerId2Provider){}) // $ Alert
.run(function(factoryId){}) // OK
.run(function(serviceId){}) // OK
.run(function(valueId){}) // OK
.run(function(constantId){}) // OK
.run(function(providerId){}) // OK
.run(function($http){}) // OK
.run(function($provider){}) // NOT OK
.run(function($scope){}) // NOT OK
.run(function($compile){}) // OK
.run(function(UNKNOWN){}) // OK
.run(function(providerIdProvider){}) // NOT OK
.run(function(providerIdProvider, UNKNOWN){}) // NOT OK, but only one error
.run(function($provide){}) // OK (special case)
.run(function(providerId2Provider){}) // NOT OK
.run(function(factoryId){})
.run(function(serviceId){})
.run(function(valueId){})
.run(function(constantId){})
.run(function(providerId){})
.run(function($http){})
.run(function($provider){}) // $ Alert
.run(function($scope){}) // $ Alert
.run(function($compile){})
.run(function(UNKNOWN){})
.run(function(providerIdProvider){}) // $ Alert
.run(function(providerIdProvider, UNKNOWN){}) // $ Alert - but only one error
.run(function($provide){}) // OK - special case
.run(function(providerId2Provider){}) // $ Alert
.config(function(factoryId){}) // NOT OK
.config(function(serviceId){}) // NOT OK
.config(function(valueId){}) // NOT OK
.config(function(constantId){}) // OK
.config(function(providerId){}) // NOT OK
.config(function($http){}) // NOT OK
.config(function($provider){}) // OK
.config(function($scope){}) // NOT OK
.config(function($compile){}) // OK
.config(function(UNKNOWN){}) // OK
.config(function(providerIdProvider){}) // OK
.config(function(providerId, UNKNOWN){}) // NOT OK, but only one error
.config(function($provide){}) // OK (special case)
.config(function(valueId2){}) // NOT OK
.config(function(factoryId){}) // $ Alert
.config(function(serviceId){}) // $ Alert
.config(function(valueId){}) // $ Alert
.config(function(constantId){})
.config(function(providerId){}) // $ Alert
.config(function($http){}) // $ Alert
.config(function($provider){})
.config(function($scope){}) // $ Alert
.config(function($compile){})
.config(function(UNKNOWN){})
.config(function(providerIdProvider){})
.config(function(providerId, UNKNOWN){}) // $ Alert - but only one error
.config(function($provide){}) // OK - special case
.config(function(valueId2){}) // $ Alert
// service: same restrcitions as .factory
.service('s14', function(factoryId){}) // OK
.service('s15', function($provider){}) // NOT OK
.service('s14', function(factoryId){})
.service('s15', function($provider){}) // $ Alert
;

View File

@@ -1,24 +1,24 @@
angular.module('myApp', [])
.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
"**://example.com/*", // BAD (exploit: http://evil.com/?ignore=://example.org/a or javascript:alert(1);://example.org/a)
"*://example.org/*", // BAD (exploit: javascript://example.org/a%0A%0Dalert(1) using a linebreak to end the comment starting with "//"!)
"https://**.example.com/*", // BAD (exploit: https://evil.com/?ignore=://example.com/a)
"https://example.**", // BAD (exploit: https://example.evil.com or http://example.:foo@evil.com)
"https://example.*", // BAD (exploit: https://example.UnexpectedTLD)
"**://example.com/*", // $ Alert - (exploit: http://evil.com/?ignore=://example.org/a or javascript:alert(1);://example.org/a)
"*://example.org/*", // $ Alert - (exploit: javascript://example.org/a%0A%0Dalert(1) using a linebreak to end the comment starting with "//"!)
"https://**.example.com/*", // $ Alert - exploit: https://evil.com/?ignore=://example.com/a
"https://example.**", // $ Alert - exploit: https://example.evil.com or http://example.:foo@evil.com
"https://example.*", // $ Alert - exploit: https://example.UnexpectedTLD
"https://example.com", // OK
"https://example.com/**", // OK
"https://example.com/*", // OK
"https://example.com/foo/*", // OK
"https://example.com/foo/**", // OK
"https://example.com/foo/*/bar", // OK
"https://example.com/foo/**/bar", // OK
"https://example.com/?**", // OK
"https://example.com/?**://example.com", // OK
"https://example.com",
"https://example.com/**",
"https://example.com/*",
"https://example.com/foo/*",
"https://example.com/foo/**",
"https://example.com/foo/*/bar",
"https://example.com/foo/**/bar",
"https://example.com/?**",
"https://example.com/?**://example.com",
"https://*.example.com",
// not flagged:
/http:\/\/www.example.org/g // BAD (exploit http://wwwaexample.org (dots are not escaped))
/http:\/\/www.example.org/g // $ Alert - (exploit http://wwwaexample.org (dots are not escaped))
]);
});

View File

@@ -1,27 +1,27 @@
(function(){
function injected1(name){} // NOT OK
function injected1(name){} // $ Alert
angular.module('app1').controller('controller1', injected1);
function injected2(name){} // OK
function injected2(name){}
injected2.$inject = ['name'];
angular.module('app2').controller('controller2', injected2);
function injected3(name){} // OK
function injected3(name){}
angular.module('app3').controller('controller3', ['name', injected3]);
angular.module('app4').controller('controller4', function(){}); // OK
angular.module('app4').controller('controller4', function(){});
angular.module('app5').controller('controller5', function(name){}); // NOT OK
angular.module('app5').controller('controller5', function(name){}); // $ Alert
function injected6(){} // OK
function injected6(){}
angular.module('app6').controller('controller6', injected6);
function notInjected7(name){} // OK
function notInjected7(name){}
var obj7 = {
controller: notInjected7
};
function injected8(name){} // OK (false negative: we do not track through properties)
function injected8(name){} // OK - false negative: we do not track through properties
var obj8 = {
controller: injected8
};
@@ -29,14 +29,14 @@
var $injector = angular.injector();
function injected9(name){} // NOT OK
function injected9(name){} // $ Alert
$injector.invoke(injected9)
function injected10(name){} // OK
function injected10(name){}
injected10.$inject = ['name'];
$injector.invoke(injected10)
function injected11(name){} // OK
function injected11(name){}
$injector.invoke(['name', injected11])
})();

View File

@@ -1,36 +1,36 @@
(function(){
function $Injected1(name){} // OK
function $Injected1(name){}
$Injected1.$inject = ['name'];
angular.module('app1').controller('controller1', $Injected1);
function $Injected2(name){} // NOT OK
function $Injected2(name){} // $ Alert
$Injected2.$inject = ['name'];
angular.module('app2').controller('controller2', ['name', $Injected2]);
function $Injected3(name){} // NOT OK
function $Injected3(name){} // $ Alert
$Injected3.$inject = ['name'];
$Injected3.$inject = ['name'];
angular.module('app3').controller('controller3', $Injected3);
function not$Injected4(name){} // OK
function not$Injected4(name){}
angular.module('app4').controller('controller4', not$Injected4);
function not$Injected5(name){} // OK
function not$Injected5(name){}
angular.module('app5').controller('controller5', ['name', not$Injected5]);
function $Injected6(name){} // OK (because it never becomes registered)
function $Injected6(name){} // OK - because it never becomes registered
$Injected6.$inject = ['name'];
$Injected6.$inject = ['name'];
function not$Injected7(name){} // OK
function not$Injected7(name){}
angular.module('app7').controller('controller7', ['name', not$Injected7]);
angular.module('app7').controller('controller7', ['name', not$Injected7]);
angular.module('app7').controller('controller7', not$Injected7);
angular.module('app8').controller('controller8', function inline8(name){}); // OK
angular.module('app8').controller('controller8', function inline8(name){});
angular.module('app9').controller('controller9', ['name', function inline9(name){}]); // OK
angular.module('app9').controller('controller9', ['name', function inline9(name){}]);
function $Injected10(name){ // NOT OK (alert formatting for multi-line function)
function $Injected10(name){ // $ Alert - alert formatting for multi-line function
}
$Injected10.$inject = ['name'];
angular.module('app10').controller('controller10', ['name', $Injected10]);

View File

@@ -1,28 +1,28 @@
(function(){
function f1(used2, unused5) {used2;} // OK (suppressed by js/unused-parameter)
function f1(used2, unused5) {used2;} // OK - suppressed by js/unused-parameter
// this function avoid suppression from js/unused-parameter by explicitly targeting one its weaknesses
function f2(unused7, used3) {used3;} // NOT OK
function f2(unused7, used3) {used3;} // $ Alert
this.f2 = f2;
angular.module('app1', [])
.run(function() {})
.run(function(unused1) {}) // OK (suppressed by js/unused-parameter)
.run(function(unused2, unused3) {}) // OK (suppressed by js/unused-parameter)
.run(function(used1, unused4) {used1;}) // OK (suppressed by js/unused-parameter)
.run(function(unused1) {}) // OK - suppressed by js/unused-parameter
.run(function(unused2, unused3) {}) // OK - suppressed by js/unused-parameter
.run(function(used1, unused4) {used1;}) // OK - suppressed by js/unused-parameter
.run(f1)
.run(["unused6", function() {}]) // NOT OK
.run(["unused6", function() {}]) // $ Alert
.run(f2)
.run(["used2", "unused9", function(used2) {}]) // NOT OK
.run(["unused10", "unused11", function() {}]) // NOT OK
.run(["used2", "unused12", function(used2) { // NOT OK (alert formatting for multi-line function)
.run(["used2", "unused9", function(used2) {}]) // $ Alert
.run(["unused10", "unused11", function() {}]) // $ Alert
.run(["used2", "unused12", function(used2) { // $ Alert - alert formatting for multi-line function
}])
;
})();
angular.module('app2')
.directive('mydirective', function() {
return {
link: function (scope, element, attrs) { // OK
link: function (scope, element, attrs) {
}
};
});

View File

@@ -4,13 +4,12 @@
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body>
<!-- BAD -->
<a href="{{help_url}}">Help</a>
<a href="{{help_url}}">Help</a> <!-- $ Alert -->
<picture>
<source media="(min-width: 650px)" srcset="#/resources/pics-large/{{item._id}}">
<img src="#/resources/pics-default/{{item._id}}">
</picture>
<!-- GOOD -->
<a ng-href="{{help_url}}">Help</a>
<picture>
<source media="(min-width: 650px)" ng-srcset="#/resources/pics-large/{{item._id}}">

View File

@@ -1,4 +1,3 @@
<div x-ng-bind="I am here to make this seem like an AngularJS template">
<!-- BAD -->
<a href="{{help_url}}">Help</a>
<a href="{{help_url}}">Help</a> <!-- $ Alert -->
</div>

View File

@@ -1,4 +1,3 @@
<body ng-app>
<!-- BAD -->
<a href="{{help_url}}">Help</a>
<a href="{{help_url}}">Help</a> <!-- $ Alert -->
</body>

View File

@@ -1,2 +1,2 @@
// OK
// if you want a specific version so specifiy it in object below : version=XXX

View File

@@ -1,4 +1,4 @@
alert("hi!"); // NOT OK
x.alert("hi!"); // OK
new alert(); // OK
function alert() { } // OK
alert("hi!"); // $ Alert
x.alert("hi!");
new alert();
function alert() { }

View File

@@ -1,25 +1,19 @@
// OK: we don't know whether the two elements are added to the same document
// OK - we don't know whether the two elements are added to the same document
var div1 = <div id="theDiff"></div>;
var div2 = <div id="theDiff"></div>;
// not OK
<a href="http://semmle.com" href="https://semmle.com">Semmle</a>;
<a href="http://semmle.com" href="https://semmle.com">Semmle</a>; // $ Alert
// not OK
<a href="https://semmle.com" href="https://semmle.com">Semmle</a>;
<a href="https://semmle.com" href="https://semmle.com">Semmle</a>; // $ Alert
// not OK
<div id=""></div>;
<div id=""></div>; // $ Alert
<div id="a b"></div>;
// not OK
<a href="http://semmle.com" href={someValue()}>Semmle</a>;
<a href="http://semmle.com" href={someValue()}>Semmle</a>; // $ Alert
// OK
<div id={someOtherValue()}></div>;
// not OK
var div3 = <div><div id="theDiff"></div><div id="theDiff"></div></div>;
var div3 = <div><div id="theDiff"></div><div id="theDiff"></div></div>; // $ Alert
// not OK
var div4 = <div id="theDiff" id="theDiff"></div>;
var div4 = <div id="theDiff" id="theDiff"></div>; // $ Alert

View File

@@ -1,7 +1,7 @@
function foo() { return "noopener noreferrer"; }
var o = { rel: "noopener noreferrer "};
// OK
<a href="http://example.com" target="_blank" rel="noopener noreferrer">Example</a>;
<a href="http://example.com" target="_blank" rel="noreferrer">Example</a>;
<a href="http://example.com" target="_blank" rel="noopener">Example</a>;
@@ -9,42 +9,39 @@ var o = { rel: "noopener noreferrer "};
<a href="http://example.com" target="_blank" {...o}>Example</a>;
<a data-ng-href="https://example.com" target="_blank" rel="noopener">Example</a>;
// OK, because of constant URL
// OK - because of constant URL
<a href="http://example.com" target="_blank">Example</a>;
<a href="http://example.com" target="_blank" rel="nopoener">Example</a>;
<a data-ng-href="https://example.com" target="_blank">Example</a>;
// NOT OK, because of dynamic URL
<a href="{{X}}" target="_blank">Example</a>;
<a href="{{X}}" target="_blank">Example</a>; // $ Alert - because of dynamic URL
<a href="{{X}}" target="_blank" rel="nopoener">Example</a>;
<a data-ng-href="{{X}}" target="_blank">Example</a>;
function f() {
// OK
var a1 = $("<a/>", { href: "http://example.com" });
a1.attr("target", "_blank");
// OK
var a2 = $("<a/>", { href: "http://example.com" });
a2.attr("target", "_blank");
a2.attr(computedName(), "noopener");
// NOT OK
var a3 = $("<a/>", { href: "{{X}}" });
var a3 = $("<a/>", { href: "{{X}}" }); // $ Alert
a3.attr("target", "_blank");
// OK
var a4 = $("<a/>");
a4[f()] = g();
a4.attr("target", "_blank");
// NOT OK
var a5 = $("<a/>");
var a5 = $("<a/>"); // $ Alert
a5.attr("href", g());
a5.attr("target", "_blank");
}
// OK, because of dynamic URL with fixed host
// OK - because of dynamic URL with fixed host
<a href="https://example.com/{{X}}" target="_blank">Example</a>;
<a href="https://ex-ample.com/{{X}}" target="_blank">Example</a>;
<a href="HTTPS://EXAMPLE.COM/{{X}}" target="_blank">Example</a>;
@@ -52,20 +49,20 @@ function f() {
<a href="//example.com/{{X}}" target="_blank">Example</a>;
<a href="//www.example.com/{{X}}" target="_blank">Example</a>;
// OK, because of dynamic URL with relative path
// OK - because of dynamic URL with relative path
<a href="./{{X}}" target="_blank">Example</a>;
<a href="../{{X}}" target="_blank">Example</a>;
<a href="index.html/{{X}}" target="_blank">Example</a>;
<a href="../index.html/{{X}}" target="_blank">Example</a>;
<a href="/{{X}}" target="_blank">Example</a>;
// OK, Flask application with internal links
// OK - Flask application with internal links
<a href="{{url_for('foo.html', 'foo')}}" target="_blank">Example</a>;
<a href="{{ url_for('foo.html', 'foo')}}" target="_blank">Example</a>;
<a href="{{ url_for('foo.html', 'foo')}}" target="_blank">Example</a>;
// OK, nunjucks template
// OK - nunjucks template
<a href="{{ url('foo', query={bla}) }}" target="_blank">Example</a>;
// OK, Django application with internal links
// OK - Django application with internal links
<a href="{% url 'admin:auth_user_changelist' %}" target="_blank">Example</a>

View File

@@ -1,10 +1,10 @@
function f() {
if (arguments[0].isArray())
arguments = arguments[0]; // NOT OK
arguments = arguments[0]; // $ Alert
}
function g(x, y) {
var arguments = [y, x]; // NOT OK
var arguments = [y, x]; // $ Alert
}
(function (){

View File

@@ -1,3 +1,3 @@
declare function ambientArguments(arguments: string[]): string; // OK
declare function ambientArguments(arguments: string[]): string;
declare function ambientArgumentsVarArgs(...arguments: string[]): string; // OK
declare function ambientArgumentsVarArgs(...arguments: string[]): string;

View File

@@ -1,4 +1,3 @@
const C = 45;
// NOT OK
class C {}
class C {} // $ Alert

View File

@@ -1,4 +1,4 @@
// OK: `const` is block scoped in ECMAScript 2015
// OK - `const` is block scoped in ECMAScript 2015
function f() {
{
const val = 1;

View File

@@ -1,4 +1,3 @@
const C = 45;
// NOT OK
function C() {}
function C() {} // $ Alert

View File

@@ -1,2 +1,2 @@
// OK
const s = "there";

View File

@@ -1,23 +1,19 @@
const x = 23, y = 42;
// NOT OK
x = 42;
x = 42; // $ Alert
// NOT OK
y = 23;
y = 23; // $ Alert
// NOT OK
var y = -1;
var y = -1; // $ Alert
// NOT OK
++x;
++x; // $ Alert
var z = 56;
// OK
z = 72;
// OK
const s = "hi";
(function (){

View File

@@ -1,12 +1,11 @@
for (var iter in Iterator(aExtraHeaders)) {
// NOT OK
var key = iter[0], key = iter[1];
var key = iter[0], key = iter[1]; // $ Alert
xhr.setRequestHeader(key, value);
}
// OK
var tmp = f(),
tmp = tmp + 19;
// OK
var a, b, a = 42;

View File

@@ -1,31 +1,30 @@
// NOT OK
g = 23;
g = 23; // $ Alert
// OK
h = 23;
alert(h);
// OK
uid = 0;
function incr() {
return uid++;
}
// OK
function foo() {
var x;
x = 0;
}
// OK
onload = function() {}
// OK
global = 42;
// OK
prop = 42;
// OK
/*global otherGlobal*/
otherGlobal = 56;

View File

@@ -1,11 +1,11 @@
import dummy from 'dummy';
var key1 = "key1"; // OK
var key1 = "key1";
export class NoConstructor {
[key1] = 4;
}
var key2 = "key2"; // OK
var key2 = "key2";
export class WithConstructor {
[key2] = 4;

View File

@@ -1,16 +1,16 @@
import { Foo } from "./exportSymbol" // OK
import { Foo } from "./exportSymbol"
export interface FooMap {
[Foo]: number; // OK
[Foo]: number;
}
const Bar = "Bar"; // OK
const Bar = "Bar";
export interface BarMap {
[Bar]: number;
}
const Baz = "Baz"; // OK
const Baz = "Baz";
if (false) {
Baz;
@@ -18,7 +18,7 @@ if (false) {
function getBaz(): typeof Baz { return null; }
class C {} // OK
class C {}
if (false) {
C;

View File

@@ -1,5 +1,5 @@
var C1 = global.C1; // OK
var C2 = global.C2; // OK
var C1 = global.C1;
var C2 = global.C2;
class C extends C1 {}
export default class extends C2 {}

View File

@@ -1,3 +1,3 @@
var C1 = global.C1; // OK
var C1 = global.C1;
export default function(x=C1) {}

View File

@@ -1,4 +1,4 @@
const React = require('react'); // OK: used in `extends` clause below
const React = require('react'); // OK - used in `extends` clause below
class Foo extends React.Component {
}

View File

@@ -2,7 +2,7 @@ function f() {
let y = false;
for (const x of [1, 2, 3]) {
if (x > 0) {
y = true; // OK
y = true;
continue;
}
return;

View File

@@ -9,5 +9,5 @@ namespace a.b.q {
registerSomething(c);
function foo() {} // OK
function foo() {}
}

View File

@@ -1,13 +1,13 @@
export function foo() {
function bar(x: number): number; // OK
function bar(x: string): string; // OK
function bar(x: any) { // OK
function bar(x: number): number;
function bar(x: string): string;
function bar(x: any) {
return x;
}
function baz(x: number): number; // OK
function baz(x: string): string; // OK
function baz(x: any) { // NOT OK, overwritten before use
function baz(x: number): number;
function baz(x: string): string;
function baz(x: any) { // $ Alert - overwritten before use
return x;
}
baz = (x) => x;

View File

@@ -1,17 +1,15 @@
function f() {
// OK: initialization to default value
// OK - initialization to default value
var x = null, y = undefined, z;
x = {};
// NOT OK
y = 23;
y = 23; // $ Alert
y = 42;
for (var p in x)
y+p;
// OK: assignment to global
// OK - assignment to global
global = 42;
// NOT OK
var a = 23; a = 42;
// OK: captured variable
var a = 23; a = 42; // $ Alert
// OK - captured variable
var b = 42;
return function() {
return b%2
@@ -20,14 +18,14 @@ function f() {
function g() {
var x;
// OK
x = 23, x += 19;
// OK
var y = 42;
}
function h() {
// OK
var x = false;
try {
this.mayThrow();
@@ -37,7 +35,7 @@ function h() {
}
function k(data) {
// OK
for(var i=0;i<data.length;i++);
}
@@ -62,7 +60,7 @@ function p() {
var i;
for (i=0; i < 10; ++i) {
if (Math.random() > .5)
// OK
i = 23;
}
}
@@ -87,11 +85,11 @@ function s() {
var container = document.createElement("div"),
div = document.createElement("div");
doStuffWith(container, div);
// OK
container = div = null;
}
// OK: the function expression could be made anonymous, but it's not
// OK - the function expression could be made anonymous, but it's not
// worth flagging this as a violation
defineGetter(req, 'subdomains', function subdomains() {
var hostname = this.hostname;
@@ -103,7 +101,7 @@ defineGetter(req, 'subdomains', function subdomains() {
return subdomains.slice(offset);
});
// OK: assigning default values
// OK - assigning default values
function t() {
var x;
x = false;
@@ -112,7 +110,7 @@ function t() {
x = 42; return x;
}
// OK: unnecessary initialisation as type hint
// OK - unnecessary initialisation as type hint
function u() {
var x;
x = [];
@@ -120,7 +118,7 @@ function u() {
x = 42; return x;
}
// OK: assigning `undefined`
// OK - assigning `undefined`
function v() {
var x;
x = void 0;
@@ -134,7 +132,7 @@ function v() {
return x;
}
// OK: assignments in dead code not flagged
// OK - assignments in dead code not flagged
!function() {
return;
var x;
@@ -159,7 +157,7 @@ function v() {
});
(function() {
let [x] = [0], // OK, but flagged due to destructuring limitations
let [x] = [0], // $ SPURIOUS: Alert - flagged due to destructuring limitations
y = 0;
x = 42;
y = 87;

View File

@@ -1,5 +1,5 @@
function outer(b) {
// OK
let addSubdomain = false;
if (x) {
@@ -16,14 +16,13 @@ function outer(b) {
}
function f(event) {
// OK
var message = event.data;
eme.init().then(() => NativeInfo.processApp('install', message.id));
}
function g() {
// NOT OK
let x = 23;
let x = 23; // $ Alert
{
x = 42;
}

View File

@@ -1,2 +1 @@
// NOT OK
exports = module.exports = { a: 23 };
exports = module.exports = { a: 23 }; // $ Alert

View File

@@ -1,2 +1 @@
// NOT OK
module.exports = exports = { a: 23 };
module.exports = exports = { a: 23 }; // $ Alert

View File

@@ -1,7 +1,7 @@
class C {
static get foo() {} // OK
static set foo(v) {} // OK
static get foo() {}
static set foo(v) {}
get bar() {} // OK
set bar(v) {} // OK
get bar() {}
set bar(v) {}
}

View File

@@ -1,3 +1,3 @@
var exports = module.exports;
exports.answer = "yes"; // NOT OK
exports.answer = "yes"; // $ Alert
exports.answer = "no";

View File

@@ -1,5 +1,5 @@
class C {
f; // OK
f;
constructor() {
this.f = 5;
@@ -7,7 +7,7 @@ class C {
}
class D {
f = 4; // NOT OK
f = 4; // $ Alert
constructor() {
this.f = 5;
@@ -15,7 +15,7 @@ class D {
}
class G {
constructor(public h: string) { // NOT OK
constructor(public h: string) { // $ Alert
this.h = h;
}
}

View File

@@ -2,7 +2,7 @@
var o = f1();
while (f2()) {
if (f4()) {
o.p = 42; // NOT OK
o.p = 42; // $ Alert
break;
}
f5();
@@ -12,8 +12,8 @@
(function(){
var o = f1();
o.p1 = o.p1 += 42; // NOT OK
o.p2 -= (o.p2 *= 42); // NOT OK
o.p1 = o.p1 += 42; // $ Alert
o.p2 -= (o.p2 *= 42); // $ Alert
});
(function(){
@@ -26,7 +26,7 @@
f3();
} catch (e) {
f4();
o.p = 42; // NOT OK
o.p = 42; // $ Alert
}
}
o.p = 42;
@@ -35,5 +35,5 @@
(function(){
var o = f1();
o.p = f2() ? o.p = f3() : f4(); // NOT OK
o.p = f2() ? o.p = f3() : f4(); // $ Alert
});

View File

@@ -1,26 +1,26 @@
(function(){
var o = {};
o.pure1 = 42; // NOT OK
o.pure1 = 42; // $ Alert
o.pure1 = 42;
o.pure2 = 42; // NOT OK
o.pure2 = 42; // $ Alert
o.pure2 = 43;
o.impure3 = 42;
f();
o.impure3 = 42;
o.pure4 = 42; // NOT OK
o.pure4 = 42; // $ Alert
43;
o.pure4 = 42;
o.impure5 = 42;
o.impure5 = f();
o.pure6 = f(); // NOT OK
o.pure6 = f(); // $ Alert
o.pure6 = 42;
o.pure7 = 42; // NOT OK
o.pure7 = 42; // $ Alert
if(x){}
o.pure7 = 42;
@@ -73,7 +73,7 @@
o15.pure15_aliasWrite = 42;
var o16 = x? o: null;
o.pure16_simpleAliasWrite = 42; // NOT OK
o.pure16_simpleAliasWrite = 42; // $ Alert
o16.pure16_simpleAliasWrite = 42;
var o17 = {
@@ -82,31 +82,31 @@
}
// DOM
o.clientTop = 42; // OK
o.clientTop = 42;
o.clientTop = 42;
o.defaulted1 = null; // OK
o.defaulted1 = null;
o.defaulted1 = 42;
o.defaulted2 = -1; // OK
o.defaulted2 = -1;
o.defaulted2 = 42;
var o = {};
o.pure18 = 42; // NOT OK
o.pure18 = 42; // NOT OK
o.pure18 = 42; // $ Alert
o.pure18 = 42; // $ Alert
o.pure18 = 42;
var o = {};
Object.defineProperty(o, "setter", { // OK
Object.defineProperty(o, "setter", {
set: function (value) { }
});
o.setter = "";
var o = { set setter(value) { } }; // OK
var o = { set setter(value) { } };
o.setter = "";
var o = {
set accessor(value) { }, // OK
set accessor(value) { },
get accessor() { }
};
@@ -115,24 +115,24 @@
o.setter = 87;
var o = {};
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1, value: getInitialValue()}) // NOT OK
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1, value: getInitialValue()}) // $ Alert
o.prop = 42;
var o = {};
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1, value: undefined}) // OK, default value
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1, value: undefined}) // OK - default value
o.prop = 42;
var o = {};
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1}) // OK
Object.defineProperty(o, "prop", {writable:!0,configurable:!0,enumerable:!1})
o.prop = 42;
var o = {};
o.pure19 = 42; // OK
o.pure19 = 42;
o.some_other_property = 42;
o.pure19 = 42;
var o = {};
o.pure20 = 42; // OK
o.pure20 = 42;
some_other_obj.some_other_property = 42;
o.pure20 = 42;
});

View File

@@ -1,8 +1,8 @@
/*global w, x:true*/
/* global y*/ // not a proper JSLint global declaration, but we (and JSHint) accept it anyway
/*global: z*/ // also not a proper global declaration
w; // OK
x; // OK
y; // not OK
z; // not OK
w;
x;
y; // $ Alert
z; // $ Alert
var x, y, z;

View File

@@ -1,11 +1,11 @@
function f(x) {
console.log(x); // OK
console.log(x);
}
console.log(x); // NOT OK
console.log(x); // $ Alert
var x = 1;
function g() {
console.log(y); // OK (not in same function)
console.log(y); // OK - not in same function
}
var y = 1;

View File

@@ -1,7 +1,7 @@
@Component(Foo) // OK
@Component(Foo)
class Foo {}
declare class Bar extends Baz {} // OK
declare class Bar extends Baz {}
declare class Baz {}
export type { I }; // OK - does not refer to the constant 'I'

View File

@@ -1,7 +1,6 @@
// NOT OK
var a, b, a = 42;
var a, b, a = 42; // $ Alert
// OK
var x;
var y;
var x;

View File

@@ -1 +1 @@
function getStuff(number) {} // OK: don't report anything related type annotations in .js files
function getStuff(number) {} // OK - don't report anything related type annotations in .js files

View File

@@ -1,36 +1,36 @@
import { MyType, x } from 'somewhere';
function join<T>(items: T[], callback: (T) => string) { // NOT OK: (T) should be (x:T)
function join<T>(items: T[], callback: (T) => string) { // $ Alert - (T) should be (x:T)
return items.map(callback).join(", ")
}
var box : <T>(T) => T[] = (x) => [x]; // NOT OK: (T) should be (x:T)
var box : <T>(T) => T[] = (x) => [x]; // $ Alert - (T) should be (x:T)
interface EventEmitter<T> {
addListener(listener: (T) => void): void; // NOT OK: (T) should be (x:T)
forwardFrom<S>(other: EventEmitter<S>, converter: (S) => T); // NOT OK: (S) should be (x:S)
addListener(listener: (T) => void): void; // $ Alert - (T) should be (x:T)
forwardFrom<S>(other: EventEmitter<S>, converter: (S) => T); // $ Alert - (S) should be (x:S)
}
interface NumberFormatter {
format(number): string; // NOT OK: (number) should be (x:number)
(number): string; // NOT OK: (number) should be (x:number)
format(number): string; // $ Alert - (number) should be (x:number)
(number): string; // $ Alert - (number) should be (x:number)
}
type TextFormatter = (NumberFormatter) => string; // NOT OK: (NumberFormatter) should be (x:NumberFormatter)
type TextFormatter = (NumberFormatter) => string; // $ Alert - (NumberFormatter) should be (x:NumberFormatter)
var myGlobal : MyType;
var myCallback: (MyType) => void; // NOT OK: (MyType) should be (x:MyType)
var myCallback: (MyType) => void; // $ Alert - (MyType) should be (x:MyType)
var myOtherCallback : (x) => void; // OK: nothing indicates that 'x' is a type name.
var myOtherCallback : (x) => void; // OK - nothing indicates that 'x' is a type name.
interface Repeated { x: number; }
interface Repeated { y: number; }
interface Repeated { z: number; }
type Callback = (Repeated) => void; // NOT OK: but should only be reported once
type Callback = (Repeated) => void; // $ Alert - but should only be reported once
class C {
getName(string) { // OK: parameter name is not part of signature
getName(string) { // OK - parameter name is not part of signature
return null;
}
}

View File

@@ -1,6 +1,6 @@
abstract class Audio3D {
setAudioStream() {
setAudioProperties(); // NOT OK
setAudioProperties(); // $ Alert
}
abstract setAudioProperties();

View File

@@ -1,6 +1,6 @@
class Audio3D {
setAudioStream() {
externs_setAudioProperties(); // OK
externs_setAudioProperties();
}
externs_setAudioProperties(){

View File

@@ -1,7 +1,7 @@
/*global setAudioProperties*/
class Audio3D {
setAudioStream() {
setAudioProperties(); // OK
setAudioProperties();
}
setAudioProperties(){

View File

@@ -1,9 +1,9 @@
class X {
m() {
m("default"); // OK
m("default");
}
resty(...x) {
m("default"); // NOT OK
m("default"); // $ Alert
}
}

View File

@@ -1,6 +1,6 @@
class Audio3D {
setAudioStream() {
setAudioProperties(); // NOT OK
setAudioProperties(); // $ Alert
}
setAudioProperties(){

View File

@@ -1,6 +1,6 @@
class Audio3D {
static setAudioStream() {
setAudioProperties(); // NOT OK
setAudioProperties(); // $ Alert
}

View File

@@ -1,39 +1,39 @@
class GlobalClass {
globalFunction(){
globalFunction(); // NOT OK
globalFunction() {
globalFunction(); // $ Alert
}
topNamespaceFunction(){
topNamespaceFunction(); // NOT OK
topNamespaceFunction() {
topNamespaceFunction(); // $ Alert
}
childNamespaceFunction(){
childNamespaceFunction(); // NOT OK
childNamespaceFunction() {
childNamespaceFunction(); // $ Alert
}
}
namespace Top {
class TopClass {
globalFunction(){
globalFunction(); // NOT OK
globalFunction() {
globalFunction(); // $ Alert
}
topNamespaceFunction(){
topNamespaceFunction(); // OK
topNamespaceFunction() {
topNamespaceFunction();
}
childNamespaceFunction(){
childNamespaceFunction(); // NOT OK, but not flagged since the namespace resolution is ignored
childNamespaceFunction() {
childNamespaceFunction(); // $ MISSING: Alert - not flagged since the namespace resolution is ignored
}
}
}
namespace Top.Child {
class ChildClass {
globalFunction(){
globalFunction(); // NOT OK
globalFunction() {
globalFunction(); // $ Alert
}
topNamespaceFunction(){
topNamespaceFunction(); // OK
topNamespaceFunction() {
topNamespaceFunction();
}
childNamespaceFunction(){
childNamespaceFunction(); // OK
childNamespaceFunction() {
childNamespaceFunction();
}
}
}
}

View File

@@ -2,7 +2,7 @@ function setAudioProperties(){}
class Audio3D {
setAudioStream() {
setAudioProperties(); // OK
setAudioProperties();
}

View File

@@ -1,7 +1,7 @@
/*global NOT_setAudioProperties*/
class Audio3D {
setAudioStream() {
setAudioProperties(); // NOT OK
setAudioProperties(); // $ Alert
}
setAudioProperties(){

View File

@@ -1,6 +1,6 @@
class Audio3D {
setAudioStream() {
this.setAudioProperties(); // OK
this.setAudioProperties();
}

View File

@@ -1,6 +1,6 @@
class Audio3D {
static setAudioStream() {
this.setAudioProperties(); // OK
this.setAudioProperties();
}

View File

@@ -2,26 +2,23 @@ var x;
function f(a) {
var sum = 0;
// NOT OK
for (i=0; i<a.length; ++i)
for (i=0; i<a.length; ++i) // $ Alert
sum += g(a[i]);
return sum;
}
function g(b) {
var prod = 1;
// NOT OK
for (i=0; i<b.length; ++i)
for (i=0; i<b.length; ++i) // $ Alert
prod *= b[i];
return prod;
}
function h() {
// OK: x is declared as a global in the same toplevel
// OK - x is declared as a global in the same toplevel
x = 23;
// NOT OK: y is not declared as a global in the same toplevel (though it is declared in test2.js)
y = 19;
// OK: console is live
y = 19; // $ Alert - y is not declared as a global in the same toplevel (though it is declared in test2.js)
// OK - console is live
console.log(x+y);
}
@@ -29,41 +26,38 @@ function k(x) {
try {
return x.y;
} catch(e) {
// OK: Error is not reachable (in our current CFG)
// OK - Error is not reachable (in our current CFG)
throw new Error();
}
}
function l() {
// OK: z is not used
// OK - z is not used
z = 56;
}
function m() {
// OK: z is live
// OK - z is live
z += 23;
}
function n() {
// OK: z is live
// OK - z is live
z = z + 23;
}
function p() {
// NOT OK
return (z = a[i]) && z+23;
return (z = a[i]) && z+23; // $ Alert
}
function q() {
// NOT OK
var x;
var x; // $ Alert
y = 23,
z = y+19;
}
function r() {
// NOT OK
z = {};
z = {}; // $ Alert
for (var p in z)
;
}

View File

@@ -3,6 +3,6 @@ abstract class Q {
static test() {}
method() {
this.test(); // OK
this.test();
}
}

View File

@@ -1,6 +1,6 @@
class Foo {
bar(){
this.baz; // OK
this.baz;
}
baz(){

View File

@@ -1,6 +1,6 @@
class Foo {
bar() {
this.baz; // OK
this.baz;
}
baz() {}
static baz() {}

View File

@@ -1,6 +1,6 @@
class Foo {
static bar(){
this.baz; // NOT OK
this.baz; // $ Alert
}
baz(){

View File

@@ -1,6 +1,6 @@
class Foo {
bar(){
this.baz; // NOT OK
this.baz; // $ Alert
}
static baz(){
}

View File

@@ -1,6 +1,6 @@
class Foo {
static bar(){
this.baz; // OK
this.baz;
}
static baz(){

View File

@@ -1,6 +1,6 @@
class Foo {
static bar() {
this.baz; // OK
this.baz;
}
static baz() {}
baz() {}

View File

@@ -1,6 +1,6 @@
class Foo {
bar(){
Foo.baz; // OK
Foo.baz;
}
static baz(){

View File

@@ -1,7 +1,7 @@
class C1 {
test() {
this.f = x;
this.f; // OK
this.f;
}
static f() {
@@ -12,7 +12,7 @@ class C1 {
class C2 {
static test() {
this.f = x;
this.f; // OK
this.f;
}
f() {
@@ -22,7 +22,7 @@ class C2 {
class C3 {
test() {
this.f; // OK
this.f;
}
static f() {
@@ -33,7 +33,7 @@ new C3().f = x;
class C4 {
static test() {
this.f; // OK
this.f;
}
f() {
@@ -52,7 +52,7 @@ class C5 extends C5_super{
}
test() {
this.f; // OK
this.f;
}
}
@@ -63,6 +63,6 @@ class C6_super {
}
class C6 extends C6_super{
static test() {
this.f; // NOT OK
this.f; // $ Alert
}
}

View File

@@ -1,4 +1,4 @@
// OK: people sometimes use multiple declarations in an externs file to represent multiple type signatures
// OK - people sometimes use multiple declarations in an externs file to represent multiple type signatures
var f = function() {};
var f = function(x) {};

View File

@@ -1,5 +1,5 @@
function f() {
// OK
var f;
}

View File

@@ -8,12 +8,12 @@ namespace N2 {
let y;
}
namespace N2 { // OK
namespace N2 {
var w;
}
function f(x: number): number;
function f(x: string): string; // OK
function f(x: any): any { // OK
function f(x: string): string;
function f(x: any): any {
return x;
}

View File

@@ -6,7 +6,7 @@ function f() {
f();
function f() { // NOT OK
function f() { // $ Alert
console.log("first declaration");
}

View File

@@ -1,22 +1,22 @@
function f() {
var x = 1;
var x = 2; // NOT OK
var x = 2; // $ Alert
}
function g(x) {
var x = 1; // NOT OK
var x = 1; // $ Alert
}
function h() {
var i = 1;
for (var i = 0; i < 10; i++) { // NOT OK
for (var i = 0; i < 10; i++) { // $ Alert
}
}
function k() {
var y = 1;
var x = 2,
y = 2; // NOT OK
y = 2; // $ Alert
}
var g;

View File

@@ -1,4 +1,4 @@
// OK: don't report anything in .js files.
// OK - don't report anything in .js files.
function getStuff(number) {
return {
"new": function() {

View File

@@ -1,11 +1,11 @@
var foo: MyInterface = 123 as any;
interface MyInterface {
function (): number; // OK. Highly unlikely that it is an accident when there are other named methods in the interface.
(): number; // OK: What was probably meant above.
new:() => void; // OK! This is a property, not a method, we ignore those.
constructor(): string; // NOT OK! This a called "constructor"
new(): Date; // OK! This a constructor signature.
function (): number; // OK - Highly unlikely that it is an accident when there are other named methods in the interface.
(): number; // OK - What was probably meant above.
new:() => void; // OK - This is a property, not a method, we ignore those.
constructor(): string; // $ Alert - This a called "constructor"
new(): Date; // OK - This a constructor signature.
myNumber: 123;
}
@@ -13,15 +13,15 @@ interface MyInterface {
var a : MyFunction = null as any;
interface MyFunction {
function(): number; // NOT OK!
function(): number; // $ Alert
}
class Foo {
new(): number { // OK! Highly unlikely that a developer confuses "constructor" and "new" when both are present.
new(): number { // OK - Highly unlikely that a developer confuses "constructor" and "new" when both are present.
return 123;
}
constructor() { // OK! This is a constructor.
constructor() { // OK - This is a constructor.
}
myString = "foobar"
@@ -34,18 +34,18 @@ class Foo {
var b : FunctionClass = new FunctionClass();
declare class FunctionClass {
function(): number; // NOT OK:
function(): number; // $ Alert
}
class Baz {
new(): Baz { // OK! When there is a method body I assume the developer knows what they are doing.
new(): Baz { // OK - When there is a method body I assume the developer knows what they are doing.
return null as any;
}
}
declare class Quz {
new(): Quz; // NOT OK! The developer likely meant to write constructor.
new(): Quz; // $ Alert - The developer likely meant to write constructor.
}
var bla = new Foo();

View File

@@ -1,27 +1,26 @@
function f() {
// NOT OK
s = null;
s = null; // $ Alert
let s = "hi";
// OK
s = "hello";
}
function g() {
// OK
s = null;
var s = "hi";
// OK
s = "hello";
}
function do_something() {
// OK
let foo;
let foo;
}
function do_something() {
// OK
let foo;
foo = "bar";
let foo;
@@ -29,7 +28,7 @@ function do_something() {
if (true) { // enter new scope, TDZ starts
const func = function () {
console.log(myVar); // OK!
console.log(myVar);
};
function otherfunc() {

View File

@@ -1,4 +1,4 @@
// OK: overly long parameter lists in external APIs aren't the fault of the externs definitions
// OK - overly long parameter lists in external APIs aren't the fault of the externs definitions
function f(a, b, c, d, e, f, g, h) {}
/** @externs */

View File

@@ -1,21 +1,21 @@
function f(
x,
x, // NOT OK
\u0078 // NOT OK
x, // $ Alert
\u0078 // $ Alert
) { return; }
this.addPropertyListener(prop.name, function(_, _, _, a) {
proxy.delegate = a.dao;
});
// OK: for strict mode functions, duplicate parameter names are a syntax error
// OK - for strict mode functions, duplicate parameter names are a syntax error
function f(x, y, x) {
'use strict';
}
function f(
x,
x // OK: empty function
x // OK - empty function
) { }
(a, a) => a + a; // OK: for strict mode functions, duplicate parameter names are a syntax error
(a, a) => a + a; // OK - for strict mode functions, duplicate parameter names are a syntax error

View File

@@ -17,9 +17,9 @@ var accessors = {
};
var clobbering = {
x: 23, // NOT OK: clobbered by `x: 56`
y: "hello", // NOT OK: clobbered by `"y": "world"`
x: 42, // NOT OK: clobbered by `x: 56`
x: 23, // $ Alert - clobbered by `x: 56`
y: "hello", // $ Alert - clobbered by `"y": "world"`
x: 42, // $ Alert - clobbered by `x: 56`
x: 56,
"y": "world"
}

View File

@@ -1,30 +1,30 @@
declare class Foobar {
method(foo: number): string;
method(foo: number): number; // NOT OK.
method(foo: number): number; // $ Alert
types1<T>(): T[]
types1(): any[] // NOT OK.
types1(): any[] // $ Alert
types2(): any[]
types2<T>(): T[] // OK!
types2<T>(): T[]
types3<T extends Array<T>>(t: T): number;
types3<T extends string>(t: T): number // OK!
types3<T extends string>(t: T): number
on(event: string, fn?: (event?: any, ...args: any[]) => void): Function;
on(event: string, fn?: (event?: any, ...args: any[]) => void): Function; // NOT OK.
on(event: string, fn?: (event?: any, ...args: any[]) => void): Function; // $ Alert
foo(this: string): string;
foo(this: number): number; // OK
foo(this: number): number;
bar(this: number): string;
bar(this: number): number; // NOT OK
bar(this: number): number; // $ Alert
}
declare class Base {
method(foo: number): string;
method(foo: number): number; // NOT OK.
method(foo: number): number; // $ Alert
overRiddenInSub(): string;
overRiddenInSub(): number;
@@ -49,13 +49,13 @@ interface Base2 {
method(): "bar";
}
// OK.
interface MultiInheritanceI extends Base1, Base2 {
method(): "foo";
method(): "bar";
}
// OK.
declare class MultiInheritanceC implements Base1, Base2 {
method(): "foo";
method(): "bar";

View File

@@ -1,3 +1,3 @@
import {B} from './B';
export let A: number = B+1; // NOT OK: `B` is not initialized if `B.ts` is imported first.
export let A: number = B+1; // $ Alert - `B` is not initialized if `B.ts` is imported first.

View File

@@ -2,4 +2,4 @@ import {A} from './A';
export let B: number = 100;
export let Q: number = A; // NOT OK: `A` is not initialized if `A.ts` is imported first.
export let Q: number = A; // $ Alert - `A` is not initialized if `A.ts` is imported first.

View File

@@ -1,3 +1,3 @@
import {B} from './B';
console.log(B) // OK: `B` does not import this file
console.log(B) // OK - `B` does not import this file

View File

@@ -1,4 +1,4 @@
import {B} from './exportCycleB';
export var A = 100;
export {B}; // OK: export binding does not immediately evaluate 'B'
export {B}; // OK - export binding does not immediately evaluate 'B'

View File

@@ -1,3 +1,3 @@
import {A} from './exportCycleA';
export let B = () => A; // OK: `A` is not used during initialization.
export let B = () => A; // OK - `A` is not used during initialization.

View File

@@ -3,5 +3,5 @@ import {B} from './safeB';
export let A = 100;
export function getSum() {
return A + B; // OK: not accessed from top-level
return A + B; // OK - not accessed from top-level
}

View File

@@ -3,5 +3,5 @@ import {A} from './safeA';
export let B = 20;
export function getProduct() {
return A * B; // OK: not accessed from top-level
return A * B; // OK - not accessed from top-level
}

View File

@@ -4,4 +4,4 @@ export interface TypeA {
field: TypeB
}
export let valueA = valueB; // OK: these imports are not cyclic at runtime
export let valueA = valueB; // OK - these imports are not cyclic at runtime

View File

@@ -12,10 +12,10 @@ class SingletonTreeModel implements ITreeModel {
isLeafNode(node: Node): node is LeafNode {
return node instanceof LeafNode;
}
isBranchNode(node: Node): node is BranchNode { // OK
isBranchNode(node: Node): node is BranchNode {
return false; // This model has no branches.
}
isValidNode(node: Node): boolean { // NOT OK
isValidNode(node: Node): boolean { // $ Alert
return Node != null; // woops
}
}

View File

@@ -1,7 +1,7 @@
class C {
constructor(public x: number) {} // OK
constructor(public x: number) {}
}
class D {
constructor(x: number) {} // NOT OK
constructor(x: number) {} // $ Alert
}

View File

@@ -1,3 +1,3 @@
function foo(this: void, x: number) { // OK: 'this' is not an ordinary parameter
function foo(this: void, x: number) { // OK - 'this' is not an ordinary parameter
return x;
}

View File

@@ -1,28 +1,26 @@
// OK
[1, , 3].forEach(function(elt, idx) {
console.log(idx + " is not omitted.");
});
// NOT OK
[1, , 3].forEach(function(elt, idx) {
[1, , 3].forEach(function(elt, idx) { // $ Alert
sum += elt;
});
// NOT OK
function f1(x, y) {
function f1(x, y) { // $ Alert
return y;
}
f1(23, 42);
// OK
function f2(x, y) {
return y;
}
[].map(f2);
// OK
function f3(x, y) {
return y;
}
@@ -30,11 +28,11 @@ function f3(x, y) {
var g = f3;
[].map(g);
// OK
define(function (require, exports, module) {
module.x = 23;
});
// OK: starts with underscore
// OK - starts with underscore
function f(_p) {
}

View File

@@ -1,18 +1,18 @@
function f(x, y) { // NOT OK
function f(x, y) { // $ Alert
return y;
}
function g(x, y) { // OK
function g(x, y) {
return y + arguments[0];
}
function h(x) { // OK
function h(x) {
function inner() {
x = 1;
}
}
// OK
/**
* @param {*} x the first argument, deliberately unused
* @param {*} y the second argument
@@ -21,8 +21,7 @@ function K(x, y) {
return y;
}
// NOT OK
/**
/** // $ Alert
* @param {*} x the first argument
* @param {*} y the second argument
*/
@@ -30,7 +29,7 @@ function K(x, y) {
return y;
}
// OK
/**
* @abstract
* @param {*} x the first argument

View File

@@ -1,4 +1,4 @@
import { h } from 'preact'; // OK - JSX element uses 'h' after babel compilation
import { q } from 'preact'; // NOT OK - not used
import { q } from 'preact'; // $ Alert - not used
export default (<div>Hello</div>);

View File

@@ -1,6 +1,6 @@
function sum(xs, i) {
var res = 0;
for(;i++<xs.length;) // NOT OK, but flagged by js/unused-index-variable
for(;i++<xs.length;) // $ Alert - but flagged by js/unused-index-variable
res += xs[0];
return res;
}

View File

@@ -1,13 +1,13 @@
import {actionHandler, actionHandlerFactory, actionHandlerFactoryProvider, actionHandlerFactoryProviderKind} from 'somewhere'; // OK: imports used as decorators
import {actionHandler, actionHandlerFactory, actionHandlerFactoryProvider, actionHandlerFactoryProviderKind} from 'somewhere'; // OK - imports used as decorators
@actionHandler
function fun() {} // OK: decorator might use the function
function fun() {} // OK - decorator might use the function
@actionHandlerFactory
class Class {} // OK: decorator might use the class
class Class {} // OK - decorator might use the class
@actionHandlerFactoryProvider
export class ExportedClass {} // OK: decorator might use the class
export class ExportedClass {} // OK - decorator might use the class
@actionHandlerFactoryProviderKind
enum Enum { plain } // OK: decorator might use the enum
enum Enum { plain } // OK - decorator might use the enum

View File

@@ -2,10 +2,9 @@
* @externs
*/
// NOT OK
var iAmUnused;
var iAmUnused; // $ Alert
// OK: used as a type
// OK - used as a type
/**
* @typedef string
*/

View File

@@ -1,3 +1,3 @@
import { h } from 'preact'; // NOT OK - not in scope of .babelrc file
import { h } from 'preact'; // $ Alert - not in scope of .babelrc file
export default (<div>Hello</div>);

View File

@@ -1,10 +1,10 @@
// OK: `SomeInterface` is used in an `implements` clause
// OK - `SomeInterface` is used in an `implements` clause
import SomeInterface from 'somewhere';
class SomeClass implements SomeInterface {
}
new SomeClass();
import SomethingElse from 'somewhere'; // OK: SomethingElse is used in a type
import SomethingElse from 'somewhere'; // OK - SomethingElse is used in a type
type T = `Now for ${SomethingElse}`;

View File

@@ -1,4 +1,4 @@
import { Foo, Bar } from "somewhere"; // OK
import { Foo, Bar } from "somewhere";
type FooBar<T> =
T extends [infer S extends Foo, ...unknown[]]

Some files were not shown because too many files have changed in this diff Show More