From 27464b238eaa07b18f42410b0766644fc66ca15e Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Fri, 6 Jan 2023 18:21:35 +0100 Subject: [PATCH 01/20] Fix regression causing root of CSS or SCSS to be sorted --- lib/getContainingNode.js | 13 +++++++++++-- lib/order/__tests__/order.js | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/getContainingNode.js b/lib/getContainingNode.js index 0c404b1..d2f8e0f 100644 --- a/lib/getContainingNode.js +++ b/lib/getContainingNode.js @@ -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; } diff --git a/lib/order/__tests__/order.js b/lib/order/__tests__/order.js index 680de85..92b3ccc 100644 --- a/lib/order/__tests__/order.js +++ b/lib/order/__tests__/order.js @@ -496,6 +496,17 @@ groupTest([ } `, }, + { + description: 'should not change in the root', + fixture: ` + display: none; + @include hello; + `, + expected: ` + display: none; + @include hello; + `, + }, { fixture: ` a { From 840b7d94c6991d2485c91032204119c18713069f Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Fri, 6 Jan 2023 18:23:32 +0100 Subject: [PATCH 02/20] Prepare 8.0.1 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4ad77..c3b2924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## 8.0.1 +* Fix regression causing root of CSS or SCSS to be sorted. + ## 8.0.0 * Dropped Node.js 12 and 14 support. * Added support for `postcss-styled-syntax`. From f8bad7765e11319e9bb46cd4449cf6a6a1807dae Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Fri, 6 Jan 2023 18:23:50 +0100 Subject: [PATCH 03/20] 8.0.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0ab5b77..b486c6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "postcss-sorting", - "version": "8.0.0", + "version": "8.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "postcss-sorting", - "version": "8.0.0", + "version": "8.0.1", "license": "MIT", "devDependencies": { "eslint": "^8.31.0", diff --git a/package.json b/package.json index 479c7c9..414f87e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-sorting", - "version": "8.0.0", + "version": "8.0.1", "description": "PostCSS plugin to keep rules and at-rules content in order.", "keywords": [ "postcss", From 572db231689910f8725cf5a2cb72aae9fe287399 Mon Sep 17 00:00:00 2001 From: June Hester Date: Tue, 7 Mar 2023 00:57:05 -0800 Subject: [PATCH 04/20] Fix crash when using postcss-sass syntax (#108) --- lib/isAllowedToProcess.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/isAllowedToProcess.js b/lib/isAllowedToProcess.js index d12c0c8..dc50782 100644 --- a/lib/isAllowedToProcess.js +++ b/lib/isAllowedToProcess.js @@ -10,7 +10,7 @@ module.exports = function isAllowedToProcess(node) { } // postcss-styled-syntax: Interpolations at the end of node - if (node.raws.after.includes('${')) { + if (node.raws.after?.includes('${')) { return false; } From 9c6fb25ccab7da5dd4bd426a92c9e310aa4ecd26 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Tue, 7 Mar 2023 10:09:21 +0100 Subject: [PATCH 05/20] Fix sorting inside CSS-in-JS `css` helper --- lib/getContainingNode.js | 2 +- .../fixtures/inside-css-helper.expected.js | 8 +++++ .../__tests__/fixtures/inside-css-helper.js | 8 +++++ .../__tests__/properties-order.js | 9 ++++++ package-lock.json | 30 +++++++++---------- package.json | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 lib/properties-order/__tests__/fixtures/inside-css-helper.expected.js create mode 100644 lib/properties-order/__tests__/fixtures/inside-css-helper.js diff --git a/lib/getContainingNode.js b/lib/getContainingNode.js index d2f8e0f..848194b 100644 --- a/lib/getContainingNode.js +++ b/lib/getContainingNode.js @@ -4,7 +4,7 @@ module.exports = function getContainingNode(node) { } // postcss-styled-syntax: declarations are children of Root node - if (node.parent?.type === 'root' && node.parent?.raws.styledSyntaxIsComponent) { + if (node.parent?.type === 'root' && node.parent?.raws.isRuleLike) { return node.parent; } diff --git a/lib/properties-order/__tests__/fixtures/inside-css-helper.expected.js b/lib/properties-order/__tests__/fixtures/inside-css-helper.expected.js new file mode 100644 index 0000000..de3e5b8 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/inside-css-helper.expected.js @@ -0,0 +1,8 @@ +const Component = styled.div` + ${() => css` + position: absolute; + top: 0; + display: block; + z-index: 2; + `}; +`; diff --git a/lib/properties-order/__tests__/fixtures/inside-css-helper.js b/lib/properties-order/__tests__/fixtures/inside-css-helper.js new file mode 100644 index 0000000..79278e4 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/inside-css-helper.js @@ -0,0 +1,8 @@ +const Component = styled.div` + ${() => css` + z-index: 2; + top: 0; + position: absolute; + display: block; + `}; +`; diff --git a/lib/properties-order/__tests__/properties-order.js b/lib/properties-order/__tests__/properties-order.js index 9f0456f..10c5e3c 100644 --- a/lib/properties-order/__tests__/properties-order.js +++ b/lib/properties-order/__tests__/properties-order.js @@ -199,6 +199,15 @@ test('Should sort properties in nested rules (styled)', () => __dirname )); +test('Should sort properties in css helper (styled)', () => + runTest( + 'inside-css-helper.js', + { + 'properties-order': ['position', 'top', 'display', 'z-index'], + }, + __dirname + )); + test('Ignore template literals in flat components (styled)', () => runTest( 'ignore-template-literals-flat.js', diff --git a/package-lock.json b/package-lock.json index b486c6f..72b69d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,12 +18,12 @@ "lint-staged": "^13.1.0", "postcss": "^8.4.20", "postcss-html": "^1.5.0", - "postcss-styled-syntax": "^0.1.0", + "postcss-styled-syntax": "^0.4.0", "prettier": "^2.8.1", "prettier-config-hudochenkov": "^0.3.0" }, "peerDependencies": { - "postcss": "^8.3.9" + "postcss": "^8.4.20" } }, "node_modules/@ampproject/remapping": { @@ -8204,9 +8204,9 @@ } }, "node_modules/postcss": { - "version": "8.4.20", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz", - "integrity": "sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g==", + "version": "8.4.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", + "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", "dev": true, "funding": [ { @@ -8265,16 +8265,16 @@ } }, "node_modules/postcss-styled-syntax": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/postcss-styled-syntax/-/postcss-styled-syntax-0.1.0.tgz", - "integrity": "sha512-r7t5YnAOH10wb7HvDR9foC0hffbSBmBKZ8qb0IJBz1Mz3jABnpbxCkJ4ZH/aXG4a93mu2/w1jttR6mKr2uNpXg==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/postcss-styled-syntax/-/postcss-styled-syntax-0.4.0.tgz", + "integrity": "sha512-LvG++K8LtIyX1Q1mNuZVQYmBo+SCwn90cEkMigo4/I0QwXrEiYt8nPeJ5rrI5Uuh+5w7hRfPyJKlvQdhVZBhUg==", "dev": true, "dependencies": { "@typescript-eslint/typescript-estree": "^5.47.0", "estree-walker": "^2.0.2" }, "peerDependencies": { - "postcss": "^8.4.20" + "postcss": "^8.4.21" } }, "node_modules/postcss-styled-syntax/node_modules/@typescript-eslint/types": { @@ -15729,9 +15729,9 @@ "peer": true }, "postcss": { - "version": "8.4.20", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz", - "integrity": "sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g==", + "version": "8.4.21", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", + "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", "dev": true, "requires": { "nanoid": "^3.3.4", @@ -15767,9 +15767,9 @@ "requires": {} }, "postcss-styled-syntax": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/postcss-styled-syntax/-/postcss-styled-syntax-0.1.0.tgz", - "integrity": "sha512-r7t5YnAOH10wb7HvDR9foC0hffbSBmBKZ8qb0IJBz1Mz3jABnpbxCkJ4ZH/aXG4a93mu2/w1jttR6mKr2uNpXg==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/postcss-styled-syntax/-/postcss-styled-syntax-0.4.0.tgz", + "integrity": "sha512-LvG++K8LtIyX1Q1mNuZVQYmBo+SCwn90cEkMigo4/I0QwXrEiYt8nPeJ5rrI5Uuh+5w7hRfPyJKlvQdhVZBhUg==", "dev": true, "requires": { "@typescript-eslint/typescript-estree": "^5.47.0", diff --git a/package.json b/package.json index 414f87e..bcb212d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "lint-staged": "^13.1.0", "postcss": "^8.4.20", "postcss-html": "^1.5.0", - "postcss-styled-syntax": "^0.1.0", + "postcss-styled-syntax": "^0.4.0", "prettier": "^2.8.1", "prettier-config-hudochenkov": "^0.3.0" }, From 325d0f08db2e9f182267fd561d833581ced7b7c1 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Tue, 7 Mar 2023 10:10:09 +0100 Subject: [PATCH 06/20] Prepare 8.0.2 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b2924..b131b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## 8.0.2 +* Fixed sorting inside CSS-in-JS `css` helper +* Fixed crash when using postcss-sass syntax + ## 8.0.1 * Fix regression causing root of CSS or SCSS to be sorted. From 6027f1c376cbe78a2298bcca8e23f862457893c5 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Tue, 7 Mar 2023 10:13:34 +0100 Subject: [PATCH 07/20] 8.0.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72b69d2..dbcc015 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "postcss-sorting", - "version": "8.0.1", + "version": "8.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "postcss-sorting", - "version": "8.0.1", + "version": "8.0.2", "license": "MIT", "devDependencies": { "eslint": "^8.31.0", diff --git a/package.json b/package.json index bcb212d..55c9f35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-sorting", - "version": "8.0.1", + "version": "8.0.2", "description": "PostCSS plugin to keep rules and at-rules content in order.", "keywords": [ "postcss", From a14543c56d1da95a98a5f3d4acce3839b76122eb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 21:07:26 +0200 Subject: [PATCH 08/20] Bump postcss from 8.4.21 to 8.4.31 (#115) Bumps [postcss](https://github.com/postcss/postcss) from 8.4.21 to 8.4.31. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.21...8.4.31) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index dbcc015..8c7491a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7737,10 +7737,16 @@ "dev": true }, "node_modules/nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -8204,9 +8210,9 @@ } }, "node_modules/postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "dev": true, "funding": [ { @@ -8216,10 +8222,14 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ], "dependencies": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, @@ -15393,9 +15403,9 @@ "dev": true }, "nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", "dev": true }, "natural-compare": { @@ -15729,12 +15739,12 @@ "peer": true }, "postcss": { - "version": "8.4.21", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz", - "integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==", + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", "dev": true, "requires": { - "nanoid": "^3.3.4", + "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } From 2f81b02b60b180db0dd855c63783c4072558261a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 21:08:01 +0200 Subject: [PATCH 09/20] Bump word-wrap from 1.2.3 to 1.2.4 (#114) Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8c7491a..6a8942f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9441,9 +9441,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", + "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -16639,9 +16639,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", + "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==", "dev": true }, "wrap-ansi": { From 14c178fe2ccbbba5713ac0ed2f0f89a071e96e86 Mon Sep 17 00:00:00 2001 From: Astrael1 <33071364+Astrael1@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:30:34 +0200 Subject: [PATCH 10/20] Ignore properties case when sorting declarations (#120) --- lib/__tests__/test.js | 13 ++------- ...operties-alphabetical-case-insensitive.css | 6 ++++ ...alphabetical-case-insensitive.expected.css | 6 ++++ .../fixtures/properties-have-same-name-4.css | 11 ++++++++ .../properties-have-same-name-4.expected.css | 11 ++++++++ .../fixtures/properties-have-same-name-5.css | 9 ++++++ .../properties-have-same-name-5.expected.css | 9 ++++++ .../__tests__/properties-order.js | 28 +++++++++++++++++++ lib/properties-order/sortNodeProperties.js | 2 +- 9 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.expected.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-have-same-name-4.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-have-same-name-4.expected.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-have-same-name-5.css create mode 100644 lib/properties-order/__tests__/fixtures/properties-have-same-name-5.expected.css diff --git a/lib/__tests__/test.js b/lib/__tests__/test.js index a2a3e3c..13479df 100644 --- a/lib/__tests__/test.js +++ b/lib/__tests__/test.js @@ -11,14 +11,7 @@ test(`Should throw an error if config has error`, () => { order: 'Justice Rains From Above', }; - const pluginRun = postcss([plugin(opts)]) - .process('', { from: undefined }) - .then(() => { - expect('Plugin should throw an error').toBeFalst(); - }) - .catch((err) => { - throw err; - }); - - expect(pluginRun).rejects.toBeTruthy(); + return expect(postcss([plugin(opts)]).process('', { from: undefined })).rejects.toThrow( + 'postcss-sorting: order: Should be an array' + ); }); diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.css new file mode 100644 index 0000000..185c451 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.css @@ -0,0 +1,6 @@ +a { + Border: red; + align-content: center; + font-family: sans-serif; + Display: block; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.expected.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.expected.css new file mode 100644 index 0000000..47d722a --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-case-insensitive.expected.css @@ -0,0 +1,6 @@ +a { + align-content: center; + Border: red; + Display: block; + font-family: sans-serif; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.css b/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.css new file mode 100644 index 0000000..02ab582 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.css @@ -0,0 +1,11 @@ +div { + position: fixed; + top: 0; + Top: 0; +} + +div { + position: fixed; + Top: 0; + top: 0; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.expected.css b/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.expected.css new file mode 100644 index 0000000..02ab582 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-have-same-name-4.expected.css @@ -0,0 +1,11 @@ +div { + position: fixed; + top: 0; + Top: 0; +} + +div { + position: fixed; + Top: 0; + top: 0; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.css b/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.css new file mode 100644 index 0000000..ee7d0e9 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.css @@ -0,0 +1,9 @@ +.header { + Padding-bottom: 20px; + Justify-content: space-between; + display: -webkit-box; + Display: -ms-flexbox; + display: flex; + Align-items: center; + flex-wrap: wrap; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.expected.css b/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.expected.css new file mode 100644 index 0000000..cbdbdf1 --- /dev/null +++ b/lib/properties-order/__tests__/fixtures/properties-have-same-name-5.expected.css @@ -0,0 +1,9 @@ +.header { + Align-items: center; + display: -webkit-box; + Display: -ms-flexbox; + display: flex; + flex-wrap: wrap; + Justify-content: space-between; + Padding-bottom: 20px; +} diff --git a/lib/properties-order/__tests__/properties-order.js b/lib/properties-order/__tests__/properties-order.js index 10c5e3c..754c6b5 100644 --- a/lib/properties-order/__tests__/properties-order.js +++ b/lib/properties-order/__tests__/properties-order.js @@ -91,6 +91,24 @@ test('Should preserve order if properties have same name', () => __dirname )); +test('Should preserve order if properties have same name (case insensitive)', () => + runTest( + 'properties-have-same-name-4', + { + 'properties-order': ['position', 'z-index'], + }, + __dirname + )); + +test('Should preserve order if properties have same name (case insensitive)', () => + runTest( + 'properties-have-same-name-5', + { + 'properties-order': 'alphabetical', + }, + __dirname + )); + test(`Should not remove first comment in the rule if it's not on separate line (properties-order)`, () => runTest( 'first-comment-in-the-rule', @@ -145,6 +163,16 @@ test('Should sort properties alphabetically', () => __dirname )); +test('Should sort properties alphabetically regardless of case', () => { + runTest( + 'properties-alphabetical-case-insensitive', + { + 'properties-order': 'alphabetical', + }, + __dirname + ); +}); + test('Should sort shorthand properties before their longhand versions', () => runTest( 'properties-alphabetical-shorthand', diff --git a/lib/properties-order/sortNodeProperties.js b/lib/properties-order/sortNodeProperties.js index 9c15667..e14b4bf 100644 --- a/lib/properties-order/sortNodeProperties.js +++ b/lib/properties-order/sortNodeProperties.js @@ -25,7 +25,7 @@ module.exports = function sortNodeProperties(node, { order, unspecifiedPropertie isStandardSyntaxProperty(childNode.prop) && !isCustomProperty(childNode.prop) ) { - let unprefixedPropName = vendor.unprefixed(childNode.prop); + let unprefixedPropName = vendor.unprefixed(childNode.prop).toLowerCase(); // Hack to allow -moz-osx-font-smoothing to be understood // just like -webkit-font-smoothing From 38e29152b729775d951376156de13e2e90d14237 Mon Sep 17 00:00:00 2001 From: Colin Duivis Date: Sat, 19 Oct 2024 23:59:29 +0200 Subject: [PATCH 11/20] Add more shorthands (#119) Added some missing shorthands: - margin-block - margin-inline - padding-block - padding-inline - offset - overflow - mask-border --- lib/properties-order/shorthandData.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/properties-order/shorthandData.js b/lib/properties-order/shorthandData.js index 9c01dcf..11db231 100644 --- a/lib/properties-order/shorthandData.js +++ b/lib/properties-order/shorthandData.js @@ -3,7 +3,11 @@ // See https://github.com/stylelint/stylelint/blob/10.1.0/lib/reference/shorthandData.js module.exports = { margin: ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], + 'margin-block': ['margin-block-start', 'margin-block-end'], + 'margin-inline': ['margin-inline-start', 'margin-inline-end'], padding: ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], + 'padding-block': ['padding-block-start', 'padding-block-end'], + 'padding-inline': ['padding-inline-start', 'padding-inline-end'], background: [ 'background-image', 'background-size', @@ -128,7 +132,9 @@ module.exports = { 'grid-gap': ['grid-row-gap', 'grid-column-gap'], 'grid-row': ['grid-row-start', 'grid-row-end'], 'grid-template': ['grid-template-columns', 'grid-template-rows', 'grid-template-areas'], + offset: ['offset-anchor', 'offset-distance', 'offset-path', 'offset-position', 'offset-rotate'], outline: ['outline-color', 'outline-style', 'outline-width'], + overflow: ['overflow-x', 'overflow-y'], 'text-decoration': ['text-decoration-color', 'text-decoration-style', 'text-decoration-line'], 'text-emphasis': ['text-emphasis-style', 'text-emphasis-color'], mask: [ @@ -141,4 +147,12 @@ module.exports = { 'mask-clip', 'mask-composite', ], + 'mask-border': [ + 'mask-border-mode', + 'mask-border-outset', + 'mask-border-repeat', + 'mask-border-slice', + 'mask-border-source', + 'mask-border-width' + ] }; From b304239ea4f86fd375ba2eec67430f878ac892a4 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Sun, 20 Oct 2024 01:56:20 +0200 Subject: [PATCH 12/20] Add more shorthand data --- .../properties-alphabetical-shorthand.css | 23 ++++++ ...erties-alphabetical-shorthand.expected.css | 23 ++++++ lib/properties-order/shorthandData.js | 75 +++++++++++++++++-- 3 files changed, 113 insertions(+), 8 deletions(-) diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.css index b78cab9..f67de92 100644 --- a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.css +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.css @@ -21,3 +21,26 @@ a { border-color: transparent; border-bottom-color: pink; } + +a { + margin-inline: 0; + margin: 0; +} + +a { + margin-bottom: 0; + margin-inline: 0; + margin: 0; +} + +a { + margin-top: 0; + margin-inline: 0; + margin: 0; +} + +a { + margin-bottom: 0; + margin-inline-start: 0; + margin: 0; +} diff --git a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.expected.css b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.expected.css index 468932f..e4aeffa 100644 --- a/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.expected.css +++ b/lib/properties-order/__tests__/fixtures/properties-alphabetical-shorthand.expected.css @@ -21,3 +21,26 @@ a { border-color: transparent; border-bottom-color: pink; } + +a { + margin: 0; + margin-inline: 0; +} + +a { + margin: 0; + margin-inline: 0; + margin-bottom: 0; +} + +a { + margin: 0; + margin-inline: 0; + margin-top: 0; +} + +a { + margin: 0; + margin-inline-start: 0; + margin-bottom: 0; +} diff --git a/lib/properties-order/shorthandData.js b/lib/properties-order/shorthandData.js index 11db231..d6245ed 100644 --- a/lib/properties-order/shorthandData.js +++ b/lib/properties-order/shorthandData.js @@ -1,13 +1,72 @@ 'use strict'; // See https://github.com/stylelint/stylelint/blob/10.1.0/lib/reference/shorthandData.js +// More properties were added in addition to the file above module.exports = { - margin: ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], - 'margin-block': ['margin-block-start', 'margin-block-end'], - 'margin-inline': ['margin-inline-start', 'margin-inline-end'], - padding: ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], - 'padding-block': ['padding-block-start', 'padding-block-end'], - 'padding-inline': ['padding-inline-start', 'padding-inline-end'], + margin: [ + 'margin-top', + 'margin-bottom', + 'margin-left', + 'margin-right', + 'margin-block', + 'margin-block-start', + 'margin-block-end', + 'margin-inline', + 'margin-inline-start', + 'margin-inline-end', + ], + 'margin-block': [ + 'margin-block-start', + 'margin-block-end', + 'margin-top', + 'margin-bottom', + 'margin-left', + 'margin-right', + ], + 'margin-block-start': ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], + 'margin-block-end': ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], + 'margin-inline': [ + 'margin-inline-start', + 'margin-inline-end', + 'margin-top', + 'margin-bottom', + 'margin-left', + 'margin-right', + ], + 'margin-inline-start': ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], + 'margin-inline-end': ['margin-top', 'margin-bottom', 'margin-left', 'margin-right'], + padding: [ + 'padding-top', + 'padding-bottom', + 'padding-left', + 'padding-right', + 'padding-block', + 'padding-block-start', + 'padding-block-end', + 'padding-inline', + 'padding-inline-start', + 'padding-inline-end', + ], + 'padding-block': [ + 'padding-block-start', + 'padding-block-end', + 'padding-top', + 'padding-bottom', + 'padding-left', + 'padding-right', + ], + 'padding-block-start': ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], + 'padding-block-end': ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], + 'padding-inline': [ + 'padding-inline-start', + 'padding-inline-end', + 'padding-top', + 'padding-bottom', + 'padding-left', + 'padding-right', + ], + 'padding-inline-start': ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], + 'padding-inline-end': ['padding-top', 'padding-bottom', 'padding-left', 'padding-right'], background: [ 'background-image', 'background-size', @@ -153,6 +212,6 @@ module.exports = { 'mask-border-repeat', 'mask-border-slice', 'mask-border-source', - 'mask-border-width' - ] + 'mask-border-width', + ], }; From e7c6d865a460c349f231730b54428ee8dd49b021 Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Sun, 20 Oct 2024 02:14:37 +0200 Subject: [PATCH 13/20] Update dependencies --- .husky/pre-commit | 5 +- jest-setup.js | 2 +- lib/__tests__/test.js | 2 +- lib/getComments.js | 2 +- lib/order/__tests__/order.js | 20 +- .../__tests__/properties-order.js | 60 +- lib/validateOptions.js | 4 +- package-lock.json | 6390 +++++++++-------- package.json | 24 +- 9 files changed, 3533 insertions(+), 2976 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af219..c27d889 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx lint-staged +lint-staged diff --git a/jest-setup.js b/jest-setup.js index 7e9d879..d0855ff 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -19,7 +19,7 @@ global.groupTest = function groupTest(testGroups) { .process(item.fixture, { from: undefined }) .then((root) => { expect(root.css).toEqual(item.expected); - }) + }), ); }); }); diff --git a/lib/__tests__/test.js b/lib/__tests__/test.js index 13479df..6519cdb 100644 --- a/lib/__tests__/test.js +++ b/lib/__tests__/test.js @@ -12,6 +12,6 @@ test(`Should throw an error if config has error`, () => { }; return expect(postcss([plugin(opts)]).process('', { from: undefined })).rejects.toThrow( - 'postcss-sorting: order: Should be an array' + 'postcss-sorting: order: Should be an array', ); }); diff --git a/lib/getComments.js b/lib/getComments.js index 42c2c59..82dffff 100644 --- a/lib/getComments.js +++ b/lib/getComments.js @@ -103,6 +103,6 @@ function afterDeclaration(comments, nextNode, nodeData, currentInitialIndex) { [...comments, commentData], nextNode.next(), nodeData, - commentData.initialIndex + commentData.initialIndex, ); } diff --git a/lib/order/__tests__/order.js b/lib/order/__tests__/order.js index 92b3ccc..3c7a8a3 100644 --- a/lib/order/__tests__/order.js +++ b/lib/order/__tests__/order.js @@ -17,7 +17,7 @@ test('Should assign comments before and after nodes correctly (order)', () => { order: ['custom-properties', 'dollar-variables', 'at-variables', 'declarations'], }, - __dirname + __dirname, )); test('Should sort by keywords', () => @@ -33,7 +33,7 @@ test('Should sort by keywords', () => 'at-rules', ], }, - __dirname + __dirname, )); test('At-rules combination from most specified to least specified', () => @@ -70,7 +70,7 @@ test('At-rules combination from most specified to least specified', () => }, ], }, - __dirname + __dirname, )); test('At-rules mixed combination', () => @@ -104,7 +104,7 @@ test('At-rules mixed combination', () => }, ], }, - __dirname + __dirname, )); test('Should sort inside nested rules', () => @@ -113,7 +113,7 @@ test('Should sort inside nested rules', () => { order: ['custom-properties', 'declarations', 'rules'], }, - __dirname + __dirname, )); test('Should sort inside nested at-rules', () => @@ -122,7 +122,7 @@ test('Should sort inside nested at-rules', () => { order: ['custom-properties', 'declarations', 'at-rules'], }, - __dirname + __dirname, )); test('Should move unspecified nodes to the bottom', () => @@ -131,7 +131,7 @@ test('Should move unspecified nodes to the bottom', () => { order: ['custom-properties', 'declarations'], }, - __dirname + __dirname, )); test('Should preserve indentation', () => @@ -140,7 +140,7 @@ test('Should preserve indentation', () => { order: ['declarations', 'rules', 'at-rules'], }, - __dirname + __dirname, )); groupTest([ @@ -613,7 +613,7 @@ test('Should sort by keywords (styled)', () => { order: ['declarations', 'rules', 'at-rules'], }, - __dirname + __dirname, )); test('Ignore nodes with template literals (styled)', () => @@ -622,5 +622,5 @@ test('Ignore nodes with template literals (styled)', () => { order: ['declarations', 'rules', 'at-rules'], }, - __dirname + __dirname, )); diff --git a/lib/properties-order/__tests__/properties-order.js b/lib/properties-order/__tests__/properties-order.js index 754c6b5..9a7de6f 100644 --- a/lib/properties-order/__tests__/properties-order.js +++ b/lib/properties-order/__tests__/properties-order.js @@ -4,7 +4,7 @@ test('Should sort properties (array config)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Should sort prefixed properties before unprefixed property', () => @@ -13,7 +13,7 @@ test('Should sort prefixed properties before unprefixed property', () => { 'properties-order': ['position', '-webkit-box-sizing', 'box-sizing', 'width'], }, - __dirname + __dirname, )); test('Should assign comments before and after declarations correctly (properties-order)', () => @@ -22,7 +22,7 @@ test('Should assign comments before and after declarations correctly (properties { 'properties-order': ['border-bottom', 'font-style'], }, - __dirname + __dirname, )); test('Should place the leftovers properties in the end (not specified)', () => @@ -31,7 +31,7 @@ test('Should place the leftovers properties in the end (not specified)', () => { 'properties-order': ['position', 'z-index'], }, - __dirname + __dirname, )); test('Should place the leftovers properties in the end (bottom)', () => @@ -41,7 +41,7 @@ test('Should place the leftovers properties in the end (bottom)', () => 'properties-order': ['position', 'z-index'], 'unspecified-properties-position': 'bottom', }, - __dirname + __dirname, )); test('Should place the leftovers properties in the beginning (top)', () => @@ -51,7 +51,7 @@ test('Should place the leftovers properties in the beginning (top)', () => 'properties-order': ['position', 'z-index'], 'unspecified-properties-position': 'top', }, - __dirname + __dirname, )); test('Should place the leftovers properties in the end (bottomAlphabetical)', () => @@ -61,7 +61,7 @@ test('Should place the leftovers properties in the end (bottomAlphabetical)', () 'properties-order': ['position', 'z-index'], 'unspecified-properties-position': 'bottomAlphabetical', }, - __dirname + __dirname, )); test('Should preserve order if properties have same name', () => @@ -70,7 +70,7 @@ test('Should preserve order if properties have same name', () => { 'properties-order': ['position', 'z-index'], }, - __dirname + __dirname, )); test('Should preserve order if properties have same name', () => @@ -79,7 +79,7 @@ test('Should preserve order if properties have same name', () => { 'properties-order': ['position', 'z-index'], }, - __dirname + __dirname, )); test('Should preserve order if properties have same name', () => @@ -88,7 +88,7 @@ test('Should preserve order if properties have same name', () => { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test('Should preserve order if properties have same name (case insensitive)', () => @@ -97,7 +97,7 @@ test('Should preserve order if properties have same name (case insensitive)', () { 'properties-order': ['position', 'z-index'], }, - __dirname + __dirname, )); test('Should preserve order if properties have same name (case insensitive)', () => @@ -106,7 +106,7 @@ test('Should preserve order if properties have same name (case insensitive)', () { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test(`Should not remove first comment in the rule if it's not on separate line (properties-order)`, () => @@ -115,7 +115,7 @@ test(`Should not remove first comment in the rule if it's not on separate line ( { 'properties-order': ['display'], }, - __dirname + __dirname, )); test(`Should sort declarations grouped together between not declarations (without comments)`, () => @@ -124,7 +124,7 @@ test(`Should sort declarations grouped together between not declarations (withou { 'properties-order': ['display', 'position'], }, - __dirname + __dirname, )); test(`Should sort declarations grouped together between not declarations (with comments)`, () => @@ -133,7 +133,7 @@ test(`Should sort declarations grouped together between not declarations (with c { 'properties-order': ['display', 'position'], }, - __dirname + __dirname, )); test(`Should sort declarations scattered everywhere (without comments)`, () => @@ -142,7 +142,7 @@ test(`Should sort declarations scattered everywhere (without comments)`, () => { 'properties-order': ['display', 'position'], }, - __dirname + __dirname, )); test(`Should sort declarations scattered everywhere (with comments)`, () => @@ -151,7 +151,7 @@ test(`Should sort declarations scattered everywhere (with comments)`, () => { 'properties-order': ['display', 'position'], }, - __dirname + __dirname, )); test('Should sort properties alphabetically', () => @@ -160,7 +160,7 @@ test('Should sort properties alphabetically', () => { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test('Should sort properties alphabetically regardless of case', () => { @@ -169,7 +169,7 @@ test('Should sort properties alphabetically regardless of case', () => { { 'properties-order': 'alphabetical', }, - __dirname + __dirname, ); }); @@ -179,7 +179,7 @@ test('Should sort shorthand properties before their longhand versions', () => { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test('Should sort prefixed properties before unprefixed property in alphabetical order', () => @@ -188,7 +188,7 @@ test('Should sort prefixed properties before unprefixed property in alphabetical { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test('Should assign comments before and after declarations correctly (properties-order, alphabetical)', () => @@ -197,7 +197,7 @@ test('Should assign comments before and after declarations correctly (properties { 'properties-order': 'alphabetical', }, - __dirname + __dirname, )); test(`Preserve-empty-lines-between properties`, () => @@ -206,7 +206,7 @@ test(`Preserve-empty-lines-between properties`, () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Should sort properties (styled)', () => @@ -215,7 +215,7 @@ test('Should sort properties (styled)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Should sort properties in nested rules (styled)', () => @@ -224,7 +224,7 @@ test('Should sort properties in nested rules (styled)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Should sort properties in css helper (styled)', () => @@ -233,7 +233,7 @@ test('Should sort properties in css helper (styled)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Ignore template literals in flat components (styled)', () => @@ -242,7 +242,7 @@ test('Ignore template literals in flat components (styled)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Ignore template literals in nested components (styled)', () => @@ -251,7 +251,7 @@ test('Ignore template literals in nested components (styled)', () => { 'properties-order': ['position', 'top', 'display', 'z-index'], }, - __dirname + __dirname, )); test('Should sort properties (html,