π Some Of The Common ESLint Errors and their solutions π
Error 1: import A should occur before import of B or function A should be placed after function B
Solution: Simply Put A on the upper side of B or placed function A after function B.
Solution: Simply Put A on the upper side of B or placed function A after function B.
2 min readMay 17, 2022
problem :
import B;
import A;solution:
import A;
import B;
Error 2: Use object destructuring
Solution: Destructure the Object
Solution: Destructure the Object
problem :
const action = this.state.action;solution:
const {action} = this.state;
Error 3: Expected a default case
Solution: Add a default case whenever you use switch cases
Solution: Add a default case whenever you use switch cases
problem :
switch (callFunction) {
case A:
Call function A;
break;
case B:
Call function B
break;
}solution:
switch (callFunction) {
case A:
Call function A;
break;
case B:
Call function B
break;
default:
break;
}
Error 4: Unexpected block statement surrounding arrow body
Solution: Fix arrow-body style problem
Solution: Fix arrow-body style problem
problem:
const selectedStudents = studentOptions.find((student) => {
return student.id === defaultstudentId;
});solution:
const selectedStudents = studentOptions.find((student) => student.id === defaultstudentId);
Error 5: Visible, non-interactive elements with click handlers must have at least one keyboard listener
Solution: you can use something like accessibleOnClick
Solution: you can use something like accessibleOnClick
problem:
<div
ref={dropdownRef}
className="d-flex align-items-center pointer"
onClick={toggleDropdown}
/>solution:
<div
ref={dropdownRef}
className="d-flex align-items-center pointer"
{...accessibleOnClick(toggleDropdown)}
/>
Error 6: Unnecessary else after return
Solution: Remove else condition and return without else condition
Solution: Remove else condition and return without else condition
problem:
compareTwoStrings(A: string, B: string) {
if (A==B) {
return true;
} else {
return false;
}
}solution:
compareTwoStrings(A: string, B: string) {
if (A==B) {
return true;
}
return false;
}
Error 7: data is already declared in the upper scope
Solution: Use alternate naming convention
Solution: Use alternate naming convention
problem:
if (err.response instanceof HttpException) {
const { data, status } = err.response;
throw new MicroserviceException(data, status);
}solution:
if (err.response instanceof HttpException) {
const { data: errorData, status } = err.response;
throw new MicroserviceException(errorData, status);
}
ESLint Rules: https://eslint.org/docs/rules/