From b295978ded29e8e53eae2b20f9d16af3b2e500d5 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 4 Oct 2022 16:04:19 -0400 Subject: [PATCH] Fix compilation with breaking type changes from https://github.com/stylelint/stylelint/pull/6264 --- .../src/rules/no-color-literal.ts | 31 ++++++++++--------- .../src/rules/no-prefix-literal.ts | 11 ++++--- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/stylelint-plugin/src/rules/no-color-literal.ts b/packages/stylelint-plugin/src/rules/no-color-literal.ts index 15010d7d42..fc619b51bd 100644 --- a/packages/stylelint-plugin/src/rules/no-color-literal.ts +++ b/packages/stylelint-plugin/src/rules/no-color-literal.ts @@ -42,8 +42,7 @@ interface Options { variablesImportPath?: Partial, string>>; } -export default stylelint.createPlugin( - ruleName, +const ruleImpl = (enabled: boolean, options: Options | undefined, context: PluginContext) => (root: Root, result: PostcssResult) => { if (!enabled) { return; @@ -124,8 +123,12 @@ export default stylelint.createPlugin( decl.value = parsedValue.toString(); } }); - }, -); + }; + +ruleImpl.ruleName = ruleName; +ruleImpl.messages = messages; + +export default stylelint.createPlugin(ruleName, ruleImpl); function declarationValueIndex(decl: Declaration) { const beforeColon = decl.toString().indexOf(":"); @@ -133,6 +136,16 @@ function declarationValueIndex(decl: Declaration) { return beforeColon + afterColon; } +function getHexToColorName(): { [upperHex: string]: string } { + const ret: { [key: string]: string } = {}; + for (const [name, hex] of Object.entries(Colors)) { + ret[normalizeHexColor(hex)] = name; + } + return ret; +} + +const hexToColorName = getHexToColorName(); + /** * Returns a CSS color variable for a given hex color, or undefined if one doesn't exist. */ @@ -143,13 +156,3 @@ function getCssColorVariable(hexColor: string, cssSyntax: CssSyntax.SASS | CssSy } return BpVariablePrefixMap[cssSyntax] + hexToColorName[normalizedHex].toLocaleLowerCase().split("_").join("-"); } - -function getHexToColorName(): { [upperHex: string]: string } { - const ret: { [key: string]: string } = {}; - for (const [name, hex] of Object.entries(Colors)) { - ret[normalizeHexColor(hex)] = name; - } - return ret; -} - -const hexToColorName = getHexToColorName(); diff --git a/packages/stylelint-plugin/src/rules/no-prefix-literal.ts b/packages/stylelint-plugin/src/rules/no-prefix-literal.ts index f95edd1ff2..9756484b75 100644 --- a/packages/stylelint-plugin/src/rules/no-prefix-literal.ts +++ b/packages/stylelint-plugin/src/rules/no-prefix-literal.ts @@ -42,8 +42,7 @@ interface Options { variablesImportPath?: Partial, string>>; } -export default stylelint.createPlugin( - ruleName, +const ruleImpl = (enabled: boolean, options: Options | undefined, context: PluginContext) => (root: Root, result: PostcssResult) => { if (!enabled) { return; @@ -119,5 +118,9 @@ export default stylelint.createPlugin( }); }).processSync(rule.selector); }); - }, -); + }; + +ruleImpl.ruleName = ruleName; +ruleImpl.messages = messages; + +export default stylelint.createPlugin(ruleName, ruleImpl);