mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
JS: Update OK-style comments to $-style
This commit is contained in:
@@ -1,43 +1,38 @@
|
||||
// BAD: Loop upper bound is off-by-one
|
||||
for (var i = 0; i <= args.length; i++) {
|
||||
for (var i = 0; i <= args.length; i++) { // $ Alert - Loop upper bound is off-by-one
|
||||
console.log(args[i]);
|
||||
}
|
||||
|
||||
// BAD: Loop upper bound is off-by-one
|
||||
for (var i = 0; args.length >= i; i++) {
|
||||
for (var i = 0; args.length >= i; i++) { // $ Alert - Loop upper bound is off-by-one
|
||||
console.log(args[i]);
|
||||
}
|
||||
|
||||
// GOOD: Loop upper bound is correct
|
||||
// OK - Loop upper bound is correct
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
console.log(args[i]);
|
||||
}
|
||||
|
||||
var j = 0;
|
||||
// BAD: Off-by-one on index validity check
|
||||
if (j <= args.length) {
|
||||
if (j <= args.length) { // $ Alert - Off-by-one on index validity check
|
||||
console.log(args[j]);
|
||||
}
|
||||
|
||||
// BAD: Off-by-one on index validity check
|
||||
if (args.length >= j) {
|
||||
if (args.length >= j) { // $ Alert - Off-by-one on index validity check
|
||||
console.log(args[j]);
|
||||
}
|
||||
|
||||
// GOOD: Correct terminating value
|
||||
// OK - Correct terminating value
|
||||
if (args.length > j) {
|
||||
console.log(args[j]);
|
||||
}
|
||||
|
||||
// BAD: incorrect upper bound
|
||||
function badContains(a, elt) {
|
||||
function badContains(a, elt) { // $ Alert - incorrect upper bound
|
||||
for (let i = 0; i <= a.length; ++i)
|
||||
if (a[i] === elt)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// GOOD: correct upper bound
|
||||
// OK - correct upper bound
|
||||
function goodContains(a, elt) {
|
||||
for (let i = 0; i < a.length; ++i)
|
||||
if (a[i] === elt)
|
||||
@@ -53,7 +48,7 @@ function same(a, b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// GOOD: incorrect upper bound, but extra check
|
||||
// OK - incorrect upper bound, but extra check
|
||||
function badContains(a, elt) {
|
||||
for (let i = 0; i <= a.length; ++i)
|
||||
if (i !== a.length && a[i] === elt)
|
||||
|
||||
Reference in New Issue
Block a user