fix(eslint-plugin-template): [attributes-order] order i18n attributes #2307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1519
i18n attributes are not exposed in the template AST. Instead, the element or attribute that the i18n attribute is associated with has an
i18n
property that stores anI18nMeta
object, but that object does not define the span of the attribute, so it cannot be used to determine whether the attribute is in the correct order.This PR changes how attributes are sourced when there is i18n data. If the element or any attribute or input has i18n metadata, then instead of getting the attributes from the template AST, Angular's
HtmlParser
is used to parse the element to get the raw attributes before they were manipulated into the template AST.This technique is only used when i18n metadata exists to avoid re-parsing the attributes when they are all present in the template AST. Because the HTML parser just parses them as attributes, we need to classify them manually. This is done by looking at what the attribute starts with, and in some cases, what it ends with. For example, if it starts with
*
then it's a structural directive.One difference between the attributes from the HTML parser and the AST is that structural directives from the AST don't include the leading
*
in their span. There were a few different places in the rule that accounted for this. I've refactored that logic into a single function so that the logic (which now needs to account for the attribute coming from the HTML parser) is all in one place.