Skip to content
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

[prefer-self-closing-tags] Conflicts with new control flow and custom selectors #1641

Open
2 tasks done
aam-antonio opened this issue Nov 25, 2023 · 1 comment
Open
2 tasks done
Labels
package: eslint-plugin-template Angular Template rules PRs Welcome If a high-quality PR is created for this it will be accepted

Comments

@aam-antonio
Copy link

Description and reproduction of the issue
When I use the control flow @for () inside a custom component, the rule detects that the container is empty and self closes the component removing all content.

{
  "rules": {
    "@angular-eslint/template/prefer-self-closing-tags": ["error"]
  }
}
<app-my-menu>
  @for (item of someArray) {
    <app-my-menu-item>{{ item.text }}</app-my-menu-item>
  }
</app-my-menu>

After fix this is the result:

<app-my-menu />

Versions

package version
@angular-eslint/eslint-plugin-template 17.1.0
@angular-eslint/template-parser 17.1.0
@typescript-eslint/parser 6.12.0
ESLint 8.54.0
node 20.9.0
# Please run `npx ng version` in your project and paste the full output here:

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest supported version of the packages and checked my ng version output per the instructions given here.
@aam-antonio aam-antonio added package: eslint-plugin-template Angular Template rules triage This issue needs to be looked at and categorized by a maintainer labels Nov 25, 2023
@abaran30 abaran30 added PRs Welcome If a high-quality PR is created for this it will be accepted and removed triage This issue needs to be looked at and categorized by a maintainer labels Nov 28, 2023
@json-derulo
Copy link
Contributor

Your code is invalid, the for loop is missing a track expression, see the docs. Your code throws a build error:

✘ [ERROR] NG5002: @for loop must have a "track" expression [plugin angular-compiler]

When adding a track expression like the following, there is no lint error and the fixer won't remove anything:

<app-my-menu>
  @for (item of someArray; track item) {
    <app-my-menu-item>{{ item.text }}</app-my-menu-item>
  }
</app-my-menu>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: eslint-plugin-template Angular Template rules PRs Welcome If a high-quality PR is created for this it will be accepted
Projects
None yet
Development

No branches or pull requests

3 participants