Eslint-plugin-vue: Rule proposal: `require-scoped-style-tag`

Created on 30 Mar 2018  路  5Comments  路  Source: vuejs/eslint-plugin-vue

Please describe what the rule should do:

This rule warns when a <style> tag in SFC does not have the scoped attribute.

What category of rule is this? (place an "X" next to just one item)

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

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

[Bad] When rule enabled, the following will give a warning:

<template>
  <div class="card">Hello</div>
</template>

<style>
.card {
  background-color: #FFFFFF;
}
</style>

[Good] When rule enabled, the following will NOT give a warning:

<template>
  <div class="card">Hello</div>
</template>

<style scoped>
.card {
  background-color: #FFFFFF;
}
</style>

Why should this rule be included

When in large team of devs, some common css selectors might be used in multiple components and have unintended conflicts. This dev would have to explicitly disable rule if there's a scenario that absolutely needs an unscoped style definition.

new rule proposition won't do

Most helpful comment

All 5 comments

Hey @crcatala Thanks for posting this proposal :)

What if the team uses css modules instead? How would you name this rule then?
Or do you see it as two separate rules?

Unfortunately this rule is not possible to implement atm., because of the vue-eslint-parser that doesn't parse other tags than <template>. And it won't change anytime soon

Also looking for something like this, any known workarounds?

Hi.
I created this rule with another ESLint plugin.
https://future-architect.github.io/eslint-plugin-vue-scoped-css/rules/require-scoped.html

This is exactly what i looking for!
Thanks you so much! :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apertureless picture apertureless  路  4Comments

filipalacerda picture filipalacerda  路  4Comments

maple-leaf picture maple-leaf  路  3Comments

Hyzual picture Hyzual  路  3Comments

soullivaneuh picture soullivaneuh  路  3Comments