Skip to content

fix: treat at-rule names as case-insensitive across rules #233

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rules/no-duplicate-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
const imports = new Set();

return {
"Atrule[name=import]"(node) {
"Atrule[name=/^import$/i]"(node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also share the official reference where it is mentioned these are case insensitive?

const url = node.prelude.children[0].value;

if (imports.has(url)) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-duplicate-keyframe-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export default {
const seen = new Map();

return {
"Atrule[name=keyframes]"() {
"Atrule[name=/^keyframes$/i]"() {
insideKeyframes = true;
seen.clear();
},

"Atrule[name=keyframes]:exit"() {
"Atrule[name=/^keyframes$/i]:exit"() {
insideKeyframes = false;
},

Expand Down
13 changes: 7 additions & 6 deletions src/rules/use-baseline.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,11 @@ export default {
}

return {
"Atrule[name=supports]"() {
"Atrule[name=/^supports$/i]"() {
supportsRules.push(new SupportsRule());
},

"Atrule[name=supports] > AtrulePrelude > Condition"(node) {
"Atrule[name=/^supports$/i] > AtrulePrelude > Condition"(node) {
const supportsRule = supportsRules.last();

for (let i = 0; i < node.children.length; i++) {
Expand Down Expand Up @@ -667,11 +667,11 @@ export default {
}
},

"Atrule[name=supports]:exit"() {
"Atrule[name=/^supports$/i]:exit"() {
supportsRules.pop();
},

"Atrule[name=media] > AtrulePrelude > MediaQueryList > MediaQuery > Condition"(
"Atrule[name=/^media$/i] > AtrulePrelude > MediaQueryList > MediaQuery > Condition"(
node,
) {
for (const child of node.children) {
Expand Down Expand Up @@ -719,11 +719,12 @@ export default {

Atrule(node) {
// ignore unknown at-rules - no-invalid-at-rules already catches this
if (!atRules.has(node.name)) {
const atRuleName = node.name.toLowerCase();
if (!atRules.has(atRuleName)) {
return;
}

const featureStatus = atRules.get(node.name);
const featureStatus = atRules.get(atRuleName);

if (!baselineAvailability.isSupported(featureStatus)) {
const loc = node.loc;
Expand Down
6 changes: 3 additions & 3 deletions src/rules/use-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
: null;

return {
"Atrule[name=import]"(node) {
"Atrule[name=/^import$/i]"(node) {
// layer, if present, must always be the second child of the prelude
const secondChild = node.prelude.children[1];
const layerNode =
Expand Down Expand Up @@ -140,7 +140,7 @@ export default {
});
},

"Atrule[name=layer]"(node) {
"Atrule[name=/^layer$/i]"(node) {
layerDepth++;

if (!options.allowUnnamedLayers && !node.prelude) {
Expand All @@ -151,7 +151,7 @@ export default {
}
},

"Atrule[name=layer]:exit"() {
"Atrule[name=/^layer$/i]:exit"() {
layerDepth--;
},

Expand Down
81 changes: 81 additions & 0 deletions tests/rules/no-duplicate-imports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ruleTester.run("no-duplicate-imports", rule, {
"@import url('x.css');",
"@import url('x.css'); @import url('y.css');",
"@import 'x.css'; @import url('y.css'); @import 'z.css';",
"@IMPORT url('x.css');",
"@imPort url('x.css'); @IMport url('y.css');",
"@IMPORT 'x.css'; @import url('y.css'); @IMport 'z.css';",
],
invalid: [
{
Expand Down Expand Up @@ -157,5 +160,83 @@ ruleTester.run("no-duplicate-imports", rule, {
},
],
},
{
code: "@IMPORT url('x.css');\n@IMPORT url('x.css');",
output: "@IMPORT url('x.css');\n",
errors: [
{
messageId: "duplicateImport",
data: { url: "x.css" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
{
code: "@IMport url('x.css');@IMPORT url('x.css');",
output: "@IMport url('x.css');",
errors: [
{
messageId: "duplicateImport",
data: { url: "x.css" },
line: 1,
column: 22,
endLine: 1,
endColumn: 43,
},
],
},
{
code: "@IMPORT url('x.css');@IMPORT url('x.css');@IMPORT url('y.css')",
output: "@IMPORT url('x.css');@IMPORT url('y.css')",
errors: [
{
messageId: "duplicateImport",
data: { url: "x.css" },
line: 1,
column: 22,
endLine: 1,
endColumn: 43,
},
],
},
{
code: "@IMPORT url('x.css');\n@IMPORT 'x.css';\n@IMPORT 'x.css';",
output: "@IMPORT url('x.css');\n@IMPORT 'x.css';",
errors: [
{
messageId: "duplicateImport",
data: { url: "x.css" },
line: 2,
column: 1,
endLine: 2,
endColumn: 17,
},
{
messageId: "duplicateImport",
data: { url: "x.css" },
line: 3,
column: 1,
endLine: 3,
endColumn: 17,
},
],
},
{
code: "@IMPORT url('a.css');\n@import url('b.css');\n@IMPORT url('c.css');\n@import url('a.css');\n@IMPORT url('d.css');",
output: "@IMPORT url('a.css');\n@import url('b.css');\n@IMPORT url('c.css');\n@IMPORT url('d.css');",
errors: [
{
messageId: "duplicateImport",
data: { url: "a.css" },
line: 4,
column: 1,
endLine: 4,
endColumn: 22,
},
],
},
],
});
75 changes: 75 additions & 0 deletions tests/rules/no-duplicate-keyframe-selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ ruleTester.run("no-duplicate-keyframe-selectors", rule, {
dedent`@keyframes test {
0% { opacity: 0; }
0.0% { opacity: 1; }
}`,
dedent`@KEYFRAMES test {
from { opacity: 0; }
to { opacity: 1; }
}`,
dedent`@KeYFrames test {
0% { opacity: 0; }
100% { opacity: 1; }
}`,
dedent`@Keyframes test {
from { opacity: 0; }
50% { opacity: 0.5; }
to { opacity: 1; }
}`,
],
invalid: [
Expand Down Expand Up @@ -245,5 +258,67 @@ ruleTester.run("no-duplicate-keyframe-selectors", rule, {
},
],
},
{
code: dedent`@KEYFRAMES test {
0% { opacity: 0; }
0% { opacity: 1; }
}`,
errors: [
{
messageId: "duplicateKeyframeSelector",
line: 3,
column: 5,
endLine: 3,
endColumn: 7,
},
],
},
{
code: dedent`@Keyframes test {
0% {
opacity: 0;
}

0% {
opacity: 1;
}

50% {
opacity: 0.5;
}

50% {
opacity: 0.75;
}

50% {
opacity: 0.5;
}

}`,
errors: [
{
messageId: "duplicateKeyframeSelector",
line: 6,
column: 5,
endLine: 6,
endColumn: 7,
},
{
messageId: "duplicateKeyframeSelector",
line: 14,
column: 5,
endLine: 14,
endColumn: 8,
},
{
messageId: "duplicateKeyframeSelector",
line: 18,
column: 5,
endLine: 18,
endColumn: 8,
},
],
},
],
});
Loading
Loading