Back to Biomejs

useBaseline

src/content/docs/linter/rules/use-baseline.mdx

latest21.2 KB
Original Source

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

<Tabs> <TabItem label="CSS" icon="seti:css"> :::note This rule has been implemented but not released yet. It will be available in the next release. ::: :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Diagnostic Category: [`lint/nursery/useBaseline`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Inspired from [`css/use-baseline`](https://github.com/eslint/css/blob/main/docs/rules/use-baseline.md)

How to configure

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": "error"
			}
		}
	}
}

Description

Disallow CSS properties, values, at-rules, functions, and selectors that are not part of the configured Baseline.

Baseline tracks the availability of web platform features across core browsers. This rule helps you avoid features that aren't supported in the browsers you need to target.

Features are categorized into three tiers:

  • Limited: Not yet available in all core browsers.
  • Newly available: Available in all core browsers for less than 30 months.
  • Widely available: Available in all core browsers for at least 30 months.

By default, the rule reports on anything that is not Baseline widely available.

Code inside @supports blocks is exempt: if you feature-detect a capability before using it, the rule does not flag it.

Examples

Invalid

css
a {
  backdrop-filter: blur(4px);
}
<pre class="language-text"><code class="language-text">code-block.css:2:3 <a href="https://biomejs.dev/linter/rules/use-baseline">lint/nursery/useBaseline</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">CSS </span><span style="color: lightgreen;"><strong>property</strong></span><span style="color: lightgreen;"> </span><span style="color: lightgreen;"><strong>backdrop-filter</strong></span><span style="color: lightgreen;"> isn't part of the chosen Baseline.</span> <strong>1 │ </strong>a &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> backdrop-filter: blur(4px); <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>3 │ </strong>&#125; <strong>4 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Using a feature that isn't part of the Baseline can lead to unexpected behavior in older browsers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Either remove the feature, or use the </span><span style="color: lightgreen;"><strong>@supports</strong></span><span style="color: lightgreen;"> at-rule to gate the feature behind a browser-specific support condition.</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/Glossary/Baseline/Compatibility">MDN Baseline</a></span><span style="color: lightgreen;"> for more information.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check </span><span style="color: lightgreen;"><a href="https://caniuse.com/?search=backdrop-filter">caniuse.com</a></span><span style="color: lightgreen;"> for more information about the feature backdrop-filter.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
css
a { width: abs(20% - 100px); }
<pre class="language-text"><code class="language-text">code-block.css:1:12 <a href="https://biomejs.dev/linter/rules/use-baseline">lint/nursery/useBaseline</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">CSS </span><span style="color: lightgreen;"><strong>function</strong></span><span style="color: lightgreen;"> </span><span style="color: lightgreen;"><strong>abs</strong></span><span style="color: lightgreen;"> isn't part of the chosen Baseline.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; width: abs(20% - 100px); &#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;">Using a feature that isn't part of the Baseline can lead to unexpected behavior in older browsers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Either remove the feature, or use the </span><span style="color: lightgreen;"><strong>@supports</strong></span><span style="color: lightgreen;"> at-rule to gate the feature behind a browser-specific support condition.</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/Glossary/Baseline/Compatibility">MDN Baseline</a></span><span style="color: lightgreen;"> for more information.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check </span><span style="color: lightgreen;"><a href="https://caniuse.com/?search=abs">caniuse.com</a></span><span style="color: lightgreen;"> for more information about the feature abs.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
css
@media (inverted-colors: inverted) { a { color: red; } }
<pre class="language-text"><code class="language-text">code-block.css:1:9 <a href="https://biomejs.dev/linter/rules/use-baseline">lint/nursery/useBaseline</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">CSS </span><span style="color: lightgreen;"><strong>media condition</strong></span><span style="color: lightgreen;"> </span><span style="color: lightgreen;"><strong>inverted-colors</strong></span><span style="color: lightgreen;"> isn't part of the chosen Baseline.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>@media (inverted-colors: inverted) &#123; a &#123; color: red; &#125; &#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><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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Using a feature that isn't part of the Baseline can lead to unexpected behavior in older browsers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Either remove the feature, or use the </span><span style="color: lightgreen;"><strong>@supports</strong></span><span style="color: lightgreen;"> at-rule to gate the feature behind a browser-specific support condition.</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/Glossary/Baseline/Compatibility">MDN Baseline</a></span><span style="color: lightgreen;"> for more information.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check </span><span style="color: lightgreen;"><a href="https://caniuse.com/?search=inverted-colors">caniuse.com</a></span><span style="color: lightgreen;"> for more information about the feature inverted-colors.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
css
details::details-content { background: red; }
<pre class="language-text"><code class="language-text">code-block.css:1:10 <a href="https://biomejs.dev/linter/rules/use-baseline">lint/nursery/useBaseline</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">CSS </span><span style="color: lightgreen;"><strong>pseudo-element</strong></span><span style="color: lightgreen;"> </span><span style="color: lightgreen;"><strong>details-content</strong></span><span style="color: lightgreen;"> isn't part of the chosen Baseline.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>details::details-content &#123; background: red; &#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><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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Using a feature that isn't part of the Baseline can lead to unexpected behavior in older browsers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Either remove the feature, or use the </span><span style="color: lightgreen;"><strong>@supports</strong></span><span style="color: lightgreen;"> at-rule to gate the feature behind a browser-specific support condition.</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/Glossary/Baseline/Compatibility">MDN Baseline</a></span><span style="color: lightgreen;"> for more information.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check </span><span style="color: lightgreen;"><a href="https://caniuse.com/?search=details-content">caniuse.com</a></span><span style="color: lightgreen;"> for more information about the feature details-content.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

Valid

css
a { color: red; }
css
/* @supports exempts feature-detected code */
@supports (backdrop-filter: blur(4px)) {
  a { backdrop-filter: blur(4px); }
}

Options

available

Specifies the minimum Baseline availability tier to accept. Defaults to "widely".

  • "widely": Only accept features that are Baseline widely available (default).
  • "newly": Accept features that are at least Baseline newly available.
  • A year number (e.g. 2023): Accept features that became newly available in that year or earlier.

Default: "widely"

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"available": "newly"
					}
				}
			}
		}
	}
}

With "newly", a property that is newly (but not yet widely) available doesn't trigger the rule:

css
a { backdrop-filter: blur(4px); }

But a limited property still fails:

css
a { accent-color: red; }
<pre class="language-text"><code class="language-text">code-block.css:1:5 <a href="https://biomejs.dev/linter/rules/use-baseline">lint/nursery/useBaseline</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">CSS </span><span style="color: lightgreen;"><strong>property</strong></span><span style="color: lightgreen;"> </span><span style="color: lightgreen;"><strong>accent-color</strong></span><span style="color: lightgreen;"> isn't part of the chosen Baseline.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; accent-color: red; &#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><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> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Using a feature that isn't part of the Baseline can lead to unexpected behavior in older browsers.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Either remove the feature, or use the </span><span style="color: lightgreen;"><strong>@supports</strong></span><span style="color: lightgreen;"> at-rule to gate the feature behind a browser-specific support condition.</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/Glossary/Baseline/Compatibility">MDN Baseline</a></span><span style="color: lightgreen;"> for more information.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check </span><span style="color: lightgreen;"><a href="https://caniuse.com/?search=accent-color">caniuse.com</a></span><span style="color: lightgreen;"> for more information about the feature accent-color.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

allowProperties

A list of CSS property names to exclude from checking (case-insensitive).

Default: []

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowProperties": [
							"backdrop-filter"
						]
					}
				}
			}
		}
	}
}

css
a { backdrop-filter: blur(4px); }

allowAtRules

A list of CSS at-rule names to exclude from checking (without @, case-insensitive).

Default: []

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowAtRules": [
							"view-transition"
						]
					}
				}
			}
		}
	}
}

css
@view-transition { navigation: auto; }

allowFunctions

A list of CSS value function names to exclude from checking (case-insensitive).

Default: []

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowFunctions": [
							"abs"
						]
					}
				}
			}
		}
	}
}

css
a { width: abs(20% - 100px); }

allowMediaConditions

A list of CSS media query condition names to exclude from checking (case-insensitive).

Default: []

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowMediaConditions": [
							"inverted-colors"
						]
					}
				}
			}
		}
	}
}

css
@media (inverted-colors: inverted) { a { color: red; } }

allowPropertyValues

An object mapping property names to arrays of allowed values (case-insensitive).

Default: {}

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowPropertyValues": {
							"clip-path": [
								"fill-box"
							]
						}
					}
				}
			}
		}
	}
}

css
a { clip-path: fill-box; }

allowSelectors

A list of CSS pseudo-class or pseudo-element names to exclude from checking (without : or ::, case-insensitive).

Default: []

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useBaseline": {
					"options": {
						"allowSelectors": [
							"has"
						]
					}
				}
			}
		}
	}
}

css
h1:has(+ h2) { margin: 0; }
</TabItem> </Tabs>