Add custom-property-no-missing-var-function rule #5317
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #5000
Closes #5044
This replaces #5044.
I've thought about this rule on and off for a while now. I thought I'd unpacked it all in #5000 (comment), but there's more.
From the
<dashed-ident>
spec:I believe we'll see more unreferenced dashed-idents in the future. For example, if
list-style-type
property was designed today, I believe dashed-idents would be required for the<custom-idents>
to avoid conflicts with CSS-defined identifiers likedisc
, e.g.:The only way to confidently know if a dashed-ident is a custom property, and should therefore be referenced with the
var
function, is to check if it has been defined as one.I've updated the rule to do this and renamed it accordingly. Similarly to the
no-unknown-animations
rule, it has the limitation of only catching unreferenced custom properties that are defined within the same source. Unlike theno-unknown-animations
rule, these manifest as false negatives rather than false positives. As such, I think we're OK to add the rule with this limitation as it'll be useful to some users, i.e. those using locally scoped variables or defining their variables at the top of the same source. We can remove the limitation when we find a way to provide context for rules like these.At the moment, it'll catch:
While avoiding any false positives for unreferenced dashed-idents. Which I think is good enough.