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 ignoreAfterCombinators: []
to selector-max-universal
#6275
Merged
ybiquitous
merged 10 commits into
stylelint:main
from
fpetrakov:update-selector-max-universal
Aug 18, 2022
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c3a355a
tests
fpetrakov 45bce81
add option ignoreAfterCombinators
fpetrakov 8c00178
add docs and improve tests
fpetrakov c157b12
add support for user defined combinators
fpetrakov f8982a1
doc fix
fpetrakov 0610d1f
one more doc fix
fpetrakov f752f30
made use of prev method on childNode + added check descendant combina…
fpetrakov 67e4c18
tests and docs fixes
fpetrakov 65ebc48
fixes
fpetrakov 50c610d
revert doc change
fpetrakov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What purpose does this bit of code have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you know, there are 4 types of combinators, according to MDN. This code's purpose is to add support for descendant combinator. This way user can add smth like this to the configuration:
["h1"]
.For example, we have code like this:
a > * { color: red }
. With combinators">", "+", "~"
it's very easy to check, in this case we did it this way:let prevChildNode = childNode.prev();
let prevChildNodeValue = prevChildNode && prevChildNode.value;
prevChildNodeValue
will equal to">"
,"+"
or"~"
, and then we just pass the value to optionMatches function:optionsMatches(secondaryOptions, 'ignoreAfterCombinators', prevChildNodeValue)
If we have code
h1 * { color: red }
and we want to ignore*
afterh1
, we will stumble upon descendant combinator, which is represented by a single space (" ") character. Inn this case, the code from above will not work asprevChildNoveValue
will equal to" "
. We have to go back even farther and check previous node of the prevChildNode to get the valueh1
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. I think we can remove this code.
I believe the rule supports the descendant combinator without this code, via the configuration of
[" "]
. We could probably do more to accommodate other whitespace descendant combinators (like tabs and newlines), but let's only do that if someone requests it. By supporting">"
,"+"
,"~"
and" "
(space) we satisfy the most common use cases and the original one in #5792.We can introduce a separate
ignoreAfterSelector: []
secondary option to support this ash1
is a type selector, not a combinator (and["h1"]
shouldn't be a valid configuration for theignoreAfterCombinators: []
option). Let's only add this option if someone requests it, though.