Skip to content

Commit

Permalink
Fix regression causing root of CSS or SCSS to report violations. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hudochenkov committed Jan 6, 2023
1 parent 4486ad7 commit 87ad51a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"main": "index.js",
"dependencies": {
"postcss": "^8.4.20",
"postcss-sorting": "^8.0.0"
"postcss-sorting": "^8.0.1"
},
"peerDependencies": {
"stylelint": "^14.0.0"
Expand Down
8 changes: 8 additions & 0 deletions rules/order/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ testRule({
}
`,
},
{
description: 'should not report things in css root',
code: `
@media (min-width: 100px) {}
display: none;
`,
},
],

reject: [
Expand Down
13 changes: 11 additions & 2 deletions utils/getContainingNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module.exports = function getContainingNode(node) {
// For styled-components: declarations are children of Root node
if (node.type !== 'rule' && node.type !== 'atrule' && node.parent.type === 'root') {
if (node.type === 'rule' || node.type === 'atrule') {
return node;
}

// postcss-styled-syntax: declarations are children of Root node
if (node.parent?.type === 'root' && node.parent?.raws.styledSyntaxIsComponent) {
return node.parent;
}

// @stylelint/postcss-css-in-js: declarations are children of Root node
if (node.parent?.document?.nodes?.some((item) => item.type === 'root')) {
return node.parent;
}

Expand Down

0 comments on commit 87ad51a

Please sign in to comment.