Skip to content

Fix selector-max-specificity end positions#7685

Merged
romainmenke merged 7 commits intomainfrom
fix-selector-max-specificity--adventurous-pelican-112c3c6d1a
May 11, 2024
Merged

Fix selector-max-specificity end positions#7685
romainmenke merged 7 commits intomainfrom
fix-selector-max-specificity--adventurous-pelican-112c3c6d1a

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.

@changeset-bot
Copy link

changeset-bot bot commented May 10, 2024

🦋 Changeset detected

Latest commit: 56269fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

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

@romainmenke romainmenke marked this pull request as ready for review May 10, 2024 14:47
@romainmenke
Copy link
Member Author

I will take a look at the coverage issue shortly.

code: ':nth-child(2n + 1) {}',
},
{
code: '[value] {}',
Copy link
Member

@Mouvedia Mouvedia May 10, 2024

Choose a reason for hiding this comment

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

nit
non-blocking

It's kind of contradictory.
i.e. that's the attribute name not its value

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM 👍🏼

@romainmenke romainmenke merged commit 91fc2ad into main May 11, 2024
@romainmenke romainmenke deleted the fix-selector-max-specificity--adventurous-pelican-112c3c6d1a branch May 11, 2024 12:33
// Check if the selector specificity exceeds the allowed maximum
if (compare(maxChildSpecificity(selectorTree), maxSpecificity) > 0) {
if (compare(nodeSpecificity(resolvedSelector), maxSpecificity) > 0) {
const index = selector.first?.sourceIndex ?? 0;
Copy link
Member

Choose a reason for hiding this comment

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

[note] The coverage diff is caused by this line, but I think it's ignorable.

If improving the coverage, we might change it like this, but I'm unsure it's really safe...

Suggested change
const index = selector.first?.sourceIndex ?? 0;
const index = selector.first.sourceIndex;

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think it is safe in practice, but I'd rather keep it anyway.

If the AST is mutated without setting sourceIndex or if something clears out a selector it would throw errors.

But maybe we can add a helper so that we can document this better?

Copy link
Member

Choose a reason for hiding this comment

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

I am fine with keeping it as-is, and I agree with adding a helper. 👍🏼

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 should actually fix this one : postcss/postcss-selector-parser#287

Then we change const index = selector.first?.sourceIndex ?? 0 to const index = selector.sourceIndex

Copy link
Member

Choose a reason for hiding this comment

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

nice👍

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.

3 participants

Comments