Skip to content

Commit 27464b2

Browse files
committed
Fix regression causing root of CSS or SCSS to be sorted
1 parent 720ef00 commit 27464b2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/getContainingNode.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
module.exports = function getContainingNode(node) {
2-
// For styled-components: declarations are children of Root node
3-
if (node.type !== 'rule' && node.type !== 'atrule' && node.parent.type === 'root') {
2+
if (node.type === 'rule' || node.type === 'atrule') {
3+
return node;
4+
}
5+
6+
// postcss-styled-syntax: declarations are children of Root node
7+
if (node.parent?.type === 'root' && node.parent?.raws.styledSyntaxIsComponent) {
8+
return node.parent;
9+
}
10+
11+
// @stylelint/postcss-css-in-js: declarations are children of Root node
12+
if (node.parent?.document?.nodes?.some((item) => item.type === 'root')) {
413
return node.parent;
514
}
615

lib/order/__tests__/order.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,17 @@ groupTest([
496496
}
497497
`,
498498
},
499+
{
500+
description: 'should not change in the root',
501+
fixture: `
502+
display: none;
503+
@include hello;
504+
`,
505+
expected: `
506+
display: none;
507+
@include hello;
508+
`,
509+
},
499510
{
500511
fixture: `
501512
a {

0 commit comments

Comments
 (0)