Codelyzer: Rules to enforce template syntax

Created on 2 Jun 2017  路  3Comments  路  Source: mgechev/codelyzer

Would it be possible/relevant to add rules that check the syntax of angular templates?
Ideas:

  • ensure whitespaces in interpolation {{ value }}
  • ensure whitespaces around pipe operator {{ value | pipe }}
  • ensure whitespaces after semicolon in structural dir*ngIf="condition; else"
  • check banana-box syntax [()] vs ([])
  • check for unused template-ref <div #unusedRef></div>
enhancement help wanted P2

Most helpful comment

Hey @QuentinFchx good ideas!

  • ensure whitespaces in interpolation {{ value }}
  • ensure whitespaces around pipe operator {{ value | pipe }}
  • ensure whitespaces after semicolon in structural dir*ngIf="condition; else"

Doable with the TemplateVisitor.

  • check banana-box syntax [()] vs ([])

Sounds like a good fit for the TemplateVisitor as well. It also feels like a good candidate for a compile-time error.

  • check for unused template-ref

The current shallow linting doesn't deal well with template references but that's another good candidate.

All 3 comments

Hey @QuentinFchx good ideas!

  • ensure whitespaces in interpolation {{ value }}
  • ensure whitespaces around pipe operator {{ value | pipe }}
  • ensure whitespaces after semicolon in structural dir*ngIf="condition; else"

Doable with the TemplateVisitor.

  • check banana-box syntax [()] vs ([])

Sounds like a good fit for the TemplateVisitor as well. It also feels like a good candidate for a compile-time error.

  • check for unused template-ref

The current shallow linting doesn't deal well with template references but that's another good candidate.

Three of the rules are already implemented. I will open two issues to track the remaining two.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidanaya picture davidanaya  路  4Comments

damsorian picture damsorian  路  3Comments

Umayalmuthupalaniappan picture Umayalmuthupalaniappan  路  5Comments

Bigous picture Bigous  路  4Comments

lazarljubenovic picture lazarljubenovic  路  4Comments