Lets say I have the following method:
getErrorMessage(state: any, thingName?: string) {
const thing: string = state.path || thingName;
const messages: string[] = [];
if (state.errors) {
for (const errorName in state.errors) {
switch (errorName) {
case 'required':
messages.push(`You must enter a ${thing}`);
break;
case 'minlength':
messages.push(`A ${thing} must be at least ${state.errors['minlength'].requiredLength}characters`);
break;
case 'pattern':
messages.push(`The ${thing} contains illegal characters`);
break;
case 'validateCardNumberWithAlgo':
messages.push(`Card doesnt pass algo`);
break;
}
}
}
return messages;
}
when I run
ng lint
I get the following error :
for (... in ...) statements must be filtered with an if statement
Having a look at similar question I don't think that answer would be applicable to my situation. After all switch statement sits in the category of if-else-if ladder.
tslint should consider switch statement as form of if statement but it doesn't?!
if
statement should come after thefor...in
, and a switch statement can be seen as a kind ofif
statement, yet it doesn't resolve the error. – Frank Modica