Back to Biomejs

noInvalidDirectionInLinearGradient

src/content/docs/linter/rules/no-invalid-direction-in-linear-gradient.mdx

latest4.6 KB
Original Source

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

<Tabs> <TabItem label="CSS" icon="seti:css"> ## Summary - Rule available since: `v1.9.0` - Diagnostic Category: [`lint/correctness/noInvalidDirectionInLinearGradient`](/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 [`function-linear-gradient-no-nonstandard-direction`](https://github.com/stylelint/stylelint/blob/main/lib/rules/function-linear-gradient-no-nonstandard-direction/README.md)

How to configure

json
{
	"linter": {
		"rules": {
			"correctness": {
				"noInvalidDirectionInLinearGradient": "error"
			}
		}
	}
}

Description

Disallow non-standard direction values for linear gradient functions.

A valid and standard direction value is one of the following:

  • an angle
  • to plus a side-or-corner (to top, to bottom, to left, to right; to top right, to right top, to bottom left, etc.)

A common mistake (matching outdated non-standard syntax) is to use just a side-or-corner without the preceding to.

Examples

Invalid

css
.foo { background: linear-gradient(top, #fff, #000); }
<pre class="language-text"><code class="language-text">code-block.css:1:36 <a href="https://biomejs.dev/linter/rules/no-invalid-direction-in-linear-gradient">lint/correctness/noInvalidDirectionInLinearGradient</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Unexpected nonstandard direction</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>.foo &#123; background: linear-gradient(top, #fff, #000); &#125; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">You should fix the direction value to follow the syntax.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">See </span><span style="color: lightgreen;"><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient">MDN web docs</a></span><span style="color: lightgreen;"> for more details.</span> </code></pre>
css
.foo { background: linear-gradient(45, #fff, #000); }
<pre class="language-text"><code class="language-text">code-block.css:1:36 <a href="https://biomejs.dev/linter/rules/no-invalid-direction-in-linear-gradient">lint/correctness/noInvalidDirectionInLinearGradient</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Unexpected nonstandard direction</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>.foo &#123; background: linear-gradient(45, #fff, #000); &#125; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">You should fix the direction value to follow the syntax.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">See </span><span style="color: lightgreen;"><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient">MDN web docs</a></span><span style="color: lightgreen;"> for more details.</span> </code></pre>

Valid

css
.foo { background: linear-gradient(to top, #fff, #000); }
css
.foo { background: linear-gradient(45deg, #fff, #000); }
</TabItem> </Tabs>