Skip to content

Commit 85aa548

Browse files
Merge pull request #4908 from OneCommunityGlobal/fix/sonarcloud-issues-development-v2
Sayali: 🔥 sonarcloud issues development v2
2 parents 9ecb141 + 73c0b4d commit 85aa548

4 files changed

Lines changed: 17 additions & 33 deletions

File tree

postinstall.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Script to copy tinymce to public folder. Read more: https://www.tiny.cloud/docs/tinymce/latest/react-pm-host/
22
const fse = require('fs-extra');
3-
const path = require('path');
3+
const path = require('node:path');
44

55
const topDir = __dirname;
6-
// const topDir = import.meta.dirname;
76
fse.emptyDirSync(path.join(topDir, 'public', 'tinymce'));
87
fse.copySync(path.join(topDir, 'node_modules', 'tinymce'), path.join(topDir, 'public', 'tinymce'), {
98
overwrite: true,

public/emailFormat.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html>
3-
<head>
2+
<html lang="en">
3+
<head>
44
<title>Hello, World</title>
5-
</head>
6-
<body>
5+
</head>
6+
<body>
77
<h1>Hello, World</h1>
8-
</body>
8+
</body>
99
</html>

public/index.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ body.bm-dashboard-dark:not(.no-global-theme) {
1212
background-color: #1b2a41 !important;
1313
color: #ffffff !important;
1414
}
15-
1615
body.dark-mode:not(.no-global-theme) #root,
1716
body.bm-dashboard-dark:not(.no-global-theme) #root {
1817
background-color: #1b2a41 !important;
1918
color: #ffffff !important;
2019
}
2120

22-
/* SAFE BASE (dark mode) */
23-
body.dark-mode:not(.no-global-theme),
24-
body.bm-dashboard-dark:not(.no-global-theme) {
25-
color: #ffffff;
26-
}
27-
2821
/* ========================= */
2922
/* TYPOGRAPHY (DARK MODE) */
3023
/* ========================= */

refactor-css-classes.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// updated on june 11
22
/* eslint-disable import/no-extraneous-dependencies */
33
/* eslint-disable no-console */
4-
const fs = require('fs');
5-
const path = require('path');
4+
const fs = require('node:fs');
5+
const path = require('node:path');
66
const postcss = require('postcss');
77
const safeParser = require('postcss-safe-parser');
88

99
// Helper to convert kebab-case, snake_case, pascalcase to camelCase
1010
const toCamelCase = str => {
11-
const formatted = str.replace(/[-_](\w)/g, (_, char) => char.toUpperCase());
11+
const formatted = str.replaceAll(/[-_](\w)/gu, (_, char) => char.toUpperCase());
1212
return formatted.charAt(0).toLowerCase() + formatted.slice(1);
1313
};
1414

@@ -21,7 +21,7 @@ const convertCSSFile = filePath => {
2121

2222
root.walkRules(rule => {
2323
const updated = rule.selectors.map(selector => {
24-
return selector.replace(/\.(\w[\w-]*)/g, (_, className) => {
24+
return selector.replaceAll(/\.(\w[\w-]*)/gu, (_, className) => {
2525
const camel = toCamelCase(className);
2626
classMap[className] = camel;
2727
return `.${camel}`;
@@ -32,15 +32,12 @@ const convertCSSFile = filePath => {
3232
});
3333

3434
fs.writeFileSync(filePath, root.toString());
35-
// eslint-disable-next-line no-console
3635
console.log(`✅ Updated CSS: ${filePath}`);
37-
// eslint-disable-next-line no-console
38-
// console.log('classMap after CSS processing:', classMap);
3936
};
4037

4138
// Step 2: Replace import statement for CSS module in JSX
4239
const replaceImportStatement = code => {
43-
const importRegex = /import\s+['"](.+\/)?([a-zA-Z0-9_-]+)\.css['"];/;
40+
const importRegex = /import\s+['"](.+\/)?([a-zA-Z0-9_-]+)\.css['"];/u;
4441
// eslint-disable-next-line default-param-last
4542
return code.replace(importRegex, (_, pathPrefix = '', cssFileName) => {
4643
return `import styles from '${pathPrefix}${cssFileName}.module.css';`;
@@ -64,8 +61,8 @@ const replaceInCodeFile = filePath => {
6461
}
6562

6663
// Step 2: Replace className="text-light input-file-upload" → className={styles.textLight + " " + styles.inputFileUpload}
67-
code = code.replace(/className\s*=\s*["']([^"']+)["']/g, (_, classStr) => {
68-
const classList = classStr.trim().split(/\s+/);
64+
code = code.replaceAll(/className\s*=\s*["']([^"']+)["']/gu, (_, classStr) => {
65+
const classList = classStr.trim().split(/\s+/u);
6966

7067
// Skip transforming if no class in classList exists in classMap
7168
if (classList.every(cls => !classMap[cls])) {
@@ -98,36 +95,31 @@ const walkDir = dir => {
9895
if (stats.isDirectory()) {
9996
walkDir(fullPath);
10097
} else if (file.endsWith('.css')) {
101-
cssFiles.push(fullPath); // Add CSS file path to the array
98+
cssFiles.push(fullPath);
10299
} else if (
103100
file.endsWith('.js') ||
104101
file.endsWith('.jsx') ||
105102
file.endsWith('.ts') ||
106103
file.endsWith('.tsx') ||
107104
file.endsWith('.html')
108105
) {
109-
codeFiles.push(fullPath); // Add JS/JSX file path to the array
106+
codeFiles.push(fullPath);
110107
}
111108
});
112109

113110
// Now process CSS files first
114111
cssFiles.forEach(cssFile => {
115112
console.log('Processing CSS file:', cssFile);
116-
convertCSSFile(cssFile); // Process CSS files
113+
convertCSSFile(cssFile);
117114
});
118115

119116
// Then process code files (JS/JSX, etc.)
120117
codeFiles.forEach(codeFile => {
121118
console.log('Processing code file:', codeFile);
122-
replaceInCodeFile(codeFile); // Process JS/JSX files
119+
replaceInCodeFile(codeFile);
123120
});
124121
};
125122

126123
// 🚀 Start here: Replace with your actual project folder path
127124
const rootDir = 'src/components/HGNForm';
128125
walkDir(rootDir);
129-
130-
// const mapPath = path.join(__dirname, 'class-map.json');
131-
// fs.writeFileSync(mapPath, JSON.stringify(classMap, null, 2));
132-
// // eslint-disable-next-line no-console
133-
// console.log(`🗺️ Class map written to ${mapPath}`);

0 commit comments

Comments
 (0)