Back to Biomejs

noDuplicateProperties

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

latest3.5 KB
Original Source

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

<Tabs> <TabItem label="CSS" icon="seti:css"> ## Summary - Rule available since: `v1.9.4` - Diagnostic Category: [`lint/suspicious/noDuplicateProperties`](/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-properties`](https://github.com/stylelint/stylelint/blob/main/lib/rules/declaration-block-no-duplicate-properties/README.md)

How to configure

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

Description

Disallow duplicate properties within declaration blocks.

This rule checks the declaration blocks for duplicate properties. It ignores custom properties.

Examples

Invalid

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

Valid

css
a {
  color: pink;
  background: orange;
}
</TabItem> </Tabs>