|
14 | 14 | * - Scans all .ts and .tsx files in the src/ directory recursively |
15 | 15 | * - Detects relative imports (starting with ./ or ../) without extensions |
16 | 16 | * - 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) |
18 | 18 | * - Provides detailed error reporting with line numbers and suggestions |
19 | 19 | * - Exits with appropriate status codes for CI/CD integration |
20 | 20 | * |
@@ -115,22 +115,23 @@ function extractImportExportStatements(content, filePath) { |
115 | 115 | // Export from: export { ... } from '...' |
116 | 116 | /export\s+(?:\{[^}]*\}|\*)\s+from\s+['"`]([^'"`]+)['"`]/g, |
117 | 117 | // 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 |
121 | 120 | ]; |
122 | 121 |
|
123 | 122 | lines.forEach((line, lineNumber) => { |
124 | 123 | const trimmedLine = line.trim(); |
125 | 124 |
|
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 |
127 | 126 | if ( |
128 | 127 | trimmedLine.startsWith("//") || |
129 | 128 | trimmedLine.startsWith("/*") || |
130 | 129 | trimmedLine.startsWith("*") || |
131 | 130 | (filePath.endsWith(".d.ts") && trimmedLine.includes("import(")) || |
132 | 131 | // 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) |
134 | 135 | ) { |
135 | 136 | return; |
136 | 137 | } |
|
0 commit comments