codelyzer icon indicating copy to clipboard operation
codelyzer copied to clipboard

angular-whitespace autofix broke the html document

Open michaeljota opened this issue 8 years ago • 14 comments

The rule is to put spaces after and before the Angular interpolation ({{}}), but sometimes it removes and adds angular brakes on its own leaving something like this {{ { firstNam }}}. Notice there is even a missing char from the firstName variable.

michaeljota avatar Aug 21 '18 15:08 michaeljota

Thanks for sharing this problem! Are there any HTML entities in the template? Would you share a test case that we can use to debug the issue?

mgechev avatar Aug 21 '18 17:08 mgechev

I had this issue with some regular variables, when two or more interpolations were close, and I have to say it seems to reproduce more by using the translation key and pipe used by ngx-translation

michaeljota avatar Aug 21 '18 17:08 michaeljota

Update: This seems like is reproducible when the interpolation are not indented with the expected amount of spaces.

Input:

<div>
 {{ variable }} <!-- Just one space -->
</div>

Output:

<div>
 {{ { variabl }}} <!-- broken -->
</div>

I'll try to test more and give you a reproducible template, but seems like it was related to this.

michaeljota avatar Aug 21 '18 18:08 michaeljota

@michaeljota I tried to reproduce this and I hadn't success. Can you share some more info? Your tslint.json, codelyzer version, tslint version, angular version, etc.

rafaelss95 avatar Aug 22 '18 01:08 rafaelss95

Also, what's your operating system? I remember we had similar issues on Windows.

mgechev avatar Aug 22 '18 06:08 mgechev

I'm sorry I didn't reply earlier. My OS is Windows 10. I was using the cli with powershell, calling it from a npm script.

michaeljota avatar Sep 03 '18 14:09 michaeljota

@rafaelss95 I'm using latest of each, but Angular I'm using latest from 5.x. I don't sure if I can share the whole file, but it's just extending recommended, and for the rules of codelyzer the same, just copy pasted the recommended.

michaeljota avatar Sep 03 '18 14:09 michaeljota

Also, don't think is important, but using tslint-prettier to disable rules that Prettier can handle. Since Prettier can't handle html yet, this rule is not disabled.

michaeljota avatar Sep 03 '18 14:09 michaeljota

@michaeljota I believe @JamesHenry was working on prettier support for Angular (inline?) templates.

mgechev avatar Sep 03 '18 15:09 mgechev

Not just yet, I originally had it in the same PR as when I added inline style formatting, but the HTML formatting (in general) in Prettier is still a WIP, once that lands it will be straightforward to add inline template formatting for Angular Components.

You can subscribe to the general issue here: https://github.com/prettier/prettier/pull/4753

JamesHenry avatar Sep 03 '18 15:09 JamesHenry

Same thing here. Trying to setup prettier+codelyzer+stylelint. Not that easy so far.

tslint.json

{
  "rulesDirectory": ["node_modules/codelyzer"],
  "extends": ["angular-tslint-rules", "tslint-consistent-codestyle", "tslint-config-prettier"],
  "rules": {
    "array-type": [true, "array"],
    "ban": [
        true,
        "eval",
        "alert",
        "$",
        {
          "name": ["*", "forEach"],
          "message": "Use a regular for loop instead. Please check .find/.findIndex/.filter/.map/.some/.every if you are performing one of these operations."
        }
    ],
    "no-implicit-dependencies": false,
    "no-inferrable-types": false,
    "no-var-keyword": true,
    "no-var-requires": true,
    "object-literal-sort-keys": [
      true,
      "match-declaration-order",
      "shorthand-first"
    ],
    "ordered-imports": true,
    "typedef": [
      true,
      "call-signature",
      "parameter",
      "member-variable-declaration"
    ]
  }
}

"angular-tslint-rules": "^1.5.0", "codelyzer": "^4.4.4" "tslint: "^5.11.0" "tslint-config-prettier": "^1.15.0" "tslint-consistent-codestyle": "^1.13.3"

Input

              <mat-option *ngFor="let av_programa of av_programas" [(value)]="av_programa.Id" class="sizeTitle">
                {{av_programa.Name}}
              </mat-option>

Output

              <mat-option *ngFor="let av_programa of av_programas" [(value)]="av_programa.Id" class="sizeTitle">
               {{ {av_programa.Nam }}}
              </mat-option>

gaspardip avatar Sep 20 '18 23:09 gaspardip

Prettier just release 1.15 with support for Angular templates and fix spaces between the declaration and the interpolation.

michaeljota avatar Nov 07 '18 20:11 michaeljota

angular-whitespace is now deprecated. So, we can close this issue.

wKoza avatar Nov 25 '18 17:11 wKoza

Is still in the docs

jorgekleeen avatar Jul 03 '19 20:07 jorgekleeen