Skip to content

fix(eslint-plugin-template): find inline templates on components in blocks #2238

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

Merged

Conversation

reduckted
Copy link
Contributor

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 into ImportDeclaration nodes, and it doesn't step into ClassDeclaration 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 than Component (or maybe look for both). If you are testing a component, there's a good chance that the file would contain both Component and @angular/core, but won't necessarily define a component class. By looking for template:, 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.

Copy link

nx-cloud bot commented Feb 10, 2025

View your CI Pipeline Execution ↗ for commit 494dcc0.

Command Status Duration Result
nx run-many -t e2e-suite --parallel 1 ✅ Succeeded 25s View ↗
nx run-many -t test --codeCoverage ✅ Succeeded 1m 30s View ↗
nx run-many -t build,typecheck,check-rule-docs,... ✅ Succeeded 55s View ↗
nx-cloud record -- pnpm nx sync:check ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm format-check ✅ Succeeded 5s View ↗
nx run-many -t test ✅ Succeeded 48s View ↗
nx run-many -t build ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-11 11:18:48 UTC

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.26%. Comparing base (53a2afe) to head (494dcc0).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2238      +/-   ##
==========================================
+ Coverage   90.53%   92.26%   +1.73%     
==========================================
  Files         179      179              
  Lines        3559     3324     -235     
  Branches      600      675      +75     
==========================================
- Hits         3222     3067     -155     
- Misses        183      199      +16     
+ Partials      154       58      -96     
Flag Coverage Δ
unittest 92.26% <100.00%> (+1.73%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/eslint-plugin-template/src/processors.ts 83.16% <100.00%> (+6.97%) ⬆️

... and 178 files with indirect coverage changes

@reduckted
Copy link
Contributor Author

The reported code coverage was inaccurate because source maps were turned off, so it wasn't correctly mapping the affected lines to the covered lines. This resulted in code coverage being reported as well below what it actually was. I've fixed this in 494dcc0 by setting sourceMap to true in all of the tsconfig.spec.json files.

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you as always!

@JamesHenry JamesHenry merged commit 249ad59 into angular-eslint:main Feb 26, 2025
7 checks passed
@reduckted reduckted deleted the feature/1825-nested-inline-templates branch February 26, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Angular eslint template rules don't apply to inline templates inside blocks
2 participants