mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-12-18 20:04:17 +01:00
Fixes from self-review
This commit is contained in:
parent
40d47f224c
commit
ef8d0e529e
@ -30,12 +30,17 @@ function scanForUsedIcons() {
|
||||
// Recursively scan all .tsx and .ts files
|
||||
function scanDirectory(dir) {
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(dir, file);
|
||||
const stat = fs.statSync(filePath);
|
||||
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
// Skip the assets directory to avoid scanning generated files
|
||||
if (file === 'assets') {
|
||||
debug(` Skipping assets directory: ${path.relative(srcDir, filePath)}`);
|
||||
return;
|
||||
}
|
||||
scanDirectory(filePath);
|
||||
} else if (file.endsWith('.tsx') || file.endsWith('.ts')) {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
@ -52,6 +57,18 @@ function scanForUsedIcons() {
|
||||
});
|
||||
}
|
||||
|
||||
// Match React.createElement(LocalIcon, { icon: 'icon-name', ... })
|
||||
const createElementMatches = content.match(/React\.createElement\(LocalIcon,\s*\{[^}]*icon:\s*['"]([^'"]+)['"]/g);
|
||||
if (createElementMatches) {
|
||||
createElementMatches.forEach(match => {
|
||||
const iconMatch = match.match(/icon:\s*['"]([^'"]+)['"]/);
|
||||
if (iconMatch) {
|
||||
usedIcons.add(iconMatch[1]);
|
||||
debug(` Found (createElement): ${iconMatch[1]} in ${path.relative(srcDir, filePath)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Match old material-symbols-rounded spans: <span className="material-symbols-rounded">icon-name</span>
|
||||
const spanMatches = content.match(/<span[^>]*className="[^"]*material-symbols-rounded[^"]*"[^>]*>([^<]+)<\/span>/g);
|
||||
if (spanMatches) {
|
||||
@ -77,21 +94,23 @@ function scanForUsedIcons() {
|
||||
});
|
||||
}
|
||||
|
||||
// Match icon strings in icon configuration files (iconMap.tsx, toolsTaxonomy.ts)
|
||||
// Only scan these specific files to avoid false positives
|
||||
if (filePath.includes('iconMap.tsx') || filePath.includes('toolsTaxonomy.ts')) {
|
||||
// Pattern: : 'icon-name' or : "icon-name" (object value assignment)
|
||||
const configIconMatches = content.match(/:\s*['"]([a-z][a-z0-9-]*(?:-rounded|-outline|-sharp)?)['"][,\s}]/g);
|
||||
if (configIconMatches) {
|
||||
configIconMatches.forEach(match => {
|
||||
const iconMatch = match.match(/:\s*['"]([a-z][a-z0-9-]*(?:-rounded|-outline|-sharp)?)['"][,\s}]/);
|
||||
if (iconMatch && iconMatch[1]) {
|
||||
const iconName = iconMatch[1];
|
||||
// Match icon strings with common Material Symbols suffixes anywhere in the code
|
||||
// Pattern: any string ending with -rounded, -outline, or -sharp that looks like an icon name
|
||||
const iconStringMatches = content.match(/['"]([a-z][a-z0-9-]*(?:-rounded|-outline|-sharp))['"][,\s})]/g);
|
||||
if (iconStringMatches) {
|
||||
iconStringMatches.forEach(match => {
|
||||
const iconMatch = match.match(/['"]([a-z][a-z0-9-]*(?:-rounded|-outline|-sharp))['"][,\s})]/);
|
||||
if (iconMatch && iconMatch[1]) {
|
||||
const iconName = iconMatch[1];
|
||||
// Skip common false positives (CSS classes, file paths, etc.)
|
||||
if (!iconName.includes('/') &&
|
||||
!iconName.startsWith('--') &&
|
||||
iconName.length < 50) {
|
||||
usedIcons.add(iconName);
|
||||
debug(` Found (config): ${iconName} in ${path.relative(srcDir, filePath)}`);
|
||||
debug(` Found (string): ${iconName} in ${path.relative(srcDir, filePath)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -23,7 +23,7 @@ describe('LocalIcon Validation', () => {
|
||||
let grepOutput: string;
|
||||
try {
|
||||
grepOutput = execSync(
|
||||
`grep -r 'LocalIcon' --include="*.tsx" --include="*.ts" ${srcPath} | grep 'icon='`,
|
||||
`grep -r 'LocalIcon' --include="*.tsx" --include="*.ts" --exclude="*.test.ts" --exclude="*.test.tsx" ${srcPath} | grep 'icon='`,
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
} catch (error: any) {
|
||||
|
||||
@ -23,7 +23,7 @@ export const useConfigNavSections = (
|
||||
{
|
||||
key: 'connectionMode',
|
||||
label: t('settings.connection.title', 'Connection Mode'),
|
||||
icon: 'cloud-rounded',
|
||||
icon: 'cloud',
|
||||
component: <ConnectionSettings />,
|
||||
},
|
||||
],
|
||||
@ -53,7 +53,7 @@ export const createConfigNavSections = (
|
||||
{
|
||||
key: 'connectionMode',
|
||||
label: 'Connection Mode',
|
||||
icon: 'cloud-rounded',
|
||||
icon: 'cloud',
|
||||
component: <ConnectionSettings />,
|
||||
},
|
||||
],
|
||||
|
||||
@ -11,7 +11,8 @@ export default defineConfig({
|
||||
exclude: [
|
||||
'node_modules/',
|
||||
'src/**/*.spec.ts', // Exclude Playwright E2E tests
|
||||
'src/tests/test-fixtures/**'
|
||||
'src/tests/test-fixtures/**',
|
||||
'src/assets/**' // Exclude generated icon files
|
||||
],
|
||||
testTimeout: 10000,
|
||||
hookTimeout: 10000,
|
||||
@ -22,7 +23,8 @@ export default defineConfig({
|
||||
'src/core/setupTests.ts',
|
||||
'**/*.d.ts',
|
||||
'src/tests/test-fixtures/**',
|
||||
'src/**/*.spec.ts'
|
||||
'src/**/*.spec.ts',
|
||||
'src/assets/**' // Exclude generated icon files
|
||||
]
|
||||
},
|
||||
projects: [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user