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
Templates: location information from @angular/compiler is not always as expected #292
Comments
There isn't documentation from the Angular Team for usage of the compiler API, so everything we know/have implemented is based on just digging in and trying to figure stuff out. I will message the Angular tooling team and request a process for us to report and resolve these issues. |
From @rafaelss95 on an overlapping issue: As reported in mgechev/codelyzer#859, #205 (comment) and #269 (comment), column numbers are off by one. Sample: angular-eslint/packages/eslint-plugin-template/tests/rules/no-call-expression.test.ts Lines 44 to 45 in b7ea86c
I noticed that we have a hacky way to handle this in
angular-eslint/packages/eslint-plugin-template/src/rules/no-negated-async.ts Lines 57 to 58 in c8dd14c
|
Not only column is off by one (or sometimes two):
The line index can also be off:
|
I think this might have something to do with CRLF line endings. |
Thanks @kyliau! At the time you wrote this it hadn't actually been released :) It is now available on npm though and I have a PR in the works which enables that and preserveWhitespace. With those two we definitely seem to get more predictable location information, thanks a lot! If you could let us know your/the teams thoughts on HTML comment nodes (which will unblock #97) that would cover off everything for now Thanks again! |
Resolved in the newly published |
I upgraded my plugin and can confirm that all interpolation locations are correct now. Thanks. However, the location for data-binding is still off. <div [class]="
value
">
</div> As seen in the screenshot below, the location of the warning is: {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 3,
"column": 3
}
} <div [class]="
value
~
">
~~
</div> While, I expect the error to be under value: {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 9
}
} <div [class]="
value
~~~~~
">
</div> |
@JamesHenry Should I open an new bug issue with above report? |
Yes please |
I noticed that expressions with additional whitespaces lead to wrong reports of errors:
I created an examplatory test-case for the negated-async pipe which fails, even though it should obviously pass:
Note: This also affects BoundAttributes, not only Interpolations.
@angular-eslint/template-parser invokes @angular/compiler with preserveWhitespaces set to true:
I tried to debug the parser and it seems impossible to find the absolute positions in the actual sourcecode with preserveWhitespaces: true, because the source-property of the AST is trimmed before the compiler decides about the location of the processed source code fragment.
Is there a way to solve this issue? Simply switching it off leads to a lot off issues in other rules (I tried running all test cases in the project).
The text was updated successfully, but these errors were encountered: