From 2de9e4ca7107560f71170dfd36ec6330c58766b7 Mon Sep 17 00:00:00 2001 From: Maximilian Franzke Date: Tue, 5 Dec 2023 07:08:12 +0100 Subject: [PATCH] refactor: xo feedback --- scripts/md-resolve-svg.js | 6 ++--- .../pages/foundations/variables/examples.tsx | 2 +- .../patternhub/scripts/get-code-files.js | 2 +- .../patternhub/scripts/get-example-file.js | 4 +-- .../patternhub/scripts/get-properties-file.js | 25 ++++++++++--------- showcases/patternhub/scripts/utils.js | 4 +-- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/scripts/md-resolve-svg.js b/scripts/md-resolve-svg.js index 75f7c11924f..d475930617e 100644 --- a/scripts/md-resolve-svg.js +++ b/scripts/md-resolve-svg.js @@ -25,8 +25,8 @@ const findReplacements = (file, filesToReplace) => { svgName = decodeURI(svgName) .replace('https://img.shields.io/badge/', '') .replace('.svg', '') - .replace(/[^a-zA-Z\d\s]/g, '') - .replace(/ /g, '_'); + .replaceAll(/[^a-zA-Z\d\s]/g, '') + .replaceAll(' ', '_'); const pathname = `${docsPath}/${svgName}`; const pathNameSvg = `${pathname}.svg`; @@ -103,7 +103,7 @@ const convertImages = async () => { // Windows has double backslash for paths filesToReplace = filesToReplace.map((file) => ({ ...file, - files: file.files.map((fileName) => fileName.replace(/\\/g, '/')) + files: file.files.map((fileName) => fileName.replaceAll('\\', '/')) })); startReplacement(filesToReplace); diff --git a/showcases/patternhub/pages/foundations/variables/examples.tsx b/showcases/patternhub/pages/foundations/variables/examples.tsx index fdfd6f53077..581169036f1 100644 --- a/showcases/patternhub/pages/foundations/variables/examples.tsx +++ b/showcases/patternhub/pages/foundations/variables/examples.tsx @@ -43,7 +43,7 @@ const Example = () => {
+ .replaceAll(' ', '-')}`}> {example === 'Spacing fixed' && (
diff --git a/showcases/patternhub/scripts/get-code-files.js b/showcases/patternhub/scripts/get-code-files.js index ce9ecb9f392..06bfb9d638e 100644 --- a/showcases/patternhub/scripts/get-code-files.js +++ b/showcases/patternhub/scripts/get-code-files.js @@ -82,7 +82,7 @@ const writeCodeFiles = async (componentPath, componentName) => { if (FS.existsSync(path)) { variants = JSON.parse(FS.readFileSync(path, 'utf8')).map((variant) => ({ ...variant, - name: variant.name.replace(/\s/g, '').replace(/\W/g, '') + name: variant.name.replaceAll(/\s/g, '').replaceAll(/\W/g, '') })); for (const variant of variants) { if (!FS.existsSync(codePath)) { diff --git a/showcases/patternhub/scripts/get-example-file.js b/showcases/patternhub/scripts/get-example-file.js index 19800a96400..a047974d25f 100644 --- a/showcases/patternhub/scripts/get-example-file.js +++ b/showcases/patternhub/scripts/get-example-file.js @@ -76,8 +76,8 @@ const getOption = (optionName, tsType) => { (property) => `"${getOption(property.key, property.value) .replace('=', '":') - .replace(/{/g, '') - .replace(/}/g, '')}` + .replaceAll('{', '') + .replaceAll('}', '')}` )}}}`; } diff --git a/showcases/patternhub/scripts/get-properties-file.js b/showcases/patternhub/scripts/get-properties-file.js index d5ed456db75..68373df1e2a 100644 --- a/showcases/patternhub/scripts/get-properties-file.js +++ b/showcases/patternhub/scripts/get-properties-file.js @@ -14,15 +14,15 @@ const getOptions = (tsType) => { case 'signature': { return `${tsType.raw - .replace(/\/\*\*\n\t/g, '') - .replace(/\*\/\n\t/g, '') - .replace(/\*/g, '//') - .replace(/{/g, '{') - .replace(/}/g, '}') - .replace(/\r\n\t\t/g, ' ') - .replace(/\t/g, ' ') - .replace(/\r\n|\r|\n/g, '
') - .replace(/\|/g, '|')}`; + .replaceAll('/**\n\t', '') + .replaceAll('*/\n\t', '') + .replaceAll('*', '//') + .replaceAll('{', '{') + .replaceAll('}', '}') + .replaceAll('\r\n\t\t', ' ') + .replaceAll('\t', ' ') + .replaceAll(/\r\n|\r|\n/g, '
') + .replaceAll('|', '|')}`; } case 'union': { @@ -56,13 +56,14 @@ const getPropertiesFile = ({ displayName, description, props }) => { const options = getOptions(prop.tsType); propTable += `| ${propKey} `; propTable += `| ${ - prop.description.replace(/\r\n|\r|\n/g, '
') || 'No description' + prop.description.replaceAll(/\r\n|\r|\n/g, '
') || + 'No description' } `; propTable += `| ${prop.tsType.type ?? prop.tsType.name} `; propTable += `| ${ options - ? `
${options.replace(
-						//g,
+				? `
${options.replaceAll(
+						'',
 						''
 				  )}
` : '' diff --git a/showcases/patternhub/scripts/utils.js b/showcases/patternhub/scripts/utils.js index 69b23ea61a7..b462a50c383 100644 --- a/showcases/patternhub/scripts/utils.js +++ b/showcases/patternhub/scripts/utils.js @@ -55,7 +55,7 @@ export const getCodeByFramework = (componentName, framework, example) => { framework !== 'react' && (props[key] instanceof Object || key === 'click') ) { - value = value.replace(/"/g, "'"); + value = value.replaceAll('"', "'"); } if (framework === 'angular') { @@ -101,7 +101,7 @@ export const getColorVariants = () => [ export const getComponentName = (filePath) => { let componentName = filePath.split('/').at(-1); - componentName = componentName.replace('.tsx', '').replace(/\s/g, ''); + componentName = componentName.replace('.tsx', '').replaceAll(/\s/g, ''); return componentName; };