Skip to content

Commit

Permalink
refactor: xo feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranzke committed Dec 5, 2023
1 parent b104233 commit 2de9e4c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions scripts/md-resolve-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Example = () => {
<div
className={`example-${example
.toLowerCase()
.replace(/ /g, '-')}`}>
.replaceAll(' ', '-')}`}>
{example === 'Spacing fixed' && (
<div>
<DBIcon icon="account">
Expand Down
2 changes: 1 addition & 1 deletion showcases/patternhub/scripts/get-code-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions showcases/patternhub/scripts/get-example-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const getOption = (optionName, tsType) => {
(property) =>
`"${getOption(property.key, property.value)
.replace('=', '":')
.replace(/{/g, '')
.replace(/}/g, '')}`
.replaceAll('{', '')
.replaceAll('}', '')}`
)}}}`;
}

Expand Down
25 changes: 13 additions & 12 deletions showcases/patternhub/scripts/get-properties-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const getOptions = (tsType) => {

case 'signature': {
return `${tsType.raw
.replace(/\/\*\*\n\t/g, '')
.replace(/\*\/\n\t/g, '')
.replace(/\*/g, '//')
.replace(/{/g, '&#123;')
.replace(/}/g, '&#125;')
.replace(/\r\n\t\t/g, ' ')
.replace(/\t/g, '&ensp;')
.replace(/\r\n|\r|\n/g, '<br/>')
.replace(/\|/g, '&#124;')}`;
.replaceAll('/**\n\t', '')
.replaceAll('*/\n\t', '')
.replaceAll('*', '//')
.replaceAll('{', '&#123;')
.replaceAll('}', '&#125;')
.replaceAll('\r\n\t\t', ' ')
.replaceAll('\t', '&ensp;')
.replaceAll(/\r\n|\r|\n/g, '<br/>')
.replaceAll('|', '&#124;')}`;
}

case 'union': {
Expand Down Expand Up @@ -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, '<br/>') || 'No description'
prop.description.replaceAll(/\r\n|\r|\n/g, '<br/>') ||
'No description'
} `;
propTable += `| ${prop.tsType.type ?? prop.tsType.name} `;
propTable += `| ${
options
? `<pre><code className="code-pre-wrap">${options.replace(
/<T>/g,
? `<pre><code className="code-pre-wrap">${options.replaceAll(
'<T>',
''
)}</code></pre>`
: ''
Expand Down
4 changes: 2 additions & 2 deletions showcases/patternhub/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 2de9e4c

Please sign in to comment.