Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make early-exit consider throwing as an early exit #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alcuadrado
Copy link

@alcuadrado alcuadrado commented Feb 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant