Skip to content

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

Open
alcuadrado wants to merge 3 commits intoajafff:masterfrom
alcuadrado:throwing-is-early-return
Open

Make early-exit consider throwing as an early exit#141
alcuadrado wants to merge 3 commits intoajafff:masterfrom
alcuadrado:throwing-is-early-return

Conversation

@alcuadrado
Copy link
Copy Markdown

@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.

1 participant