Skip to content

Commit b8d6356

Browse files
authored
fix: Don't check class names in require-baseline (#93)
* fix: Don't check class names in require-baseline fixes #91 * Refactor to simplify
1 parent 54b7da5 commit b8d6356

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

src/rules/require-baseline.js

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -735,50 +735,48 @@ export default {
735735
}
736736
},
737737

738-
Selector(node) {
739-
for (const child of node.children) {
740-
const selector = child.name;
738+
"PseudoClassSelector,PseudoElementSelector"(node) {
739+
const selector = node.name;
741740

742-
if (!selectors.has(selector)) {
743-
continue;
744-
}
741+
if (!selectors.has(selector)) {
742+
return;
743+
}
745744

746-
// if the selector has been tested in a @supports rule, don't check it
747-
if (supportsRules.hasSelector(selector)) {
748-
continue;
749-
}
745+
// if the selector has been tested in a @supports rule, don't check it
746+
if (supportsRules.hasSelector(selector)) {
747+
return;
748+
}
750749

751-
const featureStatus = selectors.get(selector);
750+
const featureStatus = selectors.get(selector);
752751

753-
if (!baselineAvailability.isSupported(featureStatus)) {
754-
const loc = child.loc;
752+
if (!baselineAvailability.isSupported(featureStatus)) {
753+
const loc = node.loc;
755754

756-
// some selectors are prefixed with the : or :: symbols
757-
let prefixSymbolLength = 0;
758-
if (child.type === "PseudoClassSelector") {
759-
prefixSymbolLength = 1;
760-
} else if (child.type === "PseudoElementSelector") {
761-
prefixSymbolLength = 2;
762-
}
755+
// some selectors are prefixed with the : or :: symbols
756+
let prefixSymbolLength = 0;
757+
if (node.type.startsWith("PseudoClass")) {
758+
prefixSymbolLength = 1;
759+
} else if (node.type.startsWith("PseudoElement")) {
760+
prefixSymbolLength = 2;
761+
}
763762

764-
context.report({
765-
loc: {
766-
start: loc.start,
767-
end: {
768-
line: loc.start.line,
769-
column:
770-
loc.start.column +
771-
selector.length +
772-
prefixSymbolLength,
773-
},
774-
},
775-
messageId: "notBaselineSelector",
776-
data: {
777-
selector,
778-
availability: baselineAvailability.availability,
763+
context.report({
764+
loc: {
765+
start: loc.start,
766+
end: {
767+
line: loc.start.line,
768+
column:
769+
loc.start.column +
770+
selector.length +
771+
prefixSymbolLength,
779772
},
780-
});
781-
}
773+
},
774+
messageId: "notBaselineSelector",
775+
data: {
776+
selector,
777+
availability: baselineAvailability.availability,
778+
},
779+
});
782780
}
783781
},
784782

tests/rules/require-baseline.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ruleTester.run("require-baseline", rule, {
6262
}`,
6363
"div { cursor: pointer; }",
6464
"pre { overflow: auto; }",
65+
".highlight, #highlight, highlight { color: red }",
6566
{
6667
code: `@property --foo {
6768
syntax: "*";

0 commit comments

Comments
 (0)