Skip to content

[ban-css-class] new rule: prevent the use of certain css classes #2401

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

Open
2 tasks
FDIM opened this issue Apr 29, 2025 · 0 comments
Open
2 tasks

[ban-css-class] new rule: prevent the use of certain css classes #2401

FDIM opened this issue Apr 29, 2025 · 0 comments
Labels
package: eslint-plugin-template Angular Template rules triage This issue needs to be looked at and categorized by a maintainer

Comments

@FDIM
Copy link

FDIM commented Apr 29, 2025

Description and reproduction of the issue

It would be quite useful for bigger projects to ban the use of certain css classes. For example the rule should not pass when is-foo is used in any of the variants:

<my-component
   [class.is-foo]="isFoo"
   [name]="value">
</my-component>
<my-component
   [ngClass]="{ '__flex is-foo': isFoo }"
   [name]="value">
</my-component>
<my-component
   class="__flex is-foo"
   [name]="value">
</my-component>

The rule should cover all the static possibilities. If we agree on the configuration format, I could give it a go at implementing it :)

{
  rules: {
    '@angular-eslint/template/ban-css-class': [
      'error',
      {
         name: 'is-foo',
         newName: 'is-bar', // could be used by fixer
         message: 'Please use is-bar instead' // optional
      },
      // do we need regex option? 
     ],
  }
}

Alternatively, maybe a more generic ban-attr rule would be more useful? It could have a special handling for class attribute to cover the cases above.

Versions

package version
@angular-eslint/eslint-plugin-template X.Y.Z
@angular-eslint/template-parser X.Y.Z
@typescript-eslint/parser X.Y.Z
ESLint X.Y.Z
node X.Y.Z
# 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.
@FDIM FDIM added package: eslint-plugin-template Angular Template rules triage This issue needs to be looked at and categorized by a maintainer labels Apr 29, 2025
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 triage This issue needs to be looked at and categorized by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant