Skip to content

Commit

Permalink
feat: npx使用增加代码行数统计
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxudong13804 committed Feb 20, 2024
1 parent 7223399 commit f7ea477
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require("fs");
const path = require("path");
const execSync = require('child_process').execSync;
const { ESLint } = require("eslint");
const LibRulesAndConfigs = require("../lib/index"); // lib定义的规则名称集
const supportFileExtNames = require("../lib/execConfigs/supportFileExtNames"); // 支持的文件类型名后缀集合
Expand Down Expand Up @@ -52,6 +53,7 @@ async function lintFiles(filePaths) {

let totalErrors = 0;
let totalWarnings = 0;
let totalLines = 0

for (const filePath of filePaths) {
const curFileIsIgnored = isFileIgnored(filePath);
Expand Down Expand Up @@ -92,15 +94,30 @@ async function lintFiles(filePaths) {
});
console.error(resultText);
}


// 统计进行lint的代码行数
let filePathsStr = fileGroups[fileType].join(' ');
// console.log(fileGroups[fileType])
let stdout = execSync(`cloc --json ${filePathsStr}`).toString();
// console.log(stdout)
totalLines += JSON.parse(stdout)['SUM']['code']

}
}

console.log('Total 排除目录列表:', BlackFilesList);
console.log('Total 排除文件名规:', FileIgnoredList);
console.log('Total 支持文件类型:', supportFileExtNames);
console.log('排除目录列表:\n', JSON.stringify(BlackFilesList));
console.log('排除文件名:', FileIgnoredList);
console.log('支持文件类型:', supportFileExtNames);
console.log('\n')

// WARN 这三行不可以省略,npx 统计结果用
console.log('Total errors:', totalErrors);
console.log('Total warnings:', totalWarnings);
console.log('Total totalLines:', totalLines);

console.log('\n')


}

Expand Down

0 comments on commit f7ea477

Please sign in to comment.