stylelint icon indicating copy to clipboard operation
stylelint copied to clipboard

Add `at-rule-no-invalid-required-descriptors`

Open jeddy3 opened this issue 1 year ago • 9 comments

What is the problem you're trying to solve?

Some at-rules have rules around required descriptors.

For example, from the @property spec:

@property rules require a syntax and inherits descriptor; if either are missing, the entire rule is invalid and must be ignored. The initial-value descriptor is optional only if the syntax is the universal syntax definition, otherwise the descriptor is required; if it’s missing, the entire rule is invalid and must be ignored.

And from the Fonts spec:

@font-palette-values rules require a font-family descriptor; if it is missing, the @font-palette-values rule is invalid and must be ignored entirely.

Catching @property mistakes would be particularly useful for people as the popularity of @property increases.

Example:

@font-face {
  src: url(foo.woff);
}
2:2 error Unexpected missing descriptor "font-family" for at-rule "font-face"

What solution would you like to see?

A new rule to catch missing descriptors for at-rules.

  • Name: at-rule-no-missing-descriptors
  • Description: Disallow missing descriptors for at-rules.
  • Message: Unexpected missing descriptor(s) "$descriptors" for at-rule "$atRule"
  • Primary option: true
  • Category: Avoid errors > Missing
  • Included in sharable configs?: Yes, recommended
  • Expanded description: Certain descriptors are required for at-rules. For example, @property...

The rule would be complementary to at-rule-property-required-list. For example, only src and font-family are required in the specs for @font-face, but someone may also want to enforce other descriptors like font-display.

jeddy3 avatar Dec 19 '24 18:12 jeddy3

In addition to the three at-rules mentioned above. There is @counter-style and its descriptors:

symbols This descriptor is required if the system descriptor is set to cyclic, numeric, alphabetic, symbolic, or fixed. additive-symbols This descriptor is required if the system descriptor is set to additive.

So, in total, four at-rules have required descriptors. Two are straight-up requires:

  • @font-face - src and font-family
  • @font-palette-values - font-family

And two have requirements based on other descriptors or their values:

  • @property
  • @counter-style

jeddy3 avatar Dec 23 '24 16:12 jeddy3

Category: Avoid errors > Missing

I think it should be under 2 categories: Missing and Invalid. i.e. the at-rule is invalid because one or more descriptors are missing

Name: at-rule-no-missing-descriptors

I am not sure about the name. It doesn't convey that the missing descriptors are specific. What about at-rule-no-missing-mandatory-descriptors or at-rule-no-missing-required-descriptors?

Mouvedia avatar Dec 25 '24 08:12 Mouvedia

i.e. the at-rule is invalid because one or more descriptors are missing

Good catch. Let's go with at-rule-no-invalid-required-descriptors.

  • Name: at-rule-no-invalid-required-descriptors
  • Description: Disallow invalid at-rules without required descriptors.
  • Message: Unexpected invalid at-rule "$atRule" without required descriptor(s) "$descriptors"
  • Primary option: true
  • Category: Avoid errors > Invalid
  • Included in sharable configs?: Yes, recommended
  • Expanded description: Certain descriptors are required for at-rules. For example, @property...

jeddy3 avatar Dec 25 '24 22:12 jeddy3

I'll label this rule as ready to implement as there are no objections. It ties in nicely with our efforts to help users write error-free at-rules.

jeddy3 avatar Jan 03 '25 08:01 jeddy3

Message: Unexpected invalid at-rule "$atRule" without required descriptor(s) "$descriptors"

We can discuss in the upcoming PR whether it should match at-rule-property-required-list's message format or not. e.g. Expected descriptor(s) "${descriptors}" for at-rule "${atRule}"

Mouvedia avatar Jan 03 '25 11:01 Mouvedia

This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant.

github-actions[bot] avatar Feb 04 '25 00:02 github-actions[bot]

@jeddy3 is it still relevant?

sw1tch3roo avatar Jul 25 '25 21:07 sw1tch3roo

Yes, it remains relevant and would be helpful to users.

Looking at the issue again with fresh eyes, let's go with:

  • Name: at-rule-no-missing-required-descriptors
  • Description: Disallow missing required descriptors for at-rules.
  • Message: Unexpected missing descriptor(s) "{descriptors}" for "${atRule}"
  • Primary option: true
  • Category: Avoid errors > Missing
  • Included in sharable configs?: Yes, recommended
  • Expanded description: Certain descriptors are required for at-rules. For example, @property...

jeddy3 avatar Jul 25 '25 23:07 jeddy3

working on this...

sw1tch3roo avatar Aug 08 '25 13:08 sw1tch3roo