crabatool 1.0.345 → 1.0.346
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils.js +20 -7
- package/package.json +2 -2
- package/tool/checkjs.js +39 -25
package/lib/utils.js
CHANGED
|
@@ -118,13 +118,13 @@ class Utils {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
removeUrlParams(url) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
if (!url) return url;
|
|
122
|
+
var index = url.indexOf("?");
|
|
123
|
+
if (index > 1) {
|
|
124
|
+
url = url.substring(0, index); // 去掉url后面的参数,包括问号
|
|
125
|
+
}
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
128
|
|
|
129
129
|
getHashCode(str) {
|
|
130
130
|
// 获取字符串的hash值
|
|
@@ -580,6 +580,19 @@ class Utils {
|
|
|
580
580
|
return content.replace(reg1, '').replace(reg2, '');
|
|
581
581
|
}
|
|
582
582
|
|
|
583
|
+
stripComments(code) {
|
|
584
|
+
// 移除多行注释 /* ... */
|
|
585
|
+
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
586
|
+
|
|
587
|
+
// 移除单行注释 // ...
|
|
588
|
+
code = code.replace(/\/\/.*?(\n|$)/g, '\n');
|
|
589
|
+
|
|
590
|
+
// 去除多余的空白行
|
|
591
|
+
code = code.replace(/^\s*[\r\n]/gm, '');
|
|
592
|
+
|
|
593
|
+
return code;
|
|
594
|
+
}
|
|
595
|
+
|
|
583
596
|
joinPath(p1, temp) {
|
|
584
597
|
if (!p1 || !temp) return temp;
|
|
585
598
|
var s = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crabatool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.346",
|
|
4
4
|
"description": "crabatool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"checkUpdate": "node run.js -checkUpdate -version master -webPath F:\\crabaevery\\www",
|
|
20
20
|
"upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:\\CarpaNET_NEW",
|
|
21
21
|
"crabaNgp": "node run.js -mergejs -hidejspath true -targetPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\js\\crabaNgp -inNames initMs.js,businessControl.js -outName F:\\CarpaMS\\src\\js\\crabaNgp.js",
|
|
22
|
-
"webPath": "node ./test/test.js -checkjs -webPath F:\\crabaevery\\www -modName crabaevery",
|
|
22
|
+
"webPath": "node ./test/test.js -checkjs -webPath F:\\crabaevery\\www -modName crabaevery -Debug true",
|
|
23
23
|
"biconfont": "node ./test/test.js -iconfont -zipPath F:\\crabaevery\\www\\biconfont -fontPath F:\\crabaevery\\www\\skins\\bicon -prefix .bicon- -fontName biconfont",
|
|
24
24
|
"aiconfont": "node ./test/test.js -iconfont -zipPath F:\\crabaevery\\www\\iconfont -fontPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\skins -prefix .aicon- -fontName iconfont",
|
|
25
25
|
"makeHash": "node run.js -makeHash -webPath ./test/ -modName craba -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json -hashName sha384",
|
package/tool/checkjs.js
CHANGED
|
@@ -115,7 +115,9 @@ module.exports.start = async function() {
|
|
|
115
115
|
var res = eslintResults[0];
|
|
116
116
|
res.messages.forEach((item) => {
|
|
117
117
|
var reg = new RegExp(/'\$\w+'\sis\snot\sdefined\./);
|
|
118
|
-
if (reg.test(item.message))
|
|
118
|
+
if (reg.test(item.message)) {
|
|
119
|
+
return; // $字符开头的全局变量不输出
|
|
120
|
+
}
|
|
119
121
|
|
|
120
122
|
var list = warnList;
|
|
121
123
|
if (!item.ruleId) {
|
|
@@ -145,31 +147,30 @@ module.exports.start = async function() {
|
|
|
145
147
|
|
|
146
148
|
// ------检查语法1--------
|
|
147
149
|
var reg = new RegExp(dangerousJs.join('|'));
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
var noComment = utils.clearComment(content);// 去掉注释的代码再查一遍;因为js里面有些危险字符是被注释了的
|
|
151
|
+
|
|
152
|
+
// 二次检查
|
|
153
|
+
if (reg.test(noComment)) {
|
|
154
|
+
reg.lastIndex = 0;
|
|
155
|
+
|
|
156
|
+
var nreg = new RegExp(dangerousJs.join('|'), 'ig');
|
|
157
|
+
var infoList = getMathReuslts(noComment, nreg, null, '兼容性字符,不推荐使用');
|
|
158
|
+
var list = errDatas[filePath];
|
|
159
|
+
if (list) errDatas[filePath] = list.concat(infoList); // 记录该js有异常
|
|
160
|
+
else errDatas[filePath] = infoList;
|
|
159
161
|
}
|
|
160
162
|
|
|
163
|
+
|
|
161
164
|
// trimEnd检查
|
|
162
|
-
var tstr = /\.trim\(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
else trimErrDatas[filePath] = infoList;
|
|
172
|
-
}
|
|
165
|
+
//var tstr = /\.trim\(['"]([^'"]){1}['"]\)|\.trimStart\(['"]([^'"]){1}['"]\)|\.trimEnd\(['"]([^'"]){1}['"]\)/gm;
|
|
166
|
+
var tstr = /(\.trim|\.trimStart|\.trimEnd)\(['"]([^'"]+)['"]\)/gm;
|
|
167
|
+
// 二次检查
|
|
168
|
+
if (tstr.test(noComment)) {
|
|
169
|
+
tstr.lastIndex = 0;
|
|
170
|
+
var infoList = getMathReuslts(noComment, tstr, null, 'trim(x)或trimEnd(x)或trimStart(x)使用不规范,不支持参数替换;请调整为trimChar(x)或trimEndChar(xx)或trimStartChar(xx)');
|
|
171
|
+
var list = trimErrDatas[filePath];
|
|
172
|
+
if (list) trimErrDatas[filePath] = list.concat(infoList); // 记录该js有异常
|
|
173
|
+
else trimErrDatas[filePath] = infoList;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
pb.clear('检验完成');
|
|
@@ -223,7 +224,7 @@ module.exports.start = async function() {
|
|
|
223
224
|
info.push("| 类型 | 数量 | 占比 |");
|
|
224
225
|
info.push("| ------ | ------ | ----- |");
|
|
225
226
|
info.push(`| 语法异常文件数Error | ${errKeys.length}个 |${calc(errKeys.length, jsFiles.length)}|`);
|
|
226
|
-
info.push(`| trimEnd或trimStart异常数 | ${trimErrKeys.length}个 |${calc(trimErrKeys.length, jsFiles.length)}|`);
|
|
227
|
+
info.push(`| trim、trimEnd或trimStart异常数 | ${trimErrKeys.length}个 |${calc(trimErrKeys.length, jsFiles.length)}|`);
|
|
227
228
|
info.push(`| 语法警告文件数Warn | ${warnKeys.length}个 |${calc(warnKeys.length, jsFiles.length)}|`);
|
|
228
229
|
info.push(`| 语法提示文件数Info | ${infoKeys.length}个 |${calc(infoKeys.length, jsFiles.length)}|`);
|
|
229
230
|
|
|
@@ -290,7 +291,7 @@ module.exports.start = async function() {
|
|
|
290
291
|
}*/
|
|
291
292
|
|
|
292
293
|
|
|
293
|
-
webhookList.push(`7. trimStart(x)和trimEnd(x)使用数:${trimErrKeys.length}个,占比${calc(trimErrKeys.length, jsFiles.length)}`);
|
|
294
|
+
webhookList.push(`7. trim(x)、trimStart(x)和trimEnd(x)使用数:${trimErrKeys.length}个,占比${calc(trimErrKeys.length, jsFiles.length)}`);
|
|
294
295
|
//}
|
|
295
296
|
//if (warnKeys.length > 0) {
|
|
296
297
|
webhookList.push(`7. js语法警告数Warn:${warnKeys.length}个,占比${calc(warnKeys.length, jsFiles.length)}`);
|
|
@@ -528,6 +529,18 @@ function calc(a, b) {
|
|
|
528
529
|
}
|
|
529
530
|
|
|
530
531
|
function getMathReuslts(content, nreg, filterFun, msg) {
|
|
532
|
+
var matches = [...content.matchAll(nreg)];
|
|
533
|
+
var list = [];
|
|
534
|
+
matches.forEach(match => {
|
|
535
|
+
var value = match[0];
|
|
536
|
+
if (!filterFun || filterFun(value)) {
|
|
537
|
+
list.push({ "char": value, "column": match.index, 'msg': msg });
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
return list;
|
|
542
|
+
|
|
543
|
+
/*
|
|
531
544
|
var all = content.matchAll(nreg);
|
|
532
545
|
var list = [];
|
|
533
546
|
var v = all.next()
|
|
@@ -539,6 +552,7 @@ function getMathReuslts(content, nreg, filterFun, msg) {
|
|
|
539
552
|
v = all.next();
|
|
540
553
|
}
|
|
541
554
|
return list;
|
|
555
|
+
*/
|
|
542
556
|
}
|
|
543
557
|
|
|
544
558
|
function getSonarEntity(type, modName, ruleId, message, filePath, line, column, endLine) {
|