Skip to content

Commit 2a09d94

Browse files
committed
ignore dynamic imports
1 parent 85b51fe commit 2a09d94

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

packages/start/scripts/validate-imports.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* - Scans all .ts and .tsx files in the src/ directory recursively
1515
* - Detects relative imports (starting with ./ or ../) without extensions
1616
* - Prevents .js/.jsx imports in TypeScript files (should use .ts/.tsx)
17-
* - Ignores commented code and CSS imports (handled by bundlers)
17+
* - Ignores commented code, CSS imports, and dynamic imports (handled by bundlers)
1818
* - Provides detailed error reporting with line numbers and suggestions
1919
* - Exits with appropriate status codes for CI/CD integration
2020
*
@@ -115,22 +115,23 @@ function extractImportExportStatements(content, filePath) {
115115
// Export from: export { ... } from '...'
116116
/export\s+(?:\{[^}]*\}|\*)\s+from\s+['"`]([^'"`]+)['"`]/g,
117117
// Export default from: export { default } from '...'
118-
/export\s+\{\s*default\s*\}\s+from\s+['"`]([^'"`]+)['"`]/g,
119-
// Dynamic imports: import('...')
120-
/import\s*\(\s*['"`]([^'"`]+)['"`]\s*\)/g
118+
/export\s+\{\s*default\s*\}\s+from\s+['"`]([^'"`]+)['"`]/g
119+
// Note: Dynamic imports are excluded as they're handled by bundlers
121120
];
122121

123122
lines.forEach((line, lineNumber) => {
124123
const trimmedLine = line.trim();
125124

126-
// Skip commented lines and TypeScript type-only imports in d.ts files
125+
// Skip commented lines, dynamic imports, and TypeScript type-only imports in d.ts files
127126
if (
128127
trimmedLine.startsWith("//") ||
129128
trimmedLine.startsWith("/*") ||
130129
trimmedLine.startsWith("*") ||
131130
(filePath.endsWith(".d.ts") && trimmedLine.includes("import(")) ||
132131
// Skip CSS imports as they're handled by bundlers
133-
/import\s+['"`][^'"`]*\.css['"`]/.test(trimmedLine)
132+
/import\s+['"`][^'"`]*\.css['"`]/.test(trimmedLine) ||
133+
// Skip dynamic imports as they're handled by bundlers
134+
/import\s*\(\s*['"`]/.test(trimmedLine)
134135
) {
135136
return;
136137
}

0 commit comments

Comments
 (0)