tslint-consistent-codestyle
tslint-consistent-codestyle copied to clipboard
Make early-exit consider throwing as an early exit
trafficstars
Hi @ajafff
Thanks for creating this package. I use multiple rules, which I find very useful.
I was considering enabling early-exit, but was surprised by tslint complaining about this pattern:
private _validateSomething(param: T) {
if (condition(param)) {
throw new InvalidParam(param);
}
}
I can refactor that into this, but it feels like making things more complex instead of simpler:
private _validateSomething(param: T) {
if (!condition(param)) {
return;
}
throw new InvalidParam(param);
}
So I modified this rule to consider throwing as an early exit.
I'm not 100% sure if what I did is correct, nor if the test I added actually works, but I preferred submitting this early to get your opinion about this change.