Skip to content

Commit 814395b

Browse files
authored
Merge pull request #1997 from angela-lee1/create-script-output-list-files-containing-linting-errors
add script to out put list of files containing linting errors
2 parents 35a61bc + c98c80c commit 814395b

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"test:backend": "cd backend && npm run test",
1717
"test:client": "cd client && npm run test",
1818
"test:all": "cross-env NODE_ENV=test npm run test:client && npm run test:backend",
19-
"prepare": "husky install"
19+
"prepare": "husky install",
20+
"lint:files": "node scripts/list-lint-files.mjs"
2021
},
2122
"dependencies": {
2223
"@mui/icons-material": "^5.14.19",

scripts/list-lint-files.mjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//import node modules for running shell commands and handling files, define file names
2+
import { execSync } from "child_process";
3+
import fs from "fs";
4+
const reportFile = "lint-report.json";
5+
const countFile = "lint-files.count.txt";
6+
7+
// Generate report
8+
const generateReports = (results, exitCode) => {
9+
const countContent = `After running the lint found total number of the files has linting problems: ${results.length}`;
10+
fs.writeFileSync(countFile, countContent, "utf-8");
11+
console.log(
12+
`Found ${results.length} files with linting errors. Total written to ${countFile}`,
13+
);
14+
15+
const modifiedResults = results.map((result) => {
16+
const vrmsIndex = result.filePath.indexOf("VRMS");
17+
const relativePath = result.filePath.substring(vrmsIndex + 4);
18+
return { ...result, filePath: relativePath };
19+
});
20+
21+
const formattedJson = JSON.stringify(modifiedResults, null, 2);
22+
fs.writeFileSync(reportFile, formattedJson, "utf-8");
23+
24+
console.log(`Lint report created: ${reportFile}`);
25+
process.exit(exitCode);
26+
};
27+
28+
try {
29+
const stdout = execSync("npx eslint . --format json").toString();
30+
const results = JSON.parse(stdout);
31+
generateReports(results, 0);
32+
} catch (error) {
33+
let results;
34+
try {
35+
const stdout = error.stdout.toString();
36+
results = JSON.parse(stdout);
37+
} catch (parseError) {
38+
console.error(
39+
"Failed to parse ESLint output. The output was not valid JSON.",
40+
);
41+
console.error("Error details:", parseError.message);
42+
console.error("Raw output:", error.stdout.toString());
43+
process.exit(1);
44+
}
45+
generateReports(results, 1);
46+
}

0 commit comments

Comments
 (0)