From f7ea477da54b1a2b456618dad26bfe58fe4da960 Mon Sep 17 00:00:00 2001 From: wangxudong13804 Date: Tue, 20 Feb 2024 17:20:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20npx=E4=BD=BF=E7=94=A8=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A1=8C=E6=95=B0=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/index.js b/bin/index.js index 0b73dd4..fa8ebf8 100644 --- a/bin/index.js +++ b/bin/index.js @@ -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"); // 支持的文件类型名后缀集合 @@ -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); @@ -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') + }