diff --git a/packages/eslint-plugin-pf-codemods/src/index.ts b/packages/eslint-plugin-pf-codemods/src/index.ts index 0418d2fe9..21e8fe7a1 100644 --- a/packages/eslint-plugin-pf-codemods/src/index.ts +++ b/packages/eslint-plugin-pf-codemods/src/index.ts @@ -1,3 +1,4 @@ -export * from './configs'; -export * from './ruleCuration'; -export * from './ruleCustomization' \ No newline at end of file +export * from "./configs"; +export * from "./ruleCuration"; +export * from "./ruleCustomization"; +export * from "./tokenLists"; diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index 487f2cb0a..c876b161a 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -49,7 +49,6 @@ export const warningRules = [ "tabs-update-markup", "tabs-warn-children-type-changed", "Th-Td-warn-update-markup", - "tokens-warn", "toolbarLabelGroupContent-updated-markup", "tooltip-warn-triggerRef-may-be-required", "treeView-warn-selectable-styling-modifier-removed", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/getComponentImportName.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/getComponentImportName.ts index 2d7c83229..b2b9fc524 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/getComponentImportName.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/getComponentImportName.ts @@ -1,6 +1,6 @@ import { ImportSpecifier } from "estree-jsx"; import { ImportDefaultSpecifierWithParent } from "./interfaces"; -import { getDefaultDeclarationString } from "./getDefaultDeclarationString"; +import { getImportPath } from "./getImportPath"; /** Gets the name of an import based on the specifier and an array of names that should be looked for in default import paths */ export function getComponentImportName( @@ -12,6 +12,6 @@ export function getComponentImportName( } return potentialNames.find((name) => - getDefaultDeclarationString(importSpecifier)?.includes(name) + getImportPath(importSpecifier)?.includes(name) ); } diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/getDefaultDeclarationString.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/getDefaultDeclarationString.ts deleted file mode 100644 index 68258614e..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/getDefaultDeclarationString.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ImportDefaultSpecifierWithParent } from "./interfaces"; - -/** Gets the import path string for a default import */ -export function getDefaultDeclarationString( - defaultImportSpecifier: ImportDefaultSpecifierWithParent -) { - return defaultImportSpecifier?.parent?.source.value?.toString(); -} diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/getImportPath.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/getImportPath.ts new file mode 100644 index 000000000..263632b4b --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/getImportPath.ts @@ -0,0 +1,11 @@ +import { + ImportDefaultSpecifierWithParent, + ImportSpecifierWithParent, +} from "./interfaces"; + +/** Gets the import path string for an import specifier (named or default) */ +export function getImportPath( + importSpecifier: ImportDefaultSpecifierWithParent | ImportSpecifierWithParent +) { + return importSpecifier?.parent?.source.value?.toString(); +} diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/index.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/index.ts index 314f1deb5..1026caeac 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/index.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/index.ts @@ -6,10 +6,10 @@ export * from "./getAttributeName"; export * from "./getChildJSXElementByName"; export * from "./getCodeModDataTag"; export * from "./getComponentImportName"; -export * from "./getDefaultDeclarationString"; export * from "./getEndRange"; export * from "./getFromPackage"; export * from "./getImportedName"; +export * from "./getImportPath"; export * from "./getLocalComponentName"; export * from "./getNodeForAttributeFixer"; export * from "./getNodeName"; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts index 5c78f3de6..902ca5ccd 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts @@ -6,7 +6,7 @@ import { JSXOpeningElementWithParent, } from "./interfaces"; import { - getDefaultDeclarationString, + getImportPath, getComponentImportName, getNodeName, hasCodeModDataTag, @@ -90,7 +90,7 @@ export function renameComponent( } return oldNames.some((name) => - getDefaultDeclarationString(imp)?.includes(name) + getImportPath(imp)?.includes(name) ); }); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.md new file mode 100644 index 000000000..eaac6cab4 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.md @@ -0,0 +1,23 @@ +### tokens-update + +We have updated our CSS tokens. About half of our tokens have been replaced with newer ones. + +- this rule provides an autofix for global non color tokens +- global color tokens will be replaced with a temporary hot pink color token **that must be manually replaced** (`t_temp_dev_tbd` react token or `--pf-t--temp--dev--tbd` CSS variable) +- other non-global (component or chart) tokens need to be replaced manually + +To find a suitable replacement token, check our [v6 token documentation](https://staging-v6.patternfly.org/tokens/all-patternfly-tokens). + +#### Examples + +In: + +```jsx +%inputExample% +``` + +Out: + +```jsx +%outputExample% +``` diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.test.ts new file mode 100644 index 000000000..183482d72 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.test.ts @@ -0,0 +1,410 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./tokens-update"; + +const getWarnMessage = (tokenName: string) => + `${tokenName} is an old CSS token. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + +const getFixMessage = (oldToken: string, newToken: string) => + `${oldToken} is an old CSS token and has been replaced with ${newToken}. If you want to use a different token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + +const getColorFixMessage = (oldToken: string, isReactToken = true) => + `${oldToken} is an old color token. This codemod will replace it with a temporary hot pink color token ${ + isReactToken ? "t_temp_dev_tbd" : "--pf-t--temp--dev--tbd" + } to prevent build errors. You should find a suitable replacement token in our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + +ruleTester.run("tokens-warn", rule, { + valid: [ + // token existing in V6 + { + code: `import c_about_modal_box from '@patternfly/react-tokens/dist/esm/c_about_modal_box';`, + }, + // token existing in V6 + { + code: `import { c_about_modal_box } from '@patternfly/react-tokens';`, + }, + ], + invalid: [ + // WARNINGS - tokens + { + code: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens';`, + output: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportSpecifier", + }, + ], + }, + { + // with alias + code: `import { c_badge_PaddingLeft as badgePL } from '@patternfly/react-tokens';`, + output: `import { c_badge_PaddingLeft as badgePL } from '@patternfly/react-tokens';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportSpecifier", + }, + ], + }, + { + // named import - esm + code: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + output: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportSpecifier", + }, + ], + }, + { + // named import - js + code: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens/dist/js/c_badge_PaddingLeft';`, + output: `import { c_badge_PaddingLeft } from '@patternfly/react-tokens/dist/js/c_badge_PaddingLeft';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportSpecifier", + }, + ], + }, + { + // default import - esm + code: `import c_badge_PaddingLeft from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + output: `import c_badge_PaddingLeft from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportDefaultSpecifier", + }, + ], + }, + { + // default import - js + code: `import c_badge_PaddingLeft from '@patternfly/react-tokens/dist/js/c_badge_PaddingLeft';`, + output: `import c_badge_PaddingLeft from '@patternfly/react-tokens/dist/js/c_badge_PaddingLeft';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportDefaultSpecifier", + }, + ], + }, + { + // default import with custom name + code: `import someToken from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + output: `import someToken from '@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft';`, + errors: [ + { + message: getWarnMessage("c_badge_PaddingLeft"), + type: "ImportDefaultSpecifier", + }, + ], + }, + + // WARNINGS - CSS variables + { + code: `document.documentElement.style.setProperty("--pf-v5-c-button--PaddingTop", "2rem");`, + output: `document.documentElement.style.setProperty("--pf-v5-c-button--PaddingTop", "2rem");`, + errors: [ + { + message: getWarnMessage("--pf-v5-c-button--PaddingTop"), + type: "Literal", + }, + ], + }, + { + code: `
Some banner
`, + output: `
Some banner
`, + errors: [ + { + message: getWarnMessage("--pf-v5-c-banner--PaddingBottom"), + type: "Literal", + }, + ], + }, + + // FIXES - non color tokens + { + code: `import { global_FontWeight_normal } from "@patternfly/react-tokens"; + global_FontWeight_normal;`, + output: `import { global_font_weight_body_default } from "@patternfly/react-tokens"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + { + // with alias + code: `import { global_FontWeight_normal as fontW_normal } from "@patternfly/react-tokens"; + fontW_normal;`, + output: `import { global_font_weight_body_default as fontW_normal } from "@patternfly/react-tokens"; + fontW_normal;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportSpecifier", + }, + ], + }, + { + // named import - esm + code: `import { global_FontWeight_normal } from '@patternfly/react-tokens/dist/esm/global_FontWeight_normal'; + global_FontWeight_normal;`, + output: `import { global_font_weight_body_default } from "@patternfly/react-tokens/dist/esm/global_font_weight_body_default"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + { + // named import - js + code: `import { global_FontWeight_normal } from '@patternfly/react-tokens/dist/js/global_FontWeight_normal'; + global_FontWeight_normal;`, + output: `import { global_font_weight_body_default } from "@patternfly/react-tokens/dist/js/global_font_weight_body_default"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + { + // default import - esm + code: `import global_FontWeight_normal from '@patternfly/react-tokens/dist/esm/global_FontWeight_normal'; + global_FontWeight_normal;`, + output: `import global_font_weight_body_default from "@patternfly/react-tokens/dist/esm/global_font_weight_body_default"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportDefaultSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + { + // default import - js + code: `import global_FontWeight_normal from '@patternfly/react-tokens/dist/js/global_FontWeight_normal'; + global_FontWeight_normal;`, + output: `import global_font_weight_body_default from "@patternfly/react-tokens/dist/js/global_font_weight_body_default"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportDefaultSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + { + // default import with custom name + code: `import fontWeightNormal from '@patternfly/react-tokens/dist/esm/global_FontWeight_normal'; + fontWeightNormal;`, + output: `import global_font_weight_body_default from "@patternfly/react-tokens/dist/esm/global_font_weight_body_default"; + global_font_weight_body_default;`, + errors: [ + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "ImportDefaultSpecifier", + }, + { + message: getFixMessage( + "global_FontWeight_normal", + "global_font_weight_body_default" + ), + type: "Identifier", + }, + ], + }, + + // FIXES - non color CSS variables + { + code: `document.documentElement.style.setProperty("--pf-v5-global--ZIndex--lg", "3");`, + output: `document.documentElement.style.setProperty("--pf-t--global--z-index--lg", "3");`, + errors: [ + { + message: getFixMessage( + "--pf-v5-global--ZIndex--lg", + "--pf-t--global--z-index--lg" + ), + type: "Literal", + }, + ], + }, + { + code: `
`, + output: `
`, + errors: [ + { + message: getFixMessage( + "--pf-v5-global--BorderWidth--lg", + "--pf-t--global--border--width--extra-strong" + ), + type: "Literal", + }, + ], + }, + + // FIXES - color tokens + { + code: `import { global_Color_100 } from "@patternfly/react-tokens";`, + output: `import { t_temp_dev_tbd as global_Color_100 /* CODEMODS: you should update this color token */ } from "@patternfly/react-tokens";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportSpecifier", + }, + ], + }, + { + // with alias + code: `import { global_Color_100 as color100 } from "@patternfly/react-tokens";`, + output: `import { t_temp_dev_tbd as color100 /* CODEMODS: you should update this color token, original v5 token was global_Color_100 */ } from "@patternfly/react-tokens";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportSpecifier", + }, + ], + }, + { + // named import - esm + code: `import { global_Color_100 } from '@patternfly/react-tokens/dist/esm/global_Color_100';`, + output: `import { t_temp_dev_tbd as global_Color_100 /* CODEMODS: you should update this color token */ } from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportSpecifier", + }, + ], + }, + { + // named import - js + code: `import { global_Color_100 } from '@patternfly/react-tokens/dist/js/global_Color_100';`, + output: `import { t_temp_dev_tbd as global_Color_100 /* CODEMODS: you should update this color token */ } from "@patternfly/react-tokens/dist/js/t_temp_dev_tbd";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportSpecifier", + }, + ], + }, + { + // default import - esm + code: `import global_Color_100 from '@patternfly/react-tokens/dist/esm/global_Color_100';`, + output: `import global_Color_100/* CODEMODS: you should update this color token */ from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportDefaultSpecifier", + }, + ], + }, + { + // default import - js + code: `import global_Color_100 from '@patternfly/react-tokens/dist/js/global_Color_100';`, + output: `import global_Color_100/* CODEMODS: you should update this color token */ from "@patternfly/react-tokens/dist/js/t_temp_dev_tbd";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportDefaultSpecifier", + }, + ], + }, + { + // default import with custom name + code: `import someColor from '@patternfly/react-tokens/dist/esm/global_Color_100';`, + output: `import someColor/* CODEMODS: you should update this color token, original v5 token was global_Color_100 */ from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd";`, + errors: [ + { + message: getColorFixMessage("global_Color_100"), + type: "ImportDefaultSpecifier", + }, + ], + }, + + // FIXES - color CSS variables + { + code: `document.documentElement.style.setProperty("--pf-v5-global--success-color--200", "#abc");`, + output: `document.documentElement.style.setProperty("--pf-t--temp--dev--tbd"/* CODEMODS: original v5 color was --pf-v5-global--success-color--200 */, "#abc");`, + errors: [ + { + message: getColorFixMessage("--pf-v5-global--success-color--200", false), + type: "Literal", + }, + ], + }, + { + code: `
`, + output: `
`, + errors: [ + { + message: getColorFixMessage("--pf-v5-global--Color--100", false), + type: "Literal", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts new file mode 100644 index 000000000..094d9864c --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokens-update.ts @@ -0,0 +1,282 @@ +import { Rule } from "eslint"; +import { + IdentifierWithParent, + ImportDefaultSpecifierWithParent, + ImportSpecifierWithParent, + getDefaultImportsFromPackage, + getFromPackage, + getImportPath, +} from "../../helpers"; +import { Identifier, ImportSpecifier, Literal } from "estree-jsx"; +import { + oldTokens, + oldCssVarNamesV5, + globalNonColorTokensMap, + oldGlobalNonColorTokens, + globalNonColorCssVarNamesMap, + oldGlobalColorCssVarNames, + oldGlobalColorTokens, +} from "../../../tokenLists"; + +module.exports = { + meta: { fixable: "code" }, + create: function (context: Rule.RuleContext) { + const tokensPackage = "@patternfly/react-tokens"; + + const { imports: tokenSpecifiers } = getFromPackage(context, tokensPackage); + + const defaultTokenSpecifiers = getDefaultImportsFromPackage( + context, + tokensPackage + ) + .map((specifier) => ({ + specifier, + path: getImportPath(specifier), + })) + .filter(({ path }) => path !== undefined) + .map(({ specifier, path }) => ({ + specifier, + token: (path as string).split("/").pop() as string, + })); + + const getWarnMessage = (tokenName: string) => + `${tokenName} is an old CSS token. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + + const getFixMessage = (oldToken: string, newToken: string) => + `${oldToken} is an old CSS token and has been replaced with ${newToken}. If you want to use a different token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + + const getColorFixMessage = (oldToken: string, isReactToken = true) => + `${oldToken} is an old color token. This codemod will replace it with a temporary hot pink color token ${ + isReactToken ? "t_temp_dev_tbd" : "--pf-t--temp--dev--tbd" + } to prevent build errors. You should find a suitable replacement token in our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; + + const shouldReplaceToken = (token: string) => + oldGlobalNonColorTokens.includes(token) && + globalNonColorTokensMap[token as keyof typeof globalNonColorTokensMap] !== + "SKIP"; + + const getTokenPathFix = ( + fixer: Rule.RuleFixer, + node: ImportSpecifierWithParent | ImportDefaultSpecifierWithParent, + oldToken: string, + newToken: string + ) => { + const packagePath = getImportPath(node); + if (packagePath && packagePath.includes(oldToken)) { + const newPath = packagePath.replace(oldToken, newToken); + return fixer.replaceText(node.parent?.source!, `"${newPath}"`); + } + }; + + const replaceToken = ( + node: + | ImportSpecifierWithParent + | ImportDefaultSpecifierWithParent + | Identifier, + oldToken: string + ) => { + const newToken = + globalNonColorTokensMap[ + oldToken as keyof typeof globalNonColorTokensMap + ]; + + context.report({ + node, + message: getFixMessage(oldToken, newToken), + fix(fixer) { + if (node.type === "Identifier") { + return fixer.replaceText(node, newToken); + } + + const tokenPathFix = getTokenPathFix(fixer, node, oldToken, newToken); + + return [ + fixer.replaceText( + node.type === "ImportSpecifier" ? node.imported : node, + newToken + ), + ...(tokenPathFix ? [tokenPathFix] : []), + ]; + }, + }); + }; + + const updateColorTokenImport = ( + node: ImportSpecifierWithParent | ImportDefaultSpecifierWithParent, + token: string + ) => { + // either has an aliased named import, or a default import with a custom name (not matching the token in an import path) + const hasAlias = node.local.name !== token; + + const comment = `/* CODEMODS: you should update this color token${ + hasAlias ? `, original v5 token was ${token}` : "" + } */`; + + context.report({ + node, + message: getColorFixMessage(token), + fix(fixer) { + const fixes = []; + const tokenPathFix = getTokenPathFix( + fixer, + node, + token, + "t_temp_dev_tbd" + ); + + if (tokenPathFix) { + fixes.push(tokenPathFix); + } + + if (node.type === "ImportSpecifier") { + fixes.push( + fixer.replaceText( + node, + `t_temp_dev_tbd as ${node.local.name} ${comment}` + ) + ); + } else { + fixes.push(fixer.insertTextAfter(node, comment)); + } + + return fixes; + }, + }); + }; + + const handleToken = ( + node: ImportSpecifierWithParent | ImportDefaultSpecifierWithParent, + token: string + ) => { + if (oldGlobalColorTokens.includes(token)) { + updateColorTokenImport(node, token); + return; + } + + if (shouldReplaceToken(token)) { + replaceToken(node, token); + return; + } + + if (oldTokens.includes(token)) { + context.report({ + node, + message: getWarnMessage(token), + }); + } + }; + + return { + ImportSpecifier(node: ImportSpecifier) { + if (tokenSpecifiers.includes(node)) { + const token = node.imported.name; + handleToken(node, token); + } + }, + ImportDefaultSpecifier(node: ImportDefaultSpecifierWithParent) { + const specifierWithToken = defaultTokenSpecifiers.find( + ({ specifier }) => node === specifier + ); + + if (!specifierWithToken) { + return; + } + + handleToken(node, specifierWithToken.token); + }, + Identifier(node: Identifier) { + const parentType = (node as IdentifierWithParent).parent?.type; + // handle ImportSpecifier and ImportDeclaration separately + if ( + parentType === "ImportSpecifier" || + parentType === "ImportDefaultSpecifier" + ) { + return; + } + + const tokenInfo = defaultTokenSpecifiers.find( + ({ specifier }) => node.name === specifier.local.name + ); + + if (tokenInfo && shouldReplaceToken(tokenInfo.token)) { + replaceToken(node, tokenInfo.token); + } + + const unaliasedTokenSpecifier = tokenSpecifiers.find( + (specifier) => + specifier.local.name === specifier.imported.name && + node.name === specifier.local.name + ); + + if (unaliasedTokenSpecifier && shouldReplaceToken(node.name)) { + replaceToken(node, node.name); + } + }, + Literal(node: Literal) { + if (typeof node.value !== "string") { + return; + } + + let varName = node.value; + const varRegex = /var\(([^)]+)\)/; + const varRegexMatch = node.value.match(varRegex); + + if (varRegexMatch) { + varName = varRegexMatch[1]; + } + + if (oldGlobalColorCssVarNames.includes(varName)) { + const comment = `/* CODEMODS: original v5 color was ${varName} */`; + + context.report({ + node, + message: getColorFixMessage(varName, false), + fix(fixer) { + return fixer.replaceText( + node, + varRegexMatch + ? `"var(--pf-t--temp--dev--tbd)"${comment}` + : `"--pf-t--temp--dev--tbd"${comment}` + ); + }, + }); + return; + } + + const newVarName = + globalNonColorCssVarNamesMap[ + varName as keyof typeof globalNonColorCssVarNamesMap + ]; + + const shouldReplaceVar = newVarName && newVarName !== "SKIP"; + + if (shouldReplaceVar) { + context.report({ + node, + message: getFixMessage(varName, newVarName), + fix(fixer) { + return fixer.replaceText( + node, + varRegexMatch ? `"var(${newVarName})"` : `"${newVarName}"` + ); + }, + }); + return; + } + + if (oldCssVarNames.includes(varName)) { + context.report({ + node, + message: getWarnMessage(varName), + }); + } + }, + }; + }, +}; + +// consumers may have run the old class-name-updater before codemods, so we should check also old tokens with v6 prefix +const oldCssVarNamesV6 = oldCssVarNamesV5.map((cssVarName) => + cssVarName.replace("v5", "v6") +); +const oldCssVarNames = [...oldCssVarNamesV5, ...oldCssVarNamesV6]; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateInput.tsx new file mode 100644 index 000000000..48c20abbc --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateInput.tsx @@ -0,0 +1,47 @@ +// replacements (fixable with --fix) +import global_BorderWidth_lg from "@patternfly/react-tokens/dist/esm/global_BorderWidth_lg"; +import { global_FontWeight_normal } from "@patternfly/react-tokens"; + +global_BorderWidth_lg; +global_FontWeight_normal; + +document.documentElement.style.setProperty("--pf-v5-global--ZIndex--lg", "3"); +
; + +// warnings (not fixable) +import c_badge_PaddingLeft from "@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft"; +import { c_alert__FontSize } from "@patternfly/react-tokens"; + +c_badge_PaddingLeft; +c_alert__FontSize; + +
; + +// Colors +import global_Color_100 from "@patternfly/react-tokens/dist/esm/global_Color_100"; +import { global_Color_200 } from "@patternfly/react-tokens/dist/esm/global_Color_200"; +import { global_Color_300 as color300 } from "@patternfly/react-tokens/dist/esm/global_Color_300"; +import { global_BorderColor_100 } from "@patternfly/react-tokens"; + +global_Color_100; +global_Color_200; +color300; +global_BorderColor_100; + +
; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateOutput.tsx new file mode 100644 index 000000000..bb8ae527c --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensUpdate/tokensUpdateOutput.tsx @@ -0,0 +1,47 @@ +// replacements (fixable with --fix) +import global_border_width_extra_strong from "@patternfly/react-tokens/dist/esm/global_border_width_extra_strong"; +import { global_font_weight_body_default } from "@patternfly/react-tokens"; + +global_border_width_extra_strong; +global_font_weight_body_default; + +document.documentElement.style.setProperty("--pf-t--global--z-index--lg", "3"); +
; + +// warnings (not fixable) +import c_badge_PaddingLeft from "@patternfly/react-tokens/dist/esm/c_badge_PaddingLeft"; +import { c_alert__FontSize } from "@patternfly/react-tokens"; + +c_badge_PaddingLeft; +c_alert__FontSize; + +
; + +// Colors +import global_Color_100/* CODEMODS: you should update this color token */ from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd"; +import { t_temp_dev_tbd as global_Color_200 /* CODEMODS: you should update this color token */ } from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd"; +import { t_temp_dev_tbd as color300 /* CODEMODS: you should update this color token, original v5 token was global_Color_300 */ } from "@patternfly/react-tokens/dist/esm/t_temp_dev_tbd"; +import { t_temp_dev_tbd as global_BorderColor_100 /* CODEMODS: you should update this color token */ } from "@patternfly/react-tokens"; + +global_Color_100; +global_Color_200; +color300; +global_BorderColor_100; + +
; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.md deleted file mode 100644 index 43f4b5e3f..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.md +++ /dev/null @@ -1,17 +0,0 @@ -### tokens-warn - -We have updated our CSS tokens. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our [v6 token documentation](https://staging-v6.patternfly.org/tokens/all-patternfly-tokens). - -#### Examples - -In: - -```jsx -%inputExample% -``` - -Out: - -```jsx -%outputExample% -``` diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.test.ts deleted file mode 100644 index 2e97bea21..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.test.ts +++ /dev/null @@ -1,117 +0,0 @@ -const ruleTester = require("../../ruletester"); -import * as rule from "./tokens-warn"; - -const getWarnMessage = (tokenName: string) => - `${tokenName} is an old CSS token. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; - -ruleTester.run("tokens-warn", rule, { - valid: [ - // token existing in V6 - { - code: `import c_about_modal_box from '@patternfly/react-tokens/dist/esm/c_about_modal_box';`, - }, - // token existing in V6 - { - code: `import { c_about_modal_box } from '@patternfly/react-tokens';`, - }, - ], - invalid: [ - { - code: `import { global_info_color_100 } from '@patternfly/react-tokens';`, - output: `import { global_info_color_100 } from '@patternfly/react-tokens';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportSpecifier", - }, - ], - }, - // with alias - { - code: `import { global_info_color_100 as infoColor } from '@patternfly/react-tokens';`, - output: `import { global_info_color_100 as infoColor } from '@patternfly/react-tokens';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportSpecifier", - }, - ], - }, - { - // named import - esm - code: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - output: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportSpecifier", - }, - ], - }, - { - // named import - js - code: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/js/global_info_color_100';`, - output: `import { global_info_color_100 } from '@patternfly/react-tokens/dist/js/global_info_color_100';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportSpecifier", - }, - ], - }, - { - // default import - esm - code: `import global_info_color_100 from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - output: `import global_info_color_100 from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportDeclaration", - }, - ], - }, - { - // default import - js - code: `import global_info_color_100 from '@patternfly/react-tokens/dist/js/global_info_color_100';`, - output: `import global_info_color_100 from '@patternfly/react-tokens/dist/js/global_info_color_100';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportDeclaration", - }, - ], - }, - { - // default import with custom name - code: `import someToken from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - output: `import someToken from '@patternfly/react-tokens/dist/esm/global_info_color_100';`, - errors: [ - { - message: getWarnMessage("global_info_color_100"), - type: "ImportDeclaration", - }, - ], - }, - // CSS variables in strings - { - code: `
`, - output: `
`, - errors: [ - { - message: getWarnMessage("--pf-v5-global--success-color--200"), - type: "Literal", - }, - ], - }, - { - code: `
`, - output: `
`, - errors: [ - { - message: getWarnMessage("var(--pf-v5-global--BorderWidth--lg)"), - type: "Literal", - }, - ], - }, - ], -}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.ts deleted file mode 100644 index ca9eebf26..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokens-warn.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { Rule } from "eslint"; -import { - getDefaultDeclarationString, - getDefaultImportsFromPackage, - getFromPackage, -} from "../../helpers"; -import { ImportDeclaration, ImportSpecifier, Literal } from "estree-jsx"; -import { oldTokens } from "./tokenLists/oldTokens"; -import { oldCssVarNamesV5 } from "./tokenLists/oldCssVarNamesV5"; - -module.exports = { - meta: {}, - create: function (context: Rule.RuleContext) { - const tokensPackage = "@patternfly/react-tokens"; - - const { imports: tokenSpecifiers } = getFromPackage(context, tokensPackage); - - const defaultTokensWithDeclaration = getDefaultImportsFromPackage( - context, - tokensPackage - ) - .map((specifier) => ({ - path: getDefaultDeclarationString(specifier), - declaration: specifier.parent, - })) - .filter(({ path }) => path !== undefined) - .map(({ path, declaration }) => ({ - token: (path as string).split("/").pop() as string, - declaration, - })); - - const getMessage = (tokenName: string) => - `${tokenName} is an old CSS token. About half of our tokens have been replaced with newer ones. To find a suitable replacement token, check our new documentation https://staging-v6.patternfly.org/tokens/all-patternfly-tokens.`; - - return { - ImportSpecifier(node: ImportSpecifier) { - if (tokenSpecifiers.includes(node)) { - const tokenName = node.imported.name; - if (oldTokens.includes(tokenName)) { - context.report({ - node, - message: getMessage(tokenName), - }); - } - } - }, - ImportDeclaration(node: ImportDeclaration) { - const tokenWithDeclaration = defaultTokensWithDeclaration.find( - ({ declaration }) => node.source.value === declaration?.source.value - ); - - if ( - tokenWithDeclaration && - oldTokens.includes(tokenWithDeclaration.token) - ) { - context.report({ - node, - message: getMessage(tokenWithDeclaration.token), - }); - } - }, - Literal(node: Literal) { - if ( - typeof node.value === "string" && - [...oldCssVarNames, ...oldCssVars].includes(node.value) - ) { - context.report({ - node, - message: getMessage(node.value), - }); - } - }, - }; - }, -}; - -// consumers may run class-name-updater before codemods, so we have to check also old tokens with v6 prefix -const oldCssVarNamesV6 = oldCssVarNamesV5.map((cssVarName) => - cssVarName.replace("v5", "v6") -); -const oldCssVarNames = [...oldCssVarNamesV5, ...oldCssVarNamesV6]; -const oldCssVars = oldCssVarNames.map((cssVarName) => `var(${cssVarName})`); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnInput.tsx deleted file mode 100644 index fa7840bcb..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnInput.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import global_warning_color_100 from "@patternfly/react-tokens/dist/esm/global_warning_color_100"; -import { c_alert__FontSize } from "@patternfly/react-tokens"; - -global_warning_color_100; -c_alert__FontSize; - -<> -
-
-; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnOutput.tsx deleted file mode 100644 index fa7840bcb..000000000 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokensWarnOutput.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import global_warning_color_100 from "@patternfly/react-tokens/dist/esm/global_warning_color_100"; -import { c_alert__FontSize } from "@patternfly/react-tokens"; - -global_warning_color_100; -c_alert__FontSize; - -<> -
-
-; diff --git a/packages/eslint-plugin-pf-codemods/src/tokenLists/index.ts b/packages/eslint-plugin-pf-codemods/src/tokenLists/index.ts new file mode 100644 index 000000000..c10fd44e7 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/tokenLists/index.ts @@ -0,0 +1,4 @@ +export * from "./oldCssVarNamesV5"; +export * from "./oldGlobalCssVarNames"; +export * from "./oldGlobalTokens"; +export * from "./oldTokens"; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokenLists/oldCssVarNamesV5.ts b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldCssVarNamesV5.ts similarity index 99% rename from packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokenLists/oldCssVarNamesV5.ts rename to packages/eslint-plugin-pf-codemods/src/tokenLists/oldCssVarNamesV5.ts index 9776278e9..7887402fd 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokenLists/oldCssVarNamesV5.ts +++ b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldCssVarNamesV5.ts @@ -1,4 +1,4 @@ -// names of css variables of the oldTokens list +// names of css variables for each token of the oldTokens list export const oldCssVarNamesV5 = [ "--pf-v5-c-about-modal-box__brand--PaddingBottom", "--pf-v5-c-about-modal-box__brand--PaddingLeft", diff --git a/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalCssVarNames.ts b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalCssVarNames.ts new file mode 100644 index 000000000..2a6939d08 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalCssVarNames.ts @@ -0,0 +1,271 @@ +// Map of old global non-color CSS vars used in V5 and their suitable replacement CSS var in V6 +// values and optional replacements are described in oldGlobalTokens.ts file +export const globalNonColorCssVarNamesMap = { + "--pf-v5-global--BorderRadius--lg": "--pf-t--global--border--radius--large", + "--pf-v5-global--BorderRadius--sm": "--pf-t--global--border--radius--small", + "--pf-v5-global--BorderWidth--lg": + "--pf-t--global--border--width--extra-strong", + "--pf-v5-global--BorderWidth--md": "--pf-t--global--border--width--strong", + "--pf-v5-global--BorderWidth--sm": "--pf-t--global--border--width--regular", + "--pf-v5-global--BorderWidth--xl": + "--pf-t--global--border--width--extra-strong", + "--pf-v5-global--BoxShadow--inset": "SKIP", + "--pf-v5-global--BoxShadow--lg": "--pf-t--global--box-shadow--lg", + "--pf-v5-global--BoxShadow--lg-bottom": + "--pf-t--global--box-shadow--lg--bottom", + "--pf-v5-global--BoxShadow--lg-left": "--pf-t--global--box-shadow--lg--left", + "--pf-v5-global--BoxShadow--lg-right": + "--pf-t--global--box-shadow--lg--right", + "--pf-v5-global--BoxShadow--lg-top": "--pf-t--global--box-shadow--lg--top", + "--pf-v5-global--BoxShadow--md": "--pf-t--global--box-shadow--md", + "--pf-v5-global--BoxShadow--md-bottom": + "--pf-t--global--box-shadow--md--bottom", + "--pf-v5-global--BoxShadow--md-left": "--pf-t--global--box-shadow--md--left", + "--pf-v5-global--BoxShadow--md-right": + "--pf-t--global--box-shadow--md--right", + "--pf-v5-global--BoxShadow--md-top": "--pf-t--global--box-shadow--md--top", + "--pf-v5-global--BoxShadow--sm": "--pf-t--global--box-shadow--sm", + "--pf-v5-global--BoxShadow--sm-bottom": + "--pf-t--global--box-shadow--sm--bottom", + "--pf-v5-global--BoxShadow--sm-left": "--pf-t--global--box-shadow--sm--left", + "--pf-v5-global--BoxShadow--sm-right": + "--pf-t--global--box-shadow--sm--right", + "--pf-v5-global--BoxShadow--sm-top": "--pf-t--global--box-shadow--sm--top", + "--pf-v5-global--BoxShadow--xl": "--pf-t--global--box-shadow--lg", + "--pf-v5-global--BoxShadow--xl-bottom": + "--pf-t--global--box-shadow--lg--bottom", + "--pf-v5-global--BoxShadow--xl-left": "--pf-t--global--box-shadow--lg--left", + "--pf-v5-global--BoxShadow--xl-right": + "--pf-t--global--box-shadow--lg--right", + "--pf-v5-global--BoxShadow--xl-top": "--pf-t--global--box-shadow--lg--top", + "--pf-v5-global--FontFamily--heading": + "--pf-t--global--font--family--heading", + "--pf-v5-global--FontFamily--heading--vf": + "--pf-t--global--font--family--heading", + "--pf-v5-global--FontFamily--monospace": "--pf-t--global--font--family--mono", + "--pf-v5-global--FontFamily--monospace--vf": + "--pf-t--global--font--family--mono", + "--pf-v5-global--FontFamily--text": "--pf-t--global--font--family--body", + "--pf-v5-global--FontFamily--text--vf": "--pf-t--global--font--family--body", + "--pf-v5-global--FontSize--2xl": "--pf-t--global--font--size--2xl", + "--pf-v5-global--FontSize--3xl": "--pf-t--global--font--size--3xl", + "--pf-v5-global--FontSize--4xl": "--pf-t--global--font--size--4xl", + "--pf-v5-global--FontSize--lg": "--pf-t--global--font--size--lg", + "--pf-v5-global--FontSize--md": "--pf-t--global--font--size--md", + "--pf-v5-global--FontSize--sm": "--pf-t--global--font--size--sm", + "--pf-v5-global--FontSize--xl": "--pf-t--global--font--size--xl", + "--pf-v5-global--FontSize--xs": "--pf-t--global--font--size--xs", + "--pf-v5-global--FontWeight--bold": + "--pf-t--global--font--weight--heading--bold", + "--pf-v5-global--FontWeight--normal": + "--pf-t--global--font--weight--body--default", + "--pf-v5-global--LineHeight--md": "--pf-t--global--font--line-height--body", + "--pf-v5-global--LineHeight--sm": + "--pf-t--global--font--line-height--heading", + "--pf-v5-global--ListStyle": "--pf-t--global--list-style", + "--pf-v5-global--TimingFunction": + "--pf-t--global--transition--timing-function", + "--pf-v5-global--Transition": "--pf-t--global--transition", + "--pf-v5-global--TransitionDuration": "--pf-t--global--transition--duration", + "--pf-v5-global--ZIndex--2xl": "--pf-t--global--z-index--2xl", + "--pf-v5-global--ZIndex--lg": "--pf-t--global--z-index--lg", + "--pf-v5-global--ZIndex--md": "--pf-t--global--z-index--md", + "--pf-v5-global--ZIndex--sm": "--pf-t--global--z-index--sm", + "--pf-v5-global--ZIndex--xl": "--pf-t--global--z-index--xl", + "--pf-v5-global--ZIndex--xs": "--pf-t--global--z-index--xs", + "--pf-v5-global--arrow--width": "SKIP", + "--pf-v5-global--arrow--width-lg": "SKIP", + "--pf-v5-global--font-path": "SKIP", + "--pf-v5-global--fonticon-path": "SKIP", + "--pf-v5-global--gutter": "--pf-t--global--spacer--gutter--default", + "--pf-v5-global--gutter--md": "--pf-t--global--spacer--lg", + "--pf-v5-global--height-breakpoint--2xl": + "--pf-t--global--breakpoint--height--2xl", + "--pf-v5-global--height-breakpoint--lg": + "--pf-t--global--breakpoint--height--lg", + "--pf-v5-global--height-breakpoint--md": + "--pf-t--global--breakpoint--height--md", + "--pf-v5-global--height-breakpoint--sm": + "--pf-t--global--breakpoint--height--sm", + "--pf-v5-global--height-breakpoint--xl": + "--pf-t--global--breakpoint--height--xl", + "--pf-v5-global--icon--FontSize--lg": "--pf-t--global--icon--size--font--2xl", + "--pf-v5-global--icon--FontSize--md": "--pf-t--global--icon--size--font--md", + "--pf-v5-global--icon--FontSize--sm": "--pf-t--global--icon--size--font--xs", + "--pf-v5-global--icon--FontSize--xl": "--pf-t--global--icon--size--font--4xl", + "--pf-v5-global--link--TextDecoration": + "--pf-t--global--text-decoration--link--line--default", + "--pf-v5-global--link--TextDecoration--hover": + "--pf-t--global--text-decoration--link--line--hover", + "--pf-v5-global--spacer--form-element": "--pf-t--global--spacer--xs", + "--pf-v5-global--target-size--MinHeight": "SKIP", + "--pf-v5-global--target-size--MinWidth": "SKIP", + + // These CSS vars have the same React token names in V5 and V6, but vars need an update: [-v5-] transforms to [-t--] + "--pf-v5-global--breakpoint--2xl": "--pf-t--global--breakpoint--2xl", + "--pf-v5-global--breakpoint--lg": "--pf-t--global--breakpoint--lg", + "--pf-v5-global--breakpoint--md": "--pf-t--global--breakpoint--md", + "--pf-v5-global--breakpoint--sm": "--pf-t--global--breakpoint--sm", + "--pf-v5-global--breakpoint--xl": "--pf-t--global--breakpoint--xl", + "--pf-v5-global--breakpoint--xs": "--pf-t--global--breakpoint--xs", + "--pf-v5-global--inverse--multiplier": "--pf-t--global--inverse--multiplier", + "--pf-v5-global--spacer--2xl": "--pf-t--global--spacer--2xl", + "--pf-v5-global--spacer--3xl": "--pf-t--global--spacer--3xl", + "--pf-v5-global--spacer--4xl": "--pf-t--global--spacer--4xl", + "--pf-v5-global--spacer--lg": "--pf-t--global--spacer--lg", + "--pf-v5-global--spacer--md": "--pf-t--global--spacer--md", + "--pf-v5-global--spacer--sm": "--pf-t--global--spacer--sm", + "--pf-v5-global--spacer--xl": "--pf-t--global--spacer--xl", + "--pf-v5-global--spacer--xs": "--pf-t--global--spacer--xs", +}; + +export const oldGlobalNonColorCssVarNames = Object.keys( + globalNonColorCssVarNamesMap +); + +export const oldGlobalColorCssVarNames = [ + "--pf-v5-global--BackgroundColor--100", + "--pf-v5-global--BackgroundColor--150", + "--pf-v5-global--BackgroundColor--200", + "--pf-v5-global--BackgroundColor--dark-100", + "--pf-v5-global--BackgroundColor--dark-200", + "--pf-v5-global--BackgroundColor--dark-300", + "--pf-v5-global--BackgroundColor--dark-400", + "--pf-v5-global--BackgroundColor--dark-transparent-100", + "--pf-v5-global--BackgroundColor--dark-transparent-200", + "--pf-v5-global--BackgroundColor--light-100", + "--pf-v5-global--BackgroundColor--light-200", + "--pf-v5-global--BackgroundColor--light-300", + "--pf-v5-global--BorderColor--100", + "--pf-v5-global--BorderColor--200", + "--pf-v5-global--BorderColor--300", + "--pf-v5-global--BorderColor--dark-100", + "--pf-v5-global--BorderColor--light-100", + "--pf-v5-global--Color--100", + "--pf-v5-global--Color--200", + "--pf-v5-global--Color--300", + "--pf-v5-global--Color--400", + "--pf-v5-global--Color--dark-100", + "--pf-v5-global--Color--dark-200", + "--pf-v5-global--Color--light-100", + "--pf-v5-global--Color--light-200", + "--pf-v5-global--Color--light-300", + "--pf-v5-global--active-color--100", + "--pf-v5-global--active-color--200", + "--pf-v5-global--active-color--300", + "--pf-v5-global--active-color--400", + "--pf-v5-global--custom-color--100", + "--pf-v5-global--custom-color--200", + "--pf-v5-global--custom-color--300", + "--pf-v5-global--danger-color--100", + "--pf-v5-global--danger-color--200", + "--pf-v5-global--danger-color--300", + "--pf-v5-global--disabled-color--100", + "--pf-v5-global--disabled-color--200", + "--pf-v5-global--disabled-color--300", + "--pf-v5-global--icon--Color--dark", + "--pf-v5-global--icon--Color--dark--dark", + "--pf-v5-global--icon--Color--dark--light", + "--pf-v5-global--icon--Color--light", + "--pf-v5-global--icon--Color--light--dark", + "--pf-v5-global--icon--Color--light--light", + "--pf-v5-global--info-color--100", + "--pf-v5-global--info-color--200", + "--pf-v5-global--link--Color", + "--pf-v5-global--link--Color--dark", + "--pf-v5-global--link--Color--dark--hover", + "--pf-v5-global--link--Color--hover", + "--pf-v5-global--link--Color--light", + "--pf-v5-global--link--Color--light--hover", + "--pf-v5-global--link--Color--visited", + "--pf-v5-global--palette--black-100", + "--pf-v5-global--palette--black-1000", + "--pf-v5-global--palette--black-150", + "--pf-v5-global--palette--black-200", + "--pf-v5-global--palette--black-300", + "--pf-v5-global--palette--black-400", + "--pf-v5-global--palette--black-500", + "--pf-v5-global--palette--black-600", + "--pf-v5-global--palette--black-700", + "--pf-v5-global--palette--black-800", + "--pf-v5-global--palette--black-850", + "--pf-v5-global--palette--black-900", + "--pf-v5-global--palette--blue-100", + "--pf-v5-global--palette--blue-200", + "--pf-v5-global--palette--blue-300", + "--pf-v5-global--palette--blue-400", + "--pf-v5-global--palette--blue-50", + "--pf-v5-global--palette--blue-500", + "--pf-v5-global--palette--blue-600", + "--pf-v5-global--palette--blue-700", + "--pf-v5-global--palette--cyan-100", + "--pf-v5-global--palette--cyan-200", + "--pf-v5-global--palette--cyan-300", + "--pf-v5-global--palette--cyan-400", + "--pf-v5-global--palette--cyan-50", + "--pf-v5-global--palette--cyan-500", + "--pf-v5-global--palette--cyan-600", + "--pf-v5-global--palette--cyan-700", + "--pf-v5-global--palette--gold-100", + "--pf-v5-global--palette--gold-200", + "--pf-v5-global--palette--gold-300", + "--pf-v5-global--palette--gold-400", + "--pf-v5-global--palette--gold-50", + "--pf-v5-global--palette--gold-500", + "--pf-v5-global--palette--gold-600", + "--pf-v5-global--palette--gold-700", + "--pf-v5-global--palette--green-100", + "--pf-v5-global--palette--green-200", + "--pf-v5-global--palette--green-300", + "--pf-v5-global--palette--green-400", + "--pf-v5-global--palette--green-50", + "--pf-v5-global--palette--green-500", + "--pf-v5-global--palette--green-600", + "--pf-v5-global--palette--green-700", + "--pf-v5-global--palette--light-blue-100", + "--pf-v5-global--palette--light-blue-200", + "--pf-v5-global--palette--light-blue-300", + "--pf-v5-global--palette--light-blue-400", + "--pf-v5-global--palette--light-blue-500", + "--pf-v5-global--palette--light-blue-600", + "--pf-v5-global--palette--light-blue-700", + "--pf-v5-global--palette--light-green-100", + "--pf-v5-global--palette--light-green-200", + "--pf-v5-global--palette--light-green-300", + "--pf-v5-global--palette--light-green-400", + "--pf-v5-global--palette--light-green-500", + "--pf-v5-global--palette--light-green-600", + "--pf-v5-global--palette--light-green-700", + "--pf-v5-global--palette--orange-100", + "--pf-v5-global--palette--orange-200", + "--pf-v5-global--palette--orange-300", + "--pf-v5-global--palette--orange-400", + "--pf-v5-global--palette--orange-50", + "--pf-v5-global--palette--orange-500", + "--pf-v5-global--palette--orange-600", + "--pf-v5-global--palette--orange-700", + "--pf-v5-global--palette--purple-100", + "--pf-v5-global--palette--purple-200", + "--pf-v5-global--palette--purple-300", + "--pf-v5-global--palette--purple-400", + "--pf-v5-global--palette--purple-50", + "--pf-v5-global--palette--purple-500", + "--pf-v5-global--palette--purple-600", + "--pf-v5-global--palette--purple-700", + "--pf-v5-global--palette--red-100", + "--pf-v5-global--palette--red-200", + "--pf-v5-global--palette--red-300", + "--pf-v5-global--palette--red-400", + "--pf-v5-global--palette--red-50", + "--pf-v5-global--palette--red-500", + "--pf-v5-global--palette--white", + "--pf-v5-global--primary-color--100", + "--pf-v5-global--primary-color--200", + "--pf-v5-global--primary-color--dark-100", + "--pf-v5-global--primary-color--light-100", + "--pf-v5-global--secondary-color--100", + "--pf-v5-global--success-color--100", + "--pf-v5-global--success-color--200", + "--pf-v5-global--warning-color--100", + "--pf-v5-global--warning-color--200", +]; diff --git a/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalTokens.ts b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalTokens.ts new file mode 100644 index 000000000..31c4148b4 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldGlobalTokens.ts @@ -0,0 +1,227 @@ +// Map of old global non-color tokens used in V5 and their suitable replacement token in V6 +export const globalNonColorTokensMap = { + global_BorderRadius_lg: "global_border_radius_large", // 30em -> 24px + global_BorderRadius_sm: "global_border_radius_small", // 3px -> 6px (optionally global_border_radius_tiny = 4px) + global_BorderWidth_lg: "global_border_width_extra_strong", + global_BorderWidth_md: "global_border_width_strong", + global_BorderWidth_sm: "global_border_width_regular", + global_BorderWidth_xl: "global_border_width_extra_strong", // 4px -> 3px + global_BoxShadow_inset: "SKIP", // NO SUITABLE REPLACEMENT, value: inset 0 0 0.625rem 0 rgba(3, 3, 3, 0.25) + global_BoxShadow_lg: "global_box_shadow_lg", + global_BoxShadow_lg_bottom: "global_box_shadow_lg_bottom", + global_BoxShadow_lg_left: "global_box_shadow_lg_left", + global_BoxShadow_lg_right: "global_box_shadow_lg_right", + global_BoxShadow_lg_top: "global_box_shadow_lg_top", + global_BoxShadow_md: "global_box_shadow_md", + global_BoxShadow_md_bottom: "global_box_shadow_md_bottom", + global_BoxShadow_md_left: "global_box_shadow_md_left", + global_BoxShadow_md_right: "global_box_shadow_md_right", + global_BoxShadow_md_top: "global_box_shadow_md_top", + global_BoxShadow_sm: "global_box_shadow_sm", + global_BoxShadow_sm_bottom: "global_box_shadow_sm_bottom", + global_BoxShadow_sm_left: "global_box_shadow_sm_left", + global_BoxShadow_sm_right: "global_box_shadow_sm_right", + global_BoxShadow_sm_top: "global_box_shadow_sm_top", + global_BoxShadow_xl: "global_box_shadow_lg", // no 'xl' shadow available, will use 'lg' + global_BoxShadow_xl_bottom: "global_box_shadow_lg_bottom", + global_BoxShadow_xl_left: "global_box_shadow_lg_left", + global_BoxShadow_xl_right: "global_box_shadow_lg_right", + global_BoxShadow_xl_top: "global_box_shadow_lg_top", + global_FontFamily_heading: "global_font_family_heading", // (optionally use global_font_family_heading_legacy) + global_FontFamily_heading_vf: "global_font_family_heading", // (optionally use global_font_family_heading_legacy) + global_FontFamily_monospace: "global_font_family_mono", // (optionally use global_font_family_mono_legacy) + global_FontFamily_monospace_vf: "global_font_family_mono", // (optionally use global_font_family_mono_legacy) + global_FontFamily_text: "global_font_family_body", // (optionally use global_font_family_body_legacy) + global_FontFamily_text_vf: "global_font_family_body", // (optionally use global_font_family_body_legacy) + global_FontSize_2xl: "global_font_size_2xl", // 1.5rem -> 1.375rem + global_FontSize_3xl: "global_font_size_3xl", + global_FontSize_4xl: "global_font_size_4xl", + global_FontSize_lg: "global_font_size_lg", + global_FontSize_md: "global_font_size_md", + global_FontSize_sm: "global_font_size_sm", + global_FontSize_xl: "global_font_size_xl", + global_FontSize_xs: "global_font_size_xs", + global_FontWeight_bold: "global_font_weight_heading_bold", // or global_font_weight_heading_default + global_FontWeight_normal: "global_font_weight_body_default", + global_LineHeight_md: "global_font_line_height_body", + global_LineHeight_sm: "global_font_line_height_heading", + global_ListStyle: "global_list_style", + global_TimingFunction: "global_transition_timing_function", + global_Transition: "global_transition", + global_TransitionDuration: "global_transition_duration", + global_ZIndex_2xl: "global_z_index_2xl", + global_ZIndex_lg: "global_z_index_lg", + global_ZIndex_md: "global_z_index_md", + global_ZIndex_sm: "global_z_index_sm", + global_ZIndex_xl: "global_z_index_xl", + global_ZIndex_xs: "global_z_index_xs", + global_arrow_width: "SKIP", // NO SUITABLE REPLACEMENT, value: 0.9375rem + global_arrow_width_lg: "SKIP", // NO SUITABLE REPLACEMENT, value: 1.5625rem + global_font_path: "SKIP", // NO SUITABLE REPLACEMENT, value: "./assets/fonts" + global_fonticon_path: "SKIP", // NO SUITABLE REPLACEMENT, value: "./assets/pficon" + global_gutter: "global_spacer_gutter_default", + global_gutter_md: "global_spacer_lg", + global_height_breakpoint_2xl: "global_breakpoint_height_2xl", + global_height_breakpoint_lg: "global_breakpoint_height_lg", + global_height_breakpoint_md: "global_breakpoint_height_md", + global_height_breakpoint_sm: "global_breakpoint_height_sm", + global_height_breakpoint_xl: "global_breakpoint_height_xl", + global_icon_FontSize_lg: "global_icon_size_font_2xl", // 1.5rem -> 1.375rem + global_icon_FontSize_md: "global_icon_size_font_md", + global_icon_FontSize_sm: "global_icon_size_font_xs", + global_icon_FontSize_xl: "global_icon_size_font_4xl", // 3.375rem -> 2.25rem + global_link_TextDecoration: "global_text_decoration_link_line_default", // optionally global_text_decoration_line_100 for no underline + global_link_TextDecoration_hover: "global_text_decoration_link_line_hover", + global_spacer_form_element: "global_spacer_xs", // 0.375rem -> 0.25rem (or global_spacer_sm = 0.5rem) + global_target_size_MinHeight: "SKIP", // NO SUITABLE REPLACEMENT, value: 44px + global_target_size_MinWidth: "SKIP", // NO SUITABLE REPLACEMENT, value: 44px +}; + +export const oldGlobalNonColorTokens = Object.keys(globalNonColorTokensMap); + +export const oldGlobalColorTokens = [ + "global_BackgroundColor_100", + "global_BackgroundColor_150", + "global_BackgroundColor_200", + "global_BackgroundColor_dark_100", + "global_BackgroundColor_dark_200", + "global_BackgroundColor_dark_300", + "global_BackgroundColor_dark_400", + "global_BackgroundColor_dark_transparent_100", + "global_BackgroundColor_dark_transparent_200", + "global_BackgroundColor_light_100", + "global_BackgroundColor_light_200", + "global_BackgroundColor_light_300", + "global_BorderColor_100", + "global_BorderColor_200", + "global_BorderColor_300", + "global_BorderColor_dark_100", + "global_BorderColor_light_100", + "global_Color_100", + "global_Color_200", + "global_Color_300", + "global_Color_400", + "global_Color_dark_100", + "global_Color_dark_200", + "global_Color_light_100", + "global_Color_light_200", + "global_Color_light_300", + "global_active_color_100", + "global_active_color_200", + "global_active_color_300", + "global_active_color_400", + "global_custom_color_100", + "global_custom_color_200", + "global_custom_color_300", + "global_danger_color_100", + "global_danger_color_200", + "global_danger_color_300", + "global_disabled_color_100", + "global_disabled_color_200", + "global_disabled_color_300", + "global_icon_Color_dark", + "global_icon_Color_dark_dark", + "global_icon_Color_dark_light", + "global_icon_Color_light", + "global_icon_Color_light_dark", + "global_icon_Color_light_light", + "global_info_color_100", + "global_info_color_200", + "global_link_Color", + "global_link_Color_dark", + "global_link_Color_dark_hover", + "global_link_Color_hover", + "global_link_Color_light", + "global_link_Color_light_hover", + "global_link_Color_visited", + "global_palette_black_100", + "global_palette_black_1000", + "global_palette_black_150", + "global_palette_black_200", + "global_palette_black_300", + "global_palette_black_400", + "global_palette_black_500", + "global_palette_black_600", + "global_palette_black_700", + "global_palette_black_800", + "global_palette_black_850", + "global_palette_black_900", + "global_palette_blue_100", + "global_palette_blue_200", + "global_palette_blue_300", + "global_palette_blue_400", + "global_palette_blue_50", + "global_palette_blue_500", + "global_palette_blue_600", + "global_palette_blue_700", + "global_palette_cyan_100", + "global_palette_cyan_200", + "global_palette_cyan_300", + "global_palette_cyan_400", + "global_palette_cyan_50", + "global_palette_cyan_500", + "global_palette_cyan_600", + "global_palette_cyan_700", + "global_palette_gold_100", + "global_palette_gold_200", + "global_palette_gold_300", + "global_palette_gold_400", + "global_palette_gold_50", + "global_palette_gold_500", + "global_palette_gold_600", + "global_palette_gold_700", + "global_palette_green_100", + "global_palette_green_200", + "global_palette_green_300", + "global_palette_green_400", + "global_palette_green_50", + "global_palette_green_500", + "global_palette_green_600", + "global_palette_green_700", + "global_palette_light_blue_100", + "global_palette_light_blue_200", + "global_palette_light_blue_300", + "global_palette_light_blue_400", + "global_palette_light_blue_500", + "global_palette_light_blue_600", + "global_palette_light_blue_700", + "global_palette_light_green_100", + "global_palette_light_green_200", + "global_palette_light_green_300", + "global_palette_light_green_400", + "global_palette_light_green_500", + "global_palette_light_green_600", + "global_palette_light_green_700", + "global_palette_orange_100", + "global_palette_orange_200", + "global_palette_orange_300", + "global_palette_orange_400", + "global_palette_orange_50", + "global_palette_orange_500", + "global_palette_orange_600", + "global_palette_orange_700", + "global_palette_purple_100", + "global_palette_purple_200", + "global_palette_purple_300", + "global_palette_purple_400", + "global_palette_purple_50", + "global_palette_purple_500", + "global_palette_purple_600", + "global_palette_purple_700", + "global_palette_red_100", + "global_palette_red_200", + "global_palette_red_300", + "global_palette_red_400", + "global_palette_red_50", + "global_palette_red_500", + "global_palette_white", + "global_primary_color_100", + "global_primary_color_200", + "global_primary_color_dark_100", + "global_primary_color_light_100", + "global_secondary_color_100", + "global_success_color_100", + "global_success_color_200", + "global_warning_color_100", + "global_warning_color_200", +]; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokenLists/oldTokens.ts b/packages/eslint-plugin-pf-codemods/src/tokenLists/oldTokens.ts similarity index 100% rename from packages/eslint-plugin-pf-codemods/src/rules/v6/tokensWarn/tokenLists/oldTokens.ts rename to packages/eslint-plugin-pf-codemods/src/tokenLists/oldTokens.ts