From the course: ESLint: Checking for Syntax and Logic Errors

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Identifying problems in loops and conditionals

Identifying problems in loops and conditionals

From the course: ESLint: Checking for Syntax and Logic Errors

Start my 1-month free trial

Identifying problems in loops and conditionals

- [Instructor] The loops and conditionals section of index.js, starting on line 15, contains a couple of issues I want ESLint to flag. There's a for loop starting on line 19. As far as my editor is concerned, everything's fine there, but I can use ESLint to check if the direction of my iterator change makes sense given my condition. To do that, I use the for direction rule. Over in my ESLint rc file, I'll add for direction with the value of error. So that's in the rules section, and for dash direction, and error. Saving that, I'm going to go back to index.js and I have a new error flagged. So, if I move the pointer over that that tip text is going to point out that the update clause moved the variable in the wrong direction. So, my code starts at 10, and it checks for a value greater than zero, and increasing I after each loop. That creates an infinite loop, because I will never satisfy that ending condition. I'm…

Contents