-
-
Notifications
You must be signed in to change notification settings - Fork 934
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 when postcss-resolve-nested-selector
is used in selector-*
#6234
Comments
postcss-resolve-nested-selector
losing raw sourcepostcss-resolve-nested-selector
is used in selector-*
Nor do I. I've labelled the issue as ready to implement in case any has any ideas. |
Is one solution contributing upstream / having the package return the raw source positions? The actual library code is only 25 lines/rather small, so hopefully adjusting it wouldn't be too tricky? |
postcss-resolve-nested-selector
is used in selector-*
postcss-resolve-nested-selector
is used in selector-*
Porting the code of stylelint/docs/developer-guide/plugins.md Line 314 in 1c386a6
|
If possible, I’d like to rely on a PostCSS plugin that implements nesting well because I think maintaining ported code may be too much for us. For example, postcss-nesting seems to work for the CSS Nesting spec. If need to support non-standard syntaxes like Sass (e.g. EDIT: it’s needed to investigate whether such plugins would fit to Stylelint, though. |
I'm revisiting this issue and investigating @romainmenke Do you have any good idea? |
Would it be fine if the selectors are desugared purely with .foo, bar {
&:hover {}
} gives : I don't mind adding a package for this under csstools (similar to the specificity package). |
Ah, no, we don't want such a
I'll dig into the problem more. Thanks for the quick response! |
Do you have examples rules of where using Because resolving with |
For example, in the stylelint/lib/rules/selector-class-pattern/index.mjs Lines 64 to 70 in eebb786
This rule resolves a nested selector as follows, so the .a {
.b {}
}
/* ↓ resolved */
.a .b {} |
It is indeed unnecessary in simple cases but would it cause false positives/negatives if This can be trivially transformed without .a {
.b {}
} More problematic : /* `divdiv` vs. div:is(div) */
div {
&& {}
}
.foo, #bar {
& {
/* `&` has specificity of 1 id selector for matches on `.foo` */
}
}
/*
`.baz .foo .bar {}`
but also matches:
`.baz.foo .bar {}`
`.foo .baz .bar {}`
*/
.foo .bar {
.baz & {}
}
/* https://github.com/w3c/csswg-drafts/issues/2881 */
.foo, fooz {
.bar, baz {
&:hover, &:focus {}
}
} |
That's my understanding, too: This change will have a greater impact on rules like
That'd be fantastic! |
I've added a package for this, but there are some things that aren't entirely clear how they should work. https://github.com/csstools/postcss-plugins/tree/main/packages/selector-resolve-nested If I understand it correctly there are multiple issues here for Stylelint:
I think the first issue (spec compliance) is covered with the new package I linked above. By resolving two selectors and combining their AST's the source locations get mangled anyway. It is fairly trivial to correct the source locations so that the parent selectors point to e.g. It is much harder to keep Ideally all selector AST nodes would already be offset by their position in the overall CSS. |
@romainmenke Thanks for creating the package so quickly. It's fantastic! Yes, your understanding is correct, and my question was bad. As you commented, keeping an original source position is almost impossible through resolving a nested selector via a library. Instead, we should save such a position in a rule logic, e.g. |
I'd like to use |
This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant. |
Can we ignore see: #7482 When looking into replacing Checking of standards compliant CSS doesn't need So I would rather remove Thoughts? |
I agree. |
Only one more after: #7867 🎉 |
@romainmenke Thanks a lot for your continuous work. Just to make sure, can we close this issue once PR #7937 is merged? |
Yes, this was the last one 🎉 |
What steps are needed to reproduce the bug?
Because the
postcss-resolve-nested-selector
package returns just a list of strings and loses a raw source position, there are some cases that we cannot calculate Stylelint problems' end positions accurately.What Stylelint configuration is needed to reproduce the bug?
How did you run Stylelint?
CLI with
sylelint *.css
Which version of Stylelint are you using?
HEAD
ef37dc54e5e08786750baea0433114b0c56e965a
What did you expect to happen?
A correct end positions for nested selectors should be reported.
What actually happened?
See the following case:
stylelint/lib/rules/selector-class-pattern/index.js
Lines 92 to 98 in ef37dc5
the
endColumn
value should be10
but actually11
:stylelint/lib/rules/selector-class-pattern/__tests__/index.js
Lines 168 to 175 in ef37dc5
Does the bug relate to non-standard syntax?
Yes, it's related to nested selectors
Proposal to fix the bug
I don't have a good idea now.
no-descending-specificity
no-duplicate-selectors
selector-max-attribute
selector-max-class
selector-max-combinators
selector-max-id
selector-max-type
selector-max-compound-selectors
selector-max-universal
selector-max-pseudo-class
selector-max-specificity
selector-no-qualifying-type
see also: #7482
The text was updated successfully, but these errors were encountered: