Back to Biomejs

noInvalidGridAreas

src/content/docs/linter/rules/no-invalid-grid-areas.mdx

latest5.8 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/noInvalidGridAreas`](/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 [`named-grid-areas-no-invalid`](https://github.com/stylelint/stylelint/blob/main/lib/rules/named-grid-areas-no-invalid/README.md)

How to configure

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

Description

Disallows invalid named grid areas in CSS Grid Layouts.

For a named grid area to be valid, all strings must define:

  • the same number of cell tokens
  • at least one cell token

And all named grid areas that spans multiple grid cells must form a single filled-in rectangle.

Examples

Invalid

css
a { grid-template-areas: "a a"
                         "b b b"; }
<pre class="language-text"><code class="language-text">code-block.css:1:26 <a href="https://biomejs.dev/linter/rules/use-consistent-grid-areas">lint/correctness/noInvalidGridAreas</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Inconsistent cell count in grid areas are not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; grid-template-areas: &quot;a a&quot; <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>2 │ </strong> &quot;b b b&quot;; &#125; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider adding the same number of cell tokens in each string.</span> </code></pre>
css
a { grid-template-areas: "b b b"
                         ""; }
<pre class="language-text"><code class="language-text">code-block.css:1:33 <a href="https://biomejs.dev/linter/rules/use-consistent-grid-areas">lint/correctness/noInvalidGridAreas</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Empty grid areas are not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; grid-template-areas: &quot;b b b&quot; <strong> │ </strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> &quot;&quot;; &#125; <strong> │ </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;">Consider adding the cell token within string.</span> </code></pre>
css
a { grid-template-areas: "a a a"
                         "b b a"; }
<pre class="language-text"><code class="language-text">code-block.css:1:33 <a href="https://biomejs.dev/linter/rules/use-consistent-grid-areas">lint/correctness/noInvalidGridAreas</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate filled in rectangle are not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; grid-template-areas: &quot;a a a&quot; <strong> │ </strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> &quot;b b a&quot;; &#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><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;">Consider removing the duplicated filled-in rectangle: </span><span style="color: lightgreen;"><strong>a</strong></span> </code></pre>

Valid

css
a { grid-template-areas: "a a a"
                         "b b b"; }
css
a { grid-template-areas: "a a a"
                         "a a a"; }
</TabItem> </Tabs>