Add code checker

This commit is contained in:
2026-03-20 21:58:27 +01:00
parent 0bc329df24
commit eb3910d7ea
2 changed files with 62 additions and 0 deletions
+1
View File
@@ -39,6 +39,7 @@
"test-watch": "npm run test-js -- --watch", "test-watch": "npm run test-js -- --watch",
"test-ts": "node --max-old-space-size=8192 ./node_modules/mocha/bin/mocha \"src/ts/tests/**/*.spec.ts\" -r ts-node/register -R progress --exit", "test-ts": "node --max-old-space-size=8192 ./node_modules/mocha/bin/mocha \"src/ts/tests/**/*.spec.ts\" -r ts-node/register -R progress --exit",
"test-ts-watch": "npm run test -- --watch --watch-extensions ts", "test-ts-watch": "npm run test -- --watch --watch-extensions ts",
"check-code": "node ./src/scripts/experiments/checkCode.js",
"test-inspect": "mocha \"src/scripts/tests/**/*.spec.js\" -R progress --inspect --exit --watch", "test-inspect": "mocha \"src/scripts/tests/**/*.spec.js\" -R progress --inspect --exit --watch",
"update-angular": "npm update @angular/common @angular/compiler @angular/core @angular/forms @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/animations @angular/compiler-cli @angular/platform-server @angular/cdk --save", "update-angular": "npm update @angular/common @angular/compiler @angular/core @angular/forms @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/animations @angular/compiler-cli @angular/platform-server @angular/cdk --save",
"latest-angular": "npm i @angular/common@latest @angular/compiler@latest @angular/core@latest @angular/forms@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/router@latest @angular/animations@latest @angular/compiler-cli@latest @angular/platform-server@latest @angular/cdk@latest --save", "latest-angular": "npm i @angular/common@latest @angular/compiler@latest @angular/core@latest @angular/forms@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/router@latest @angular/animations@latest @angular/compiler-cli@latest @angular/platform-server@latest @angular/cdk@latest --save",
+61
View File
@@ -0,0 +1,61 @@
import * as path from 'path';
import * as fs from 'fs';
const lookForClient = ['common', 'client' , 'graphics', 'components'];
const lookForServer = ['common', 'server' , 'graphics', 'components'];
const ignores = [['common', 'encoders']].map(l => path.join(...l));
const base = ['src', 'ts'];
const clientChecks = lookForClient.map(e => path.join(process.cwd(), ...base, e));
const serverChecks = lookForServer.map(e => path.join(process.cwd(), ...base, e));
let issues = 0;
let checked = 0;
function processDir(pathStr: string, client = false) {
const files = fs.readdirSync(pathStr, { withFileTypes: true });
for (const file of files) {
const filePath = path.join(pathStr, file.name);
if (ignores.some(n => filePath.includes(n))) {
continue;
}
if (file.isDirectory()) {
processDir(filePath);
} else if (file.isFile()) {
if (file.name.endsWith('.ts')) {
const lines = fs.readFileSync(filePath, 'utf-8').split('\n').map(l => l.trim());
checked++;
const filter = lines.filter(l => client ? /.*import.*from.*['"`].*\/client\/.*['"`]/.test(l) : /.*import.*from.*['"`].*\/server\/.*['"`]/.test(l));
if (filter.length) {
issues++;
console.warn('='.repeat(16));
console.log(filePath);
for (const line of filter) {
console.log(` ${lines.indexOf(line) + 1}| ${line}`);
}
console.warn('='.repeat(16));
}
}
} else {
console.log(`File not supported ${pathStr}`);
}
}
}
function main() {
for (const check of clientChecks) {
processDir(check, true);
}
for (const check of serverChecks) {
processDir(check, true);
}
if (issues) {
console.log(`Found ${issues} issues in ${checked} files`);
} else {
console.log(`Checked ${checked} files no issues have been found`);
}
}
main();