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

[Feature Request] Limiting template condition complexity #508

Closed
intellix opened this issue Feb 1, 2018 · 4 comments · Fixed by #509
Closed

[Feature Request] Limiting template condition complexity #508

intellix opened this issue Feb 1, 2018 · 4 comments · Fixed by #509
Assignees

Comments

@intellix
Copy link

intellix commented Feb 1, 2018

We've got a payment process with conditions to reveal different steps of said process to push the user through it. An example of an *ngIf condition for revealing the Card entry step to the user:

<div *ngIf="step === 'amount' || (step === 'card' && transaction.action !== 'iframe-sent' && transaction.action !== 'html-provided' && transaction.action !== 'redirect-to-url')">
  Enter your card details
</div>

This amount of condition complexity is dangerous because it's breakage can only be detected via E2E or Manual QA. During refactor another developer can completely break payments.

I think one way Codelyzer can help here is allowing us to limit the complexity of an *ngIf condition allowed in the view. The above example would throw that it's too complex and the condition needs to be moved into the Component class, of which can be unit tested:

get canShowCardStep() {
  return this.step === 'amount' || (this.step === 'card' && this.transaction.action !== 'iframe-sent' && this.transaction.action !== 'html-provided' && this.transaction.action !== 'redirect-to-url;
}
<div *ngIf="canShowCardStep">
  Enter your card details
</div>
@mgechev
Copy link
Owner

mgechev commented Feb 1, 2018

Love this feature request. Probably we can apply some version of cyclomatic complexity estimation.

@wKoza
Copy link
Collaborator

wKoza commented Feb 1, 2018

Love this feature request

I'm not surprised

@mgechev
Copy link
Owner

mgechev commented Feb 1, 2018

Here's a simple estimation of cyclomatic complexity implemented in go https://github.com/fzipp/gocyclo/blob/master/gocyclo.go. It should be easy to port it to the Angular expression/template ASTs.

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 a pull request may close this issue.

3 participants