Skip to content
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

Conversation

romainmenke
Copy link
Member

Which issue, if any, is this issue related to?

See : #6234

Is there anything in the PR that needs further explanation?

No, it's self-explanatory.

Copy link

changeset-bot bot commented Feb 1, 2024

⚠️ No Changeset found

Latest commit: 8819c54

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@romainmenke romainmenke force-pushed the selector-end-positions--unassuming-marsh-frog-bec59ebff0 branch from 7aba548 to 8897a3a Compare February 1, 2024 18:15
@romainmenke romainmenke changed the title Selector end positions unassuming marsh frog bec59ebff0 Fix inaccurate end positions in selector-max-type Feb 1, 2024
@romainmenke romainmenke force-pushed the selector-end-positions--unassuming-marsh-frog-bec59ebff0 branch from 8897a3a to 44bab90 Compare February 1, 2024 18:20
Comment on lines -42 to -44
{
code: '.foo { [&] {} }',
},
Copy link
Member Author

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 [&]

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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.

Screenshot 2024-02-01 at 21 00 38

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

Copy link
Member

@Mouvedia Mouvedia Feb 2, 2024

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.

Comment on lines +132 to +149
{
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,
},
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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:

  1. 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.
  2. 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 :)
  3. 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.

Copy link
Member

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.

Copy link
Member

@Mouvedia Mouvedia Feb 6, 2024

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.

Copy link
Member Author

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see : #7518

@romainmenke romainmenke force-pushed the selector-end-positions--unassuming-marsh-frog-bec59ebff0 branch from 44bab90 to 2d633cc Compare February 1, 2024 18:22
@Mouvedia
Copy link
Member

Mouvedia commented Feb 1, 2024

I am not seeing selector-max-type under https://github.com/stylelint-scss/stylelint-scss/tree/master/src/rules, does that mean it will have to be turned off if you are using sass?
e.g. &__foo {}

@romainmenke romainmenke changed the title Fix inaccurate end positions in selector-max-type Fix inaccurate end positions in selector-max-type (breaking) Feb 6, 2024
@romainmenke
Copy link
Member Author

Closing this, but also stored the interesting bits in a gist here : https://gist.github.com/romainmenke/32b8e196d0bde94b4429710e3c6ada38

@romainmenke romainmenke deleted the selector-end-positions--unassuming-marsh-frog-bec59ebff0 branch March 17, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants