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,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)