fix(eslint-plugin-template): find inline templates on components in blocks #2238
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 #1825
Rather than only looking at the statements in a source file to find the class declarations, the preprocessor now walks down the syntax tree to find the class declarations.
This might seem like it will add a bit more work to the processor, but I don't think it will have much of an impact on performance.
For a typical component file that contains some
import
statements and a class declaration, nothing will change - the syntax tree walking explicitly avoids stepping down intoImportDeclaration
nodes, and it doesn't step intoClassDeclaration
nodes, so the net result would be no change to performance.For a file that contains some more things like type exports, top-level variable assignments and enum declarations, most of those things are also skipped. Variable assignments cannot be skipped because a class could be defined somewhere within the value being assigned (the value being assigned could be a function that defines a class, for example).
For any other files, it will end up doing a bit more work, but its worth remembering that the heuristics will filter out most files anyway.
One thought I did have is adjusting those heuristics to look for
template:
rather thanComponent
(or maybe look for both). If you are testing a component, there's a good chance that the file would contain bothComponent
and@angular/core
, but won't necessarily define a component class. By looking fortemplate:
, the preprocessor could avoid looking at more files.Anyway, I haven't changed any of the heuristics, but if you think that's a good idea, I can make that change as well.