angular-whitespace autofix broke the html document
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.
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?
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
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 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.
Also, what's your operating system? I remember we had similar issues on Windows.
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.
@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.
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 I believe @JamesHenry was working on prettier support for Angular (inline?) templates.
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
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>
Prettier just release 1.15 with support for Angular templates and fix spaces between the declaration and the interpolation.
angular-whitespace is now deprecated. So, we can close this issue.
Is still in the docs