Add `declaration-block-no-duplicate`
See original GitHub issueWhat is the problem you’re trying to solve?
Warn about declaration blocks that can be merged to one:
.selector-a {
color: red;
}
// rule should warn about this one;
// it can be merged to the previous one
.selector-b {
color: red;
}
.selector-c {
color: green;
}
// rule should NOT warn about this one;
// it could be necessary to have this here for specificity
.selector-d {
color: red;
}
Expected output from autofix:
.selector-a,
.selector-b {
color: red;
}
.selector-c {
color: green;
}
.selector-d {
color: red;
}
What solution would you like to see?
A new rule declaration-block-no-duplicate
that warns about consecutive declaration blocks with exactly the same declarations.
Issue Analytics
- State:
- Created 9 months ago
- Reactions:1
- Comments:13 (10 by maintainers)
Top Results From Across the Web
declaration-block-no-duplicate-properties - Stylelint
Disallow duplicate properties within declaration blocks. ... This rule ignores variables ( $sass , @less , --custom-property ). The fix option can automatically ......
Read more >Add autofix to declaration-block-no-duplicate-properties #6119
I have set the Stylelint config to remove duplicate CSS properties and values as below. "declaration-block-no-duplicate-properties": [ true, { " ...
Read more >Enable declaration-block-no-duplicate-properties in Stylelint
Enabling the rule now notes lots of duplicate background-image rules, ... Enable declaration-block-no-duplicate-properties in Stylelint.
Read more >stylelint-declaration-block-no-ignored-properties - npm
Disallow property values that are ignored due to another property value in the same rule.. Latest version: 2.6.0, last published: 2 months ...
Read more >Add declaration-block-no-duplicate-custom-properties
Add declaration -block-no-duplicate-custom-properties.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree that the new rule is only useful for specific use cases and unsuitable for built-in rules.
Or perhaps it would be better to say that it is difficult to create such a rule that would satisfy a generic use case for duplicate declaration blocks.
Again, let me show the rule blueprint below:
declaration-block-no-duplicate
true
ignore: ["nonconsecutive-duplicates"]
Unexpected duplicate declaration block
The different things from https://github.com/stylelint/stylelint/issues/6524#issuecomment-1352375216 are “Secondary options” and “Section”. Because I think this rule is for conventions rather than “Avoid errors”.