noSvelteClassDirective (HTML)
Language HTML
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/noSvelteClassDirective - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noSvelteClassDirective": "error" } } }}Description
Section titled “Description”Disallow Svelte’s class: directive.
The class: directive adds one class to an element when a condition is true.
Since Svelte 5.16, the class attribute accepts objects and arrays, which can do the same.
Svelte recommends the class attribute, because an object or an array can add several
classes with one condition, and can be combined with other class values, such as the
classes that a component receives from its parent.
Objects and arrays in the class attribute need Svelte 5.16 or later.
This rule doesn’t check which Svelte version your project uses,
so turn it off if your project uses an older version.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<div class:active={isActive}></div>code-block.svelte:1:6 lint/nursery/noSvelteClassDirective ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This class: directive can be replaced with the class attribute.
> 1 │ <div class:active={isActive}></div>
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Since Svelte 5.16, the class attribute accepts objects and arrays. Unlike the directive, they can add several classes with one condition and can be combined with other class values.
ℹ Move the class into the element's class attribute, using an object such as class={{ active: isActive }}.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<div class:active></div>code-block.svelte:1:6 lint/nursery/noSvelteClassDirective ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This class: directive can be replaced with the class attribute.
> 1 │ <div class:active></div>
│ ^^^^^^^^^^^^
2 │
ℹ Since Svelte 5.16, the class attribute accepts objects and arrays. Unlike the directive, they can add several classes with one condition and can be combined with other class values.
ℹ Move the class into the element's class attribute, using an object such as class={{ active: isActive }}.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<div class={{ active: isActive }}></div><div class={{ active }}></div><div class={["button", isActive && "active"]}></div><div class={isActive ? "active" : "inactive"}></div>References
Section titled “References”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.