Back to Biomejs

noImportantInKeyframe

src/content/docs/linter/rules/no-important-in-keyframe.mdx

latest3.3 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="CSS" icon="seti:css"> ## Summary - Rule available since: `v1.8.0` - Diagnostic Category: [`lint/suspicious/noImportantInKeyframe`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`keyframe-declaration-no-important`](https://github.com/stylelint/stylelint/blob/main/lib/rules/keyframe-declaration-no-important/README.md)

How to configure

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noImportantInKeyframe": "error"
			}
		}
	}
}

Description

Disallow invalid !important within keyframe declarations

Using !important within keyframes declarations is completely ignored in some browsers.

Examples

Invalid

css
@keyframes foo {
    from {
      opacity: 0;
    }
    to {
      opacity: 1 !important;
    }
}
<pre class="language-text"><code class="language-text">code-block.css:6:18 <a href="https://biomejs.dev/linter/rules/no-important-in-keyframe">lint/suspicious/noImportantInKeyframe</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using </span><span style="color: Tomato;"><strong>!important</strong></span><span style="color: Tomato;"> within keyframes declaration is completely ignored in some browsers.</span> <strong>4 │ </strong> &#125; <strong>5 │ </strong> to &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> opacity: 1 !important; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>7 │ </strong> &#125; <strong>8 │ </strong>&#125; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider removing useless </span><span style="color: lightgreen;"><strong>!important</strong></span><span style="color: lightgreen;"> declaration.</span> </code></pre>

Valid

css
@keyframes foo {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
}
</TabItem> </Tabs>