Skip to content

Commit

Permalink
fix: cloc对于文件名含有空格的解析异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxudong13804 committed Feb 21, 2024
1 parent d644ec3 commit c0b39f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 12 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,21 @@ async function lintFiles(filePaths) {

// 统计进行lint的代码行数
try {
let filePathsStr = fileGroups[fileType].join(' ');
// console.log(fileGroups[fileType])
// 对于文件名包含空格的需要 添加 引号 否则无法 cloc read,没有的话不用
const dealNameHasBlank = fileGroups[fileType].map((item) => {
// 如果字符串中有空格(即 /\s/ 的正则表达式有匹配结果),那么返回被引号包围的字符串
if (/\s/.test(item)) {
return `"${item}"`;
}
// 否则返回原始字符串
return item;
});
let filePathsStr = dealNameHasBlank.join(' ');

// let stdout = execSync(`cloc --json ${filePathsStr}`).toString();
// console.log('wow\n', JSON.parse(stdout))

let stdout = execSync(`${clocPath} --json '${filePathsStr}'`).toString();
let stdout = execSync(`${clocPath} --json ${filePathsStr}`).toString();
totalBlankLines += JSON.parse(stdout)['SUM']?.blank || 0
totalCommentLines += JSON.parse(stdout)['SUM']?.comment || 0
totalCodeLines += JSON.parse(stdout)['SUM']?.code || 0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@afuteam/eslint-plugin-fe",
"version": "2.0.5-beta.9",
"version": "2.0.5-beta.10",
"description": "AfuTeam ESLint Plugin",
"main": "./lib/index.js",
"exports": {
Expand Down
12 changes: 12 additions & 0 deletions tests/filenamehasBLANK/a copy 2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var a = 9

console.log(a)

const ban = 11

ban = 'ban'


console.log(c)

// ceshi o

0 comments on commit c0b39f3

Please sign in to comment.