diff --git a/package.json b/package.json index 7cc28a97..e7183fdd 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "vrms-server", "version": "0.3.0", "description": "VRMS Server", + "type": "module", "scripts": { "start": "concurrently \"cd backend && npm run start\" \"cd client && npm run start\"", "mvp": "concurrently \"cd backend && npm run start\" \"cd client-mvp-04 && npm run start\"", @@ -16,7 +17,8 @@ "test:backend": "cd backend && npm run test", "test:client": "cd client && npm run test", "test:all": "cross-env NODE_ENV=test npm run test:client && npm run test:backend", - "prepare": "husky install" + "prepare": "husky install", + "lint:files": "node scripts/list-lint-files.js" }, "dependencies": { "@mui/icons-material": "^5.14.19", diff --git a/scripts/list-lint-files.js b/scripts/list-lint-files.js new file mode 100644 index 00000000..05c764a7 --- /dev/null +++ b/scripts/list-lint-files.js @@ -0,0 +1,46 @@ +//import node modules for running shell commands and handling files, define file names +import { execSync } from "child_process"; +import fs from "fs"; +const reportFile = "lint-report.json"; +const countFile = "lint-files.count.txt"; + +// Generate report +const generateReports = (results, exitCode) => { + const countContent = `After running the lint found total number of the files has linting problems: ${results.length}`; + fs.writeFileSync(countFile, countContent, "utf-8"); + console.log( + `Found ${results.length} files with linting errors. Total written to ${countFile}`, + ); + + const modifiedResults = results.map((result) => { + const vrmsIndex = result.filePath.indexOf("VRMS"); + const relativePath = result.filePath.substring(vrmsIndex + 4); + return { ...result, filePath: relativePath }; + }); + + const formattedJson = JSON.stringify(modifiedResults, null, 2); + fs.writeFileSync(reportFile, formattedJson, "utf-8"); + + console.log(`Lint report created: ${reportFile}`); + process.exit(exitCode); +}; + +try { + const stdout = execSync("npx eslint . --format json").toString(); + const results = JSON.parse(stdout); + generateReports(results, 0); +} catch (error) { + let results; + try { + const stdout = error.stdout.toString(); + results = JSON.parse(stdout); + } catch (parseError) { + console.error( + "Failed to parse ESLint output. The output was not valid JSON.", + ); + console.error("Error details:", parseError.message); + console.error("Raw output:", error.stdout.toString()); + process.exit(1); + } + generateReports(results, 1); +}