Codelyzer: Whitespace rules in angular templates

Created on 9 May 2018  路  7Comments  路  Source: mgechev/codelyzer

the TSLint Whitespace rule can check for whitespace around operators, for example

if(foo===bar){return}  // TSLint missing whitespace error
const x=a?b:c;   //multiple TSLint missing whitespace errors

if(foo === bar){return} //no TSLint error
const x = a ? b : c; //no TSLint error

However, the codelyzer angular-whitespace rule does not catch this

<button *ngIf="foo===bar"
    [disabled]="checkCount()===0">
</button>  <!-- no TSLint error-->

Is there a way to catch this? Could the angular-whitespace rule be configured to piggyback off the whitespace rule, and enforce the same config options for code in angular templates as are used for the whitespace rule if it is configured?

Most helpful comment

Some people, such as Material2 team, doesn't like whitespaces between the interpolations, so it could be another improvement: add some configuration like never, so that would validate it to have no spaces.

All 7 comments

Following the feature request process that lodash has, I'm closing the issue and adding votes needed label.

Later we can prioritize the feature requests by popularity and include them in a future release.

Some people, such as Material2 team, doesn't like whitespaces between the interpolations, so it could be another improvement: add some configuration like never, so that would validate it to have no spaces.

Another example of where whitespace rule could be enforced:

<div [ngClass]="{foo:item.isFoo}"> <!-- should have space after colon -->

Thinking more about it... do we really want to messing with formatting rules in a linter? Well, while I can imagine how this rule could be useful in many cases, I really think it's more appropriated to left this kind of rule to a formatter, like Prettier*, for example.

IMHO, this project shouldn't mess with spaces and formatting in general. Formatting rules are always a pain and it also never satisfies every people.

* Sadly, Prettier still doesn't format HTML.

Update: Now you can use Prettier to format HTML :)

@mgechev Let's remove the votes needed label here?

@rafaelss95 you're a project collaborator. I believe you should have write access as well. Let me know if that's not the case so I can fix it.

@mgechev Ah, yes I have :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rolandjitsu picture rolandjitsu  路  5Comments

lazarljubenovic picture lazarljubenovic  路  4Comments

negberts picture negberts  路  3Comments

michaeljota picture michaeljota  路  4Comments

Umayalmuthupalaniappan picture Umayalmuthupalaniappan  路  5Comments