Commit 3302fcb
committed
fix(linter/plugins): sort visitors in order of specificity (#16834)
ESLint calls visitor functions in order of selector specificity, with the least specific selectors first.
Attribute count takes priority in calculation of specificity. A selector with 1 attribute is considered more specific than a selector with any number of identifiers, but no attributes.
e.g. these visit methods are called in the order they're defined:
```js
const rule = {
create(context) {
return {
// 0 identifiers, 0 attributes (least specific)
"*"(node) {},
// 1 identifier, 0 attributes
"Identifier"(node) {},
// 2 identifiers, 0 attributes
":matches(Identifier, Program)"(node) {},
// 1 identifier, 1 attribute (most specific)
"Identifier[name=foo]"(node) {},
// 0 identifiers, 0 attributes (least specific)
"*:exit"(node) {},
// 1 identifier, 0 attributes
"Identifier:exit"(node) {},
// 2 identifiers, 0 attributes (most specific)
":matches(Identifier, Program):exit"(node) {},
};
}
};
```
This PR implement ordering by specificity, to match ESLint.
Fixes 900 conformance tests for `indent` rule.1 parent 274594e commit 3302fcb
File tree
3 files changed
+523
-61750
lines changed- apps/oxlint
- conformance
- src-js/plugins
- test/fixtures/selector
3 files changed
+523
-61750
lines changed
0 commit comments