Dont check for imports in comments (#19026)
* remove all comments from content before checking for imports * lower treshold
This commit is contained in:
@@ -3,7 +3,7 @@ import path from 'path';
|
||||
import { createImportMap } from '../importmap/index.js';
|
||||
|
||||
const ILLEGAL_CORE_IMPORTS_THRESHOLD = 7;
|
||||
const SELF_IMPORTS_THRESHOLD = 12;
|
||||
const SELF_IMPORTS_THRESHOLD = 11;
|
||||
|
||||
const clientProjectRoot = path.resolve(import.meta.dirname, '../../');
|
||||
const modulePrefix = '@umbraco-cms/backoffice/';
|
||||
@@ -51,10 +51,15 @@ function getImportsInFile(filePath) {
|
||||
if (!['.ts'].includes(ext)) return [];
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
|
||||
// remove all comments from the content
|
||||
const regex = /\/\/.*|\/\*[\s\S]*?\*\//gm;
|
||||
const cleanedContent = content.replace(regex, '');
|
||||
|
||||
const imports = [];
|
||||
|
||||
let match;
|
||||
while ((match = importRegex.exec(content)) !== null) {
|
||||
while ((match = importRegex.exec(cleanedContent)) !== null) {
|
||||
imports.push({ type: 'import', value: match[1] });
|
||||
}
|
||||
|
||||
@@ -170,7 +175,7 @@ function reportSelfImportsFromModules() {
|
||||
`Self imports found in ${total} modules. ${total - SELF_IMPORTS_THRESHOLD} more than the threshold.`,
|
||||
);
|
||||
} else {
|
||||
console.log(`✅ Success! Still under the threshold of ${SELF_IMPORTS_THRESHOLD} self imports.`);
|
||||
console.log(`✅ Success! Still (${total}) under the threshold of ${SELF_IMPORTS_THRESHOLD} self imports.`);
|
||||
}
|
||||
|
||||
console.log(`\n\n`);
|
||||
|
||||
Reference in New Issue
Block a user