quick-lint-js

Find bugs in JavaScript programs.

E0108: 'in' disallowed in C-style for loop initializer

C-style for loops can have a expression the first ;-separated part. It is an error for the expression to use the in operator without parentheses:

for (let i = 'startAtOne' in opts ? 1 : 0;
     i < opts.count;
     ++i) {
  if (!processItem(data[i])) {
    break;
  }
}

To fix this error, surround the in expression with parentheses:

for (let i = ('startAtOne' in opts) ? 1 : 0;
     i < opts.count;
     ++i) {
  if (!processItem(data[i])) {
    break;
  }
}

Documentation for other errors