question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `declaration-block-no-duplicate`

See original GitHub issue

What 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:closed
  • Created 9 months ago
  • Reactions:1
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ybiquitouscommented, Dec 16, 2022

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.

1reaction
ybiquitouscommented, Dec 15, 2022

Again, let me show the rule blueprint below:

  • Name: declaration-block-no-duplicate
  • Primary option: true
  • Secondary options: ignore: ["nonconsecutive-duplicates"]
  • Autofixable: No (we can implement later)
  • Message: Unexpected duplicate declaration block
  • Description: “Disallow duplicate declaration blocks.”
  • Section: “Enforce non-stylistic conventions” -> “Duplicate”

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”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found