Back to Biomejs

noInvalidPositionAtImportRule

src/content/docs/linter/rules/no-invalid-position-at-import-rule.mdx

latest3.8 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/correctness/noInvalidPositionAtImportRule`](/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 [`no-invalid-position-at-import-rule`](https://github.com/stylelint/stylelint/blob/main/lib/rules/no-invalid-position-at-import-rule/README.md)

How to configure

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

Description

Disallow the use of @import at-rules in invalid positions.

Any @import rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the @import rule is invalid.

Examples

Invalid

css
a {}
@import 'foo.css';
<pre class="language-text"><code class="language-text">code-block.css:2:2 <a href="https://biomejs.dev/linter/rules/no-invalid-position-at-import-rule">lint/correctness/noInvalidPositionAtImportRule</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This </span><span style="color: Tomato;"><strong>@import</strong></span><span style="color: Tomato;"> is in the wrong position.</span> <strong>1 │ </strong>a &#123;&#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>@import 'foo.css'; <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><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>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Any </span><span style="color: lightgreen;"><strong>@import</strong></span><span style="color: lightgreen;"> rules must precede all other valid at-rules and style rules in a stylesheet (ignoring @charset and @layer), or else the </span><span style="color: lightgreen;"><strong>@import</strong></span><span style="color: lightgreen;"> rule is invalid.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider moving import position.</span> </code></pre>

Valid

css
@import 'foo.css';
a {}
</TabItem> </Tabs>