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

Rule proposal: vue/forbid-classes #1631

Closed
taobojlen opened this issue Sep 21, 2021 · 2 comments
Closed

Rule proposal: vue/forbid-classes #1631

taobojlen opened this issue Sep 21, 2021 · 2 comments

Comments

@taobojlen
Copy link
Contributor

Please describe what the rule should do:

It'd be nice if this plugin had a rule that disallowed certain classes being used. This is useful if you have some global CSS and you don't want its class selectors to be used accidentally, and it can be very helpful if you're migrating away from a lot of legacy CSS.

We're using a rule like this to help us migrate away from Bootstrap. As we remove usages of Bootstrap CSS classes, we forbid them to ensure that we don't re-introduce usages of them.

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

.eslintrc.json:

...
    "rules": {
        "vue/forbid-classes": ["error", {
          "files": ["./.eslint/forbidden-classes.json"],
         "classes": ["badClass"]
        }],
...
<div class="badClass" />
<div :class="{ 'badClass': someBoolean }" />
<div :class="someString + ' badClass'" />
<div :class="`badClass ${someString}`" />

Additional context

This rule has been very useful on our team already. Not only does it prevent us from introducing new usages of global CSS that we're phasing out, it also makes it quick and easy to find where we use those classes in the first place.

@ota-meshi
Copy link
Member

It sounds good to me. I think it's a good to follow the existing rules and name the rule vue/no-restricted-class.

@ota-meshi
Copy link
Member

#1639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants