-
-
Notifications
You must be signed in to change notification settings - Fork 929
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
Fix inaccurate end positions in selector-max-type
(breaking)
#7509
Fix inaccurate end positions in selector-max-type
(breaking)
#7509
Conversation
|
7aba548
to
8897a3a
Compare
selector-max-type
8897a3a
to
44bab90
Compare
{ | ||
code: '.foo { [&] {} }', | ||
}, |
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.
[&]
can not be parsed and gives a warning, but [&]
also isn't a valid selector.
I would prefer to just drop this test because bogus inputs will always give bogus outputs.
Editted to clarify that this comment is only about [&]
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.
Don't know if our policies have changed since
Non-standard selectors should be ignored, and tests for them should be accepted.
but shouldn't it fail gracefully?
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.
Are non-standard selectors all selectors that aren't standard, or are they only those that are valid in sass, less,...
Nuance between :
- completely bogus
- valid in a CSS flavor, but not in standard CSS
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.
I don't know but I think that we should at least communicate with stylelint-scss
so that they can prepare a rule synchronised with our next release to offer as a drop-in solution to annoyed users.
That way you may drop anything that isn't standard.
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.
I'm sorry, I think there is some confusion here :)
[&]
is not a sass or less selector.
It isn't a valid selector anywhere as far as I know.
If it is valid anywhere, please let me know because then my entire premise is incorrect.
selector-max-type
already used and continues to use isStandardSyntaxSelector
to ignore any selector that is detectable as sass, less, ...
That [&]
was fine in this rule was incorrect, likely a result of postcss-resolve-nested-selector
doing find/replace with strings.
It is also unlikely that users are writing [&]
because this gives errors in general, even when it passes for this rule : https://stylelint.io/demo/#N4Igxg9gJgpiBcIB0AzCEAEwMB0B2GGA2gGQC6W+hhkANhAE7wYDmDMMeA3FRgL74+IADQgUAS1owAcgEMAtnEQwAHgoAOUpGADOOkeAh4JLBCGC8cIVQBdOUHVeZFehKzpsBPKbXF4bALSQxuIsAR6yeFCyDFBWvGSCBsEmAGKM8rI2ZgBWOkYGsOr6iBYEuCAe3jC+-k4VtFkwHlbClpVePn6BKaHhNpHRsfVWjXYtIEl8QA
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.
Editted to clarify that this comment is only about [&]
Sorry my bad, I was commenting on the basis that it was about the lines removed from line 36 to 44 which contained code: '.foo { &__bar {} }',
.
[&]
is probably "completely bogus", you are right.
{ | ||
code: '.foo { &-bar {} }', | ||
description: '&-bar is an invalid selector, types must precede `&`', | ||
message: messages.expected('&-bar', 0), | ||
line: 1, | ||
column: 8, | ||
endLine: 1, | ||
endColumn: 13, | ||
}, | ||
{ | ||
code: '.foo { &__bar {} }', | ||
description: '&__bar is an invalid selector, types must precede `&`', | ||
message: messages.expected('&__bar', 0), | ||
line: 1, | ||
column: 8, | ||
endLine: 1, | ||
endColumn: 14, | ||
}, |
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.
This is a breaking change.
If people use this rule while writing sass style nesting they will get errors after updating. Given the popularity of sass style nesting it will definitely be noticed when we change this.
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.
Maybe add a specific if
to detect the pattern and console.warn
a hint?
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.
Or should we add detection for this in isStandardSyntaxSelector
?
&__bar
and &-bar
are never standard selectors, they can only be sass, less, ...
So I think isStandardSyntaxSelector
should return false in this case.
I think this might be the least intrusive way forward.
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.
are never standard selectors
If true, it ought to be fixed in a separate commit.
IIRC this util is being exported so it might have consequences.
We shouldn't care though, utils ought to match their names.
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.
I agree with adding detection to isStandardSyntaxSelector
by another pull request, as @Mouvedia suggested.
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.
I agree with the refactoring using the nice package "@csstools/selector-resolve-nested unless it introduces breaking changes.
I am a bit confused now :)
I think that any refactor using this package will have some amount of breaking changes and should be saved for a next major.
I think we have these options:
- do not use this package at this time, save it for a next major. We close these PR's and focus purely on the issue of inaccurate end positions which might also have a different solution.
- Start work early on the next major and start refactoring all selector rules to use this package. How exactly we work on the next major, this early, is a different topic :)
- A mix of 1 and 2 where we fix inaccurate end positions in a way that facilitates a future switch to this package. This also implies having a good understanding of this package and how it will integrate in the future.
Option 1 might not find a solution and it can not solve issues with nesting. But it could be a non-breaking step forward.
Notes :
- I am not attached to these changes, the proposed package, ... These can all be discarded if they are not the right way forward.
- I am fine with shelving this work for a few months. Closing these PR's and reviving the effort 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.
Thank you for the detailed explanation. I misunderstood there was room to refactor via @csstools/selector-resolve-nested
somewhere in the code base. 👍🏼
We just released the current major version (16.0.0) a few months ago (Dec 2023), so I predict the next major release will be several months later. I guess staring the work for the next major version is a bit too early at this point.
Of course, I welcome non-breaking changes. Also, since end-position bugs are a bit less critical, we could address other works, e.g. considering the migration path from postcss-resolve-nested-selector
to @csstools/selector-resolve-nested
.
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.
For the record, I vote 3.
It might be annoying to keep both packages and try to navigate/arbitrate breaking changes but it will result in a smoother transition.
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.
I have a vague idea of what 3 looks like.
I will try to prepare a PR with that shortly.
Then this is less abstract :)
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.
see : #7518
44bab90
to
2d633cc
Compare
I am not seeing |
selector-max-type
selector-max-type
(breaking)
Closing this, but also stored the interesting bits in a gist here : https://gist.github.com/romainmenke/32b8e196d0bde94b4429710e3c6ada38 |
See : #6234
No, it's self-explanatory.