stylelint: `declaration-block-no-redundant-longhand-properties` is not forwards compatible

Forwards compatibility means that future CSS can be used in a (slightly) older version of Stylelint.

I don’t expect this to be true for large syntax changes. But I expect Stylelint to not break my code each time a new constituent is added to a shorthand.

A concrete example is the introduction of text-decoration-thickness in text-decoration. The syntax was updated:

  • from <'text-decoration-line'> || <'text-decoration-style'> || <'text-decoration-color'>
  • to <'text-decoration-line'> || <'text-decoration-thickness'> || <'text-decoration-style'> || <'text-decoration-color'>

See :

https://stylelint.io/demo/#N4Igxg9gJgpiBcICGACYAdAdugLjmAHjgLSyQBOSOAlhJsTgBbVgDWmMAzp-CgEwAHAgG4sufEVIwKVWvU44AngBsYvKBDwwoo7FslkIlGnWLLqHXgFdMscuY67xhEoeNzikZUd7ltugF8QABoQADNqVQA5JABbOERCOIFVADowbhDwOgiAcwQQDEwUFHQQFxhbTjLeAG0sEpKyhRUYBxJITDziBSRbJHIoMoaUAF0sINDOvIAxI1iqAoArTjos2AFOAqKmkBbVdprSkGUqLhwy4JHmpQOLDpzqXJ6cPqgBoYRj0-wFYcwggEgA

a {
	text-decoration-thickness: 2px;
	text-decoration-style: dotted;
	text-decoration-line: underline;
	text-decoration-color: red;
}

Is changed to

a {
	text-decoration-thickness: 2px;
	text-decoration: underline dotted red;
}

Which erases text-decoration-thickness.

Updates can be made to teach Stylelint about the updated syntax but this implies a significant maintenance burden.

This is different from other kinds of unknown syntax or CSS aspects as many CSS authors will not have memorized exactly which longhands are constituents of which shorthands and might not even notice the destructive changes Stylelint makes in these cases.


The issue here is not text-decoration itself, but that changing longhands to shorthands is a very impactful source code change.

Longhands and shorthands are simply not the same in CSS.

This issue intended for discussion around this topic and to make sure that this aspect of this rule is in line with the overal goals of Stylelint core rules.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (29 by maintainers)

Commits related to this issue

Most upvoted comments

Since we are about to reach a resolution, I would like to say that Id prefer if impactful changes to stylelint-standard-config were all contained in the same version.

So to be clear based on

https://chromestatus.com/metrics/css/popularity: i.e. completely arbitrary rule of mine: above 55% themselves and their counterpart being under 40%

  • -webkit-appearance
  • -webkit-text-size-adjust
  • -webkit-font-smoothing

our discussion in #7917:

  • transition-behavior

whatwg/compat#28 and #7727:

  • -webkit-background-size

I would send several PRs to add exceptions so that they can be merged in the same timespan. Let’s continue our discussion in a new issue on stylelint-standard-config’s side.

@romainmenke Can we close this issue?

@romainmenke Thanks for summarizing. I’m in favor of the summary https://github.com/stylelint/stylelint/issues/7630#issuecomment-2283431464. 👍🏼

Maybe this is a good approach for these rules:

  • we always try to be up to date with our mapping of shorthands and longhands
  • we use ignoreLonghands and ignoreShorthands in the shared configs for those properties that aren’t widely available yet (as you both suggested)
  • when we receive bug reports for specific cases we add special handling in declaration-block-no-redundant-longhand-properties

Aside:

Wanted to say that none of this is feedback on the hard work that so many people have been putting into this rule 😃

It is a really complicated subject that is non-trivial to get right and maintain.

This is mostly an illustration of how complexity cascades. Shorthands are significant complexity in CSS itself and any tooling that touches on shorthands will also encounter complexity.

At the minimum add "ignoreLonghands": ["text-decoration-thickness"].

I think this will not resolve the fundamental problem with this rule. First of all, we should discuss if this rule should be present the shared config.

"ignoreLonghands": ["text-decoration-thickness"]

This is indeed very useful as an escape hatch when user notice that their CSS is altered in incorrect ways.

But it does expect users to notice. I fear that most will assume that Stylelint knows best and will get frustrated when they eventually find that Stylelint is breaking their code.

We could have automation/signals to help us update this rule more quickly (@webref/css has data for longhands, shorthands, logical groups, …)


Ultimately this is also an upstream issue 😃 Adding constituents to a shorthand or making a longhand into a shorthand is a breaking change in CSS itself. So it also breaks downstream tools (e.g. Stylelint)