Skip to content

Commit 4b50e7c

Browse files
Fox32romainmenke
andauthored
fix being unable to ignore warnings in postcss-cascade-layers (#1640)
Co-authored-by: Romain Menke <11521496+romainmenke@users.noreply.github.com>
1 parent a6951a6 commit 4b50e7c

File tree

7 files changed

+87
-21
lines changed

7 files changed

+87
-21
lines changed

plugins/postcss-cascade-layers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Cascade Layers
22

3+
### Unreleased (patch)
4+
5+
- Fix being unable to ignore all warning types simultaneously
6+
37
### 5.0.1
48

59
_October 23, 2024_

plugins/postcss-cascade-layers/dist/index.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-cascade-layers/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-cascade-layers/src/index.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,31 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
2929

3030
let hasAnyLayer = false;
3131

32-
if (options.onRevertLayerKeyword || options.onImportLayerRule) {
33-
root.walk((node) => {
34-
if (node.type === 'decl') {
35-
if (IS_REVERT_LAYER_REGEX.test(node.value)) {
36-
node.warn(result, 'handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions.');
37-
return;
38-
}
39-
32+
root.walk((node) => {
33+
if (node.type === 'decl') {
34+
if (options.onRevertLayerKeyword && IS_REVERT_LAYER_REGEX.test(node.value)) {
35+
node.warn(result, 'handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions.');
4036
return;
4137
}
4238

43-
if (node.type === 'atrule') {
44-
if (IS_IMPORT_REGEX.test(node.name) && HAS_LAYER_REGEX.test(node.params)) {
45-
node.warn(result, 'To use @import with layers, the postcss-import plugin is also required. This plugin alone will not support using the @import at-rule.');
46-
return;
47-
}
39+
return;
40+
}
4841

49-
if (IS_LAYER_REGEX.test(node.name)) {
50-
hasAnyLayer = true;
51-
return;
52-
}
42+
if (node.type === 'atrule') {
43+
if (options.onImportLayerRule && IS_IMPORT_REGEX.test(node.name) && HAS_LAYER_REGEX.test(node.params)) {
44+
node.warn(result, 'To use @import with layers, the postcss-import plugin is also required. This plugin alone will not support using the @import at-rule.');
45+
return;
46+
}
5347

48+
if (IS_LAYER_REGEX.test(node.name)) {
49+
hasAnyLayer = true;
5450
return;
5551
}
56-
});
57-
}
52+
53+
return;
54+
}
55+
});
56+
5857

5958
if (!hasAnyLayer) {
6059
return;

plugins/postcss-cascade-layers/test/_tape.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ postcssTape(plugin)({
4545
'invalid-rules': {
4646
message: 'correctly handles invalid rules',
4747
},
48+
'warnings-ignored': {
49+
message: 'correctly ignored warnings',
50+
options: {
51+
onRevertLayerKeyword: false,
52+
onConditionalRulesChangingLayerOrder: false,
53+
onImportLayerRule: false,
54+
},
55+
warnings: 0,
56+
},
4857
'warnings': {
4958
message: 'correctly handles warnings',
5059
options: {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* [postcss-cascade-layers]: To use the @import at-rule with layer, the postcss-import plugin is also required. This plugin alone will not support importing layers. */
2+
@import 'imports/theme.css' layer(theme);
3+
@import 'imports/theme-overrides.css' layer;
4+
5+
/* [postcss-cascade-layers]: handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions. */
6+
@layer {
7+
.foo {
8+
color: revert-layer;
9+
}
10+
}
11+
12+
/* [postcss-cascade-layers]: handling different layer orders in conditional rules is unsupported by this plugin and will cause style differences between browser versions. */
13+
@media (min-width: 10px) {
14+
@layer B {
15+
.foo {
16+
color: red;
17+
}
18+
}
19+
}
20+
21+
@layer A {
22+
.foo {
23+
color: pink;
24+
}
25+
}
26+
27+
@layer B {
28+
.foo {
29+
color: red;
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* [postcss-cascade-layers]: To use the @import at-rule with layer, the postcss-import plugin is also required. This plugin alone will not support importing layers. */
2+
@import 'imports/theme.css' layer(theme);
3+
@import 'imports/theme-overrides.css' layer;
4+
5+
/* [postcss-cascade-layers]: handling "revert-layer" is unsupported by this plugin and will cause style differences between browser versions. */
6+
.foo {
7+
color: revert-layer;
8+
}
9+
10+
/* [postcss-cascade-layers]: handling different layer orders in conditional rules is unsupported by this plugin and will cause style differences between browser versions. */
11+
@media (min-width: 10px) {
12+
.foo:not(#\#) {
13+
color: red;
14+
}
15+
}
16+
17+
.foo:not(#\#):not(#\#) {
18+
color: pink;
19+
}
20+
21+
.foo:not(#\#) {
22+
color: red;
23+
}

0 commit comments

Comments
 (0)