From e6962e320b3b9b3f122f51442327927292ad5807 Mon Sep 17 00:00:00 2001 From: Lee Chase Date: Tue, 9 Jul 2024 13:44:39 +0100 Subject: [PATCH] fix: partially address issue 124 --- .../motion-duration-use/__tests__/index.js | 50 ++++++++++++++++--- src/rules/theme-use/__tests__/index.js | 10 ++++ src/utils/checkRule.js | 2 +- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/rules/motion-duration-use/__tests__/index.js b/src/rules/motion-duration-use/__tests__/index.js index 6fada79..0f08098 100644 --- a/src/rules/motion-duration-use/__tests__/index.js +++ b/src/rules/motion-duration-use/__tests__/index.js @@ -453,38 +453,76 @@ testRule({ { code: `.foo { transition: all 70ms; }`, fixed: `.foo { transition: all $duration--fast-01; }`, - description: "v11 reject and fix literal duration matching token '70ms'", + description: "v10 reject and fix literal duration matching token '70ms'", message: messages.rejectedTransition('transition', '70ms'), }, { code: `.foo { transition: all 110ms; }`, fixed: `.foo { transition: all $duration--fast-02; }`, - description: "v11 reject and fix literal duration matching token '110ms'", + description: "v10 reject and fix literal duration matching token '110ms'", message: messages.rejectedTransition('transition', '110ms'), }, { code: `.foo { transition: all 150ms; }`, fixed: `.foo { transition: all $duration--moderate-01; }`, - description: "v11 reject and fix literal duration matching token '150ms'", + description: "v10 reject and fix literal duration matching token '150ms'", message: messages.rejectedTransition('transition', '150ms'), }, { code: `.foo { transition: all 240ms; }`, fixed: `.foo { transition: all $duration--moderate-02; }`, - description: "v11 reject and fix literal duration matching token '240ms'", + description: "v10 reject and fix literal duration matching token '240ms'", message: messages.rejectedTransition('transition', '240ms'), }, { code: `.foo { transition: all 400ms; }`, fixed: `.foo { transition: all $duration--slow-01; }`, - description: "v11 reject and fix literal duration matching token '400ms'", + description: "v10 reject and fix literal duration matching token '400ms'", message: messages.rejectedTransition('transition', '400ms'), }, { code: `.foo { transition: all 700ms; }`, fixed: `.foo { transition: all $duration--slow-02; }`, - description: "v11 reject and fix literal duration matching token '700ms'", + description: "v10 reject and fix literal duration matching token '700ms'", message: messages.rejectedTransition('transition', '700ms'), }, ], }); + +testRule({ + plugins: [plugin], + ruleName, + customSyntax: 'postcss-scss', + fix: true, + config: true, + reject: [ + { + code: `@use "@carbon/layout" as layout; .foo { transition: padding 400ms cubic-bezier(0.25, 0.8, 0.075, 1); }`, + fixed: `@use "@carbon/layout" as layout; .foo { transition: padding $duration-slow-01 cubic-bezier(0.25, 0.8, 0.075, 1); }`, + description: `v11 reject and fix 'motion-duration' but and add no prefix`, + message: messages.rejectedTransition('transition', '400ms'), + }, + ], +}); + +// testRule({ +// plugins: [plugin], +// ruleName, +// customSyntax: 'postcss-scss', +// fix: true, +// config: [ +// true, +// { +// enforceScopes: true, +// }, +// ], +// enforceScopes: true, +// reject: [ +// { +// code: `@use "@carbon/layout" as layout; @use "@carbon/motion"; .foo { transition: padding 400ms cubic-bezier(0.25, 0.8, 0.075, 1); }`, +// fixed: `@use "@carbon/layout" as layout; @use "@carbon/motion"; .foo { transition: padding motion.$duration-slow-01 cubic-bezier(0.25, 0.8, 0.075, 1); }`, +// description: `v11 reject and fix 'motion-duration' but and add no prefix`, +// message: messages.rejectedTransition('transition', '400ms'), +// }, +// ], +// }); diff --git a/src/rules/theme-use/__tests__/index.js b/src/rules/theme-use/__tests__/index.js index dff046c..7a51ce9 100644 --- a/src/rules/theme-use/__tests__/index.js +++ b/src/rules/theme-use/__tests__/index.js @@ -676,6 +676,16 @@ testRule({ // fixed: // "@use '@carbon/theme' as carbon_theme; .foo { color: carbon_theme.$button-danger-active; }" // }, + ], +}); + +testRule({ + plugins: [plugin], + ruleName, + config: [true, { enforceScopes: true }], + customSyntax: 'postcss-scss', + fix: true, + reject: [ { code: "@use '@carbon/layout'; @use '@carbon/theme' as carbon_theme; .foo { background-color: $active-danger; }", description: diff --git a/src/utils/checkRule.js b/src/utils/checkRule.js index 31b52c8..c5d0d0a 100644 --- a/src/utils/checkRule.js +++ b/src/utils/checkRule.js @@ -222,7 +222,7 @@ export default async function checkRule( if (!options.enforceScopes && !localScopes.includes('')) { // scopes are not being enforced allow no scope - localScopes.push(''); + localScopes.unshift(''); } // **** walk rules and check values