question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `require-scoped-style-tag`

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
ota-meshicommented, Nov 16, 2019
1reaction
smoonsfcommented, Nov 18, 2019

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! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the current state of the "scoped" attribute for the style ...
The scoped attribute is a boolean attribute. If present, it indicates that the styles are intended just for the subtree rooted at the...
Read more >
Scope Proposal & Explainer - OddBird CSS Sandbox
Scoped styles can be used either in light or shadow DOM. All scopes & scoped styles continue to respect the shadow boundary, the...
Read more >
The scoped attribute | HTML5 Doctor
The scoped attribute for the <style> element allows you to include styles mid-document that targets a specific element and its children.
Read more >
A new experimental feature - scoped stylesheets
A web author can limit style rules to only apply to a part of a page by setting the 'scoped' attribute on a...
Read more >
Saving the Day with Scoped CSS
Using scoped styles without a proper polyfill is dangerous. In a browser that doesn't support them, the styles you declare will affect the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found