From the course: ESLint: Checking for Syntax and Logic Errors
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Calling out general logic errors
From the course: ESLint: Checking for Syntax and Logic Errors
Calling out general logic errors
- [Instructor] My index.js file contains a few test statements starting on line 63 that test for errors in logical tests. ESLint supports a number of rules for a range of potential logic issues, but I want to use a few specific ones. Line 63 contains a subtle error in the condition that I still find myself making on occasion. Instead of using a logical comparison operator, like triple equals, I used the assignment operator, a single equal sign. That means I won't have a comparison here, and my code won't do what I intended. ESLint supports the no-cond-assign rule to catch assignments in conditions. The default setting allows you to do assignment in a condition within a separate set of parentheses as a way of making your intention clearer. Using that default, I can set the value for this rule with a simple string. So, back in .eslintrc, I'm going to add another rule, no-cond-assign with a value of error, and then saving…