# svelte/no-unused-class-name
disallow the use of a class in the template without a corresponding style
# π Rule Details
This rule is aimed at reducing unused classes in the HTML template. While svelte-check
will produce the css-unused-selector
if your <style>
block includes any classes that arenβt used in the template, this rule works the other way around - it reports cases wehre the template contains classes that arenβt referred to in the <style>
block.
<script lang="ts">
/* eslint svelte/no-unused-class-name: "error" */
</script>
<!-- β GOOD -->
<div class="first-class">Hello</div>
<div class="second-class">Hello</div>
<div class="third-class fourth-class">Hello</div>
<!-- β BAD -->
Unused class "fifth-class". (svelte/no-unused-class-name)<div class="fifth-class">Hello</div>
Unused class "sixth-class". (svelte/no-unused-class-name)<div class="sixth-class first-class">Hello</div>
<style>
.first-class {
color: red;
}
.second-class,
.third-class {
color: blue;
}
.fourth-class {
color: green;
}
</style>
# π§ Options
{
"svelte/no-unused-class-name": [
"error",
{
"allowedClassNames": ["class-name-one", "class-name-two", "/^regex-.*$/"] // You can also use regex to match class names
}
]
}
allowedClassNames
β¦ A list of class names that shouldnβt be reported by this rule. Default[]
.
# π Version
This rule was introduced in eslint-plugin-svelte v2.31.0