New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add selector-anb-no-unmatchable
#5907
Comments
@jeddy3 The new rule sounds good to me. 👍🏼 I'm concerned about the one thing that the rule name includes a What do you think? |
Note: In the spec URL, |
|
I've updated the rule name to reflect #5575. The rule should also catch negative indexes too. I've labelled the issue as ready to implement. Please consider contributing if you have time. There are steps on how to add a new rule in the Developer guide. |
selector-anb-no-unmatchable
Hi all, I'm interested in taking this on - have been doing some Rust work on the side, and saw Dan's original tweet. Were there any follow-up items from #5586 / suggested places to start? I see the Rust code for their |
That's fantastic, thank you. We recently added CSSTree to our dependencies for the It'd be good to see some numbers on the package size, and whether SWC (like CSSTree) can parse just selectors. Regardless of the parser we choose, it's should be pretty trivial to switch, if we ever want to in the future, especially with the tests in place. (@mattxwang If we decide to go with CSSTree for this rule, please don't feel obliged to take it on as it won't have a Rust aspect which may have piqued your interest.) |
Thanks for the quick response @jeddy3! Didn't realize that CSSTree has this functionality, which is great! I was able to spin up a first draft for the rule (using CSSTree) in #6678. Let me know what you think! If you'd like, I'm also happy to explore the SWC option, but it seems like CSSTree does the job quite well. |
What is the problem you're trying to solve?
I'd like to catch
nth-*
selectors with zero index like:Although it's valid CSS, it won't match anything.
From the spec:
See: https://twitter.com/dan_abramov/status/1492277543185096704
Related to #5575 (which I suggest we break into separate rules).
What solution would you like to see?
A new rule to help me avoid errors in structural pseudo-classes:
It'll catch:
It'd also disallow zero index of S selectors, e.g.:
This is a good candidate for using an An+B parser, e.g. the one from SWC if it's available, otherwise, we can release for just the simple case of
0
as that's the most common mistake.selector-anb-no-unmatchable
true
Unexpected unmatchable An+B selector "${puesdoClass}"
(e.g. Unexpected unmatchable An+B selector "nth-child(0)")Any thoughts on the rule, its name and scope?
Incidentally, there's a set of rules to enforce (non-stylistic) conventions in this area too, e.g. preferring:
:first-child
over:nth-child(1)
(or vice versa):nth-child(even)
over:nth-child(2n+0)
(or vice versa)If you'd like to add any of these to Stylelint, please open a separate issue.
The text was updated successfully, but these errors were encountered: