Here is the code that aims to exit the loop once the desired result is found by returning true
ngModel.$parsers.unshift(function (viewValue) {
let names = scope.vm.names;
_.find(names, function (elem) {
let name = elem.name;
if (name && viewValue) {
if (name.toLowerCase() === viewValue.toLowerCase()) {
ngModel.$setValidity('unique', false);
return true; // exit the loop
} else {
ngModel.$setValidity('unique', true);
}
}
});
return viewValue;
});
The code is functioning correctly as expected, but lint detects an error saying:
× Unnecessary 'else' after 'return'. (no-else-return)
27 | ngModel.$setValidity('unique', false);
28 | return true; // exit the loop
29 | } else {
| ^
30 | ngModel.$setValidity('unique', true);
31 | }
32 | }
Is there a way to prevent this error from showing up or can we enhance the code for a more efficient solution?