-
-
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 selector-max-specificity
end positions
#7685
Changes from all commits
df247f0
ff462a2
f39fd45
19b11ee
9c819ed
535503a
56269fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": patch | ||
--- | ||
|
||
Fixed: `selector-max-specificity` end positions |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,16 +1,14 @@ | ||||||
import { compare, selectorSpecificity } from '@csstools/selector-specificity'; | ||||||
import resolvedNestedSelector from 'postcss-resolve-nested-selector'; | ||||||
|
||||||
import { | ||||||
aNPlusBNotationPseudoClasses, | ||||||
aNPlusBOfSNotationPseudoClasses, | ||||||
linguisticPseudoClasses, | ||||||
} from '../../reference/selectors.mjs'; | ||||||
import { assertNumber, isRegExp, isString } from '../../utils/validateTypes.mjs'; | ||||||
import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsForRule.mjs'; | ||||||
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs'; | ||||||
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs'; | ||||||
import optionsMatches from '../../utils/optionsMatches.mjs'; | ||||||
import parseSelector from '../../utils/parseSelector.mjs'; | ||||||
import report from '../../utils/report.mjs'; | ||||||
import ruleMessages from '../../utils/ruleMessages.mjs'; | ||||||
import validateOptions from '../../utils/validateOptions.mjs'; | ||||||
|
@@ -234,35 +232,27 @@ const rule = (primary, secondaryOptions) => { | |||||
const maxSpecificity = { a, b, c }; | ||||||
|
||||||
root.walkRules((ruleNode) => { | ||||||
if (!isStandardSyntaxRule(ruleNode)) { | ||||||
return; | ||||||
} | ||||||
|
||||||
// Using `.selectors` gets us each selector in the eventuality we have a comma separated set | ||||||
for (const selector of ruleNode.selectors) { | ||||||
for (const resolvedSelector of resolvedNestedSelector(selector, ruleNode)) { | ||||||
// Skip non-standard syntax selectors | ||||||
if (!isStandardSyntaxSelector(resolvedSelector)) { | ||||||
continue; | ||||||
} | ||||||
|
||||||
const selectorTree = parseSelector(resolvedSelector, result, ruleNode); | ||||||
|
||||||
if (!selectorTree) continue; | ||||||
if (!isStandardSyntaxRule(ruleNode)) return; | ||||||
|
||||||
flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => { | ||||||
resolvedSelectors.forEach((resolvedSelector) => { | ||||||
// 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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 But maybe we can add a helper so that we can document this better? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 👍🏼 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice👍 |
||||||
const selectorStr = selector.toString().trim(); | ||||||
|
||||||
report({ | ||||||
ruleName, | ||||||
result, | ||||||
node: ruleNode, | ||||||
message: messages.expected, | ||||||
messageArgs: [resolvedSelector, primary], | ||||||
word: selector, | ||||||
messageArgs: [selectorStr, primary], | ||||||
index, | ||||||
endIndex: index + selectorStr.length, | ||||||
}); | ||||||
} | ||||||
} | ||||||
} | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
}; | ||||||
}; | ||||||
|
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.
nit
non-blocking
It's kind of contradictory.
i.e. that's the attribute name not its value