From 5e93ebaac18939744f0a8346ef775f6a90b07571 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 31 Aug 2023 09:50:22 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Don=E2=80=99t=20break=20`@apply=20=E2=80=A6?= =?UTF-8?q?=20#{'!important'}`=20sorting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `#{!important}` was already handled but SCSS allows one to wrap it in any number of matched single or double quotes so we check for that as well --- src/index.js | 4 +++- tests/format.test.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index c353aa25..49abe9d4 100644 --- a/src/index.js +++ b/src/index.js @@ -533,7 +533,9 @@ function transformCss(ast, { env }) { if (node.type === 'css-atrule' && node.name === 'apply') { node.params = sortClasses(node.params, { env, - ignoreLast: /\s+(?:!important|#{!important})\s*$/.test(node.params), + ignoreLast: /\s+(?:!important|#{(['"]*)!important\1})\s*$/.test( + node.params, + ), }) } }) diff --git a/tests/format.test.js b/tests/format.test.js index 90c4090b..138d54ba 100644 --- a/tests/format.test.js +++ b/tests/format.test.js @@ -145,7 +145,18 @@ let tests = { // t`
`, ], css: [...css, t`@apply ${yes} !important;`], - scss: [...css, t`@apply ${yes} #{!important};`], + scss: [ + ...css, + t`@apply ${yes} #{!important};`, + t`@apply ${yes} #{'!important'};`, + t`@apply ${yes} #{"!important"};`, + + // These shouldn't ever be used but they are valid + // syntax so we might as well not break them + t`@apply ${yes} #{""!important""};`, + t`@apply ${yes} #{'''!important'''};`, + t`@apply ${yes} #{"'"'"!important"'"'"};`, + ], less: [...css, t`@apply ${yes} !important;`], babel: javascript, typescript: javascript, From c338b1c739d10ebb5dd85573930879d4ed8aeff3 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 31 Aug 2023 09:52:25 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7990812b..4b85b427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Type `tailwindFunctions` and `tailwindAttributes` as optional ([#206](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/206)) +- Don’t break `@apply … #{'!important'}` sorting ([#212](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/212)) ## [0.5.3] - 2023-08-15