Back to Biomejs

noDuplicateCustomProperties

src/content/docs/linter/rules/no-duplicate-custom-properties.mdx

latest8.2 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/suspicious/noDuplicateCustomProperties`](/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 [`declaration-block-no-duplicate-custom-properties`](https://github.com/stylelint/stylelint/blob/main/lib/rules/declaration-block-no-duplicate-custom-properties/README.md)

How to configure

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

Description

Disallow duplicate custom properties within declaration blocks.

This rule checks the declaration blocks for duplicate custom properties.

Examples

Invalid

css
a { --custom-property: pink; --custom-property: orange;  }
<pre class="language-text"><code class="language-text">code-block.css:1:30 <a href="https://biomejs.dev/linter/rules/no-duplicate-custom-properties">lint/suspicious/noDuplicateCustomProperties</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate custom properties can lead to unexpected behavior and may override previous declarations unintentionally.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; --custom-property: pink; --custom-property: orange; &#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><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;"><strong>--custom-property</strong></span><span style="color: lightgreen;"> is already defined here.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; --custom-property: pink; --custom-property: orange; &#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><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;">Remove or rename the duplicate custom property to ensure consistent styling.</span> </code></pre>
css
a { --custom-property: pink; background: orange; --custom-property: orange }
<pre class="language-text"><code class="language-text">code-block.css:1:50 <a href="https://biomejs.dev/linter/rules/no-duplicate-custom-properties">lint/suspicious/noDuplicateCustomProperties</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Duplicate custom properties can lead to unexpected behavior and may override previous declarations unintentionally.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; --custom-property: pink; background: orange; --custom-property: orange &#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><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;"><strong>--custom-property</strong></span><span style="color: lightgreen;"> is already defined here.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>a &#123; --custom-property: pink; background: orange; --custom-property: orange &#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><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;">Remove or rename the duplicate custom property to ensure consistent styling.</span> </code></pre>

Valid

css
a { --custom-property: pink; }
css
a { --custom-property: pink; --cUstOm-prOpErtY: orange; }
</TabItem> </Tabs>