Refactor selector-max-specificity
to leverage upstream helper
#7689
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.
None
While working on
selector-max-specificity
for the end position fix I noticed that all of the complexity in the rule is for theignoreSelectors
secondary option.Because this option is present it is needed to manually walk the selector and re-implement large sections of
@csstools/selector-specificity
so that ignoring selectors works as expected.I've added an option upstream to customize the specificity calculations.
See : https://github.com/csstools/postcss-plugins/blob/main/packages/selector-specificity/docs/selector-specificity.selectorspecificity.md
Because this is integrated into
@csstools/selector-specificity
we can offload a lot more complexity to that package.A good example was all of the logic around
:nth-child(n of .foo)
.All this logic already existed upstream but couldn't be used before.
A side effect of this change is that this rule is also a bit faster.
Without secondary options.
Main:
This change:
With secondary options.
Main:
This change: