crabatool 1.0.97 → 1.0.101

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/.eslintrc.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "rules": {
15
15
  "semi": "off",
16
16
  "no-redeclare": "off",
17
- "no-unused-vars": "off",
17
+ //"no-unused-vars": "off",
18
18
  "missingSemi": "off"
19
19
  },
20
20
  "globals": {
@@ -60,6 +60,7 @@
60
60
  "getClientBounds": "readonly",
61
61
  "echarts": "readonly",
62
62
  "SysConsts": "readonly",
63
- "math": "readonly"
63
+ "math": "readonly",
64
+ "createIterator": "readonly"
64
65
  }
65
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.97",
3
+ "version": "1.0.101",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.js CHANGED
@@ -39,7 +39,7 @@ var config = {
39
39
  // 用于保存检查报告的api
40
40
  reportHost: 'http://crabadoc.ca.com',
41
41
 
42
- Debug: true,
42
+ Debug: false,
43
43
 
44
44
  // 告诉助手项目有哪些是全局变量,不然会提示未定义
45
45
  globals: ['crabadoc', 'Type', 'CrabaMarkdown', '$doc', 'www', 'crabaJs'],
package/tool/checkjs.js CHANGED
@@ -40,8 +40,9 @@ module.exports.start = async function() {
40
40
  utils.copyFile(path.join(__dirname, '../.eslintrc.json'), path.join(process.cwd(), '.eslintrc.json'));
41
41
  var jsFiles = utils.getFiles({ source: config.webPath, exts: '.js', ignores: config.ignoreCheck });
42
42
 
43
- var errList = [];
44
- var errRegList = [];
43
+ var errDatas = {};
44
+ var warnDatas = {};
45
+ var infoDatas = {};
45
46
  var bigList = [];
46
47
  var notUtf8List = [];
47
48
  var utf8List = [];
@@ -86,18 +87,35 @@ module.exports.start = async function() {
86
87
  bigList.push(`${filePath} ${parseInt(stats.size / 1024)}kb`);
87
88
  }
88
89
 
89
- var errInfo = { list: [] };
90
90
  if (eslintResults.length > 0 && eslintResults[0].errorCount > 0) {
91
+ var warnList = [];
92
+ var infoList = [];
93
+ var ieList = [];
91
94
  var res = eslintResults[0];
92
95
  res.messages.forEach((item) => {
93
96
  var reg = new RegExp(/'\$\w+'\sis\snot\sdefined\./);
94
97
  if (reg.test(item.message)) return; // $字符开头的全局变量不输出
95
- errInfo.list.push({ char: item.ruleId + ',' + item.messageId, line: item.line, endLine: item.endLine, column: item.column, msg: item.message });
98
+
99
+ var list = warnList;
100
+ if (!item.ruleId) {
101
+ list = ieList;
102
+ item.ruleId = '此文件有严重异常,解析失败';
103
+ } else if (item.ruleId.indexOf('native-ie') > -1 || item.ruleId.indexOf('no-dupe-keys') > -1) {
104
+ list = ieList;
105
+ } else if (item.ruleId.indexOf('no-unused-vars') > -1) {
106
+ list = infoList;
107
+ }
108
+ list.push({ char: item.ruleId + ',' + item.messageId, line: item.line, endLine: item.endLine, column: item.column, msg: item.message });
96
109
  });
97
110
 
98
- if (errInfo.list.length > 0) {
99
- errList.push(filePath);
100
- errRegList.push(errInfo);
111
+ if (warnList.length > 0) {
112
+ warnDatas[filePath] = warnList;
113
+ }
114
+ if (ieList.length > 0) {
115
+ errDatas[filePath] = ieList;
116
+ }
117
+ if (infoList.length > 0) {
118
+ infoDatas[filePath] = infoList;
101
119
  }
102
120
  }
103
121
 
@@ -108,14 +126,11 @@ module.exports.start = async function() {
108
126
 
109
127
  // 二次检查
110
128
  if (reg.test(noComment)) {
111
- if (errInfo.list.length == 0) {
112
- errList.push(filePath); // 记录该js有异常
113
- errRegList.push(errInfo);
114
- }
115
-
116
129
  var nreg = new RegExp(dangerousJs.join('|'), 'ig');
117
- var elist = getMathReuslts(noComment, nreg);
118
- errInfo.list = errInfo.list.concat(elist);
130
+ var infoList = getMathReuslts(noComment, nreg);
131
+ var list = errDatas[filePath];
132
+ if (list) errDatas[filePath] = list.concat(infoList); // 记录该js有异常
133
+ else errDatas[filePath] = infoList;
119
134
  }
120
135
  }
121
136
  }
@@ -127,7 +142,10 @@ module.exports.start = async function() {
127
142
  // 生成检测报告 markdown语法
128
143
  var warnGspxCount = Object.keys(gspxData.warnList).length;
129
144
  var status = '无异常';
130
- if (errList.length > 0 || notUtf8List.length > 0 || warnGspxCount > 0 || gspxData.errorList.length > 0) {
145
+ var errKeys = Object.keys(errDatas);
146
+ var warnKeys = Object.keys(warnDatas);
147
+ var infoKeys = Object.keys(infoDatas);
148
+ if (errKeys.length > 0 || warnKeys.length > 0 || notUtf8List.length > 0 || warnGspxCount > 0 || gspxData.errorList.length > 0) {
131
149
  status = '有异常';
132
150
  }
133
151
 
@@ -135,7 +153,7 @@ module.exports.start = async function() {
135
153
  var modName = getModName();
136
154
  var webhookList = [];
137
155
  var info = [];
138
- info.push(`# ${modName}代码检测报告——${status}`);
156
+ info.push(`# ${modName}代码检测报告`);
139
157
  webhookList.push(info[0]);
140
158
 
141
159
  info.push("| 名称 | 结果 |");
@@ -150,28 +168,38 @@ module.exports.start = async function() {
150
168
  info.push("# 检测结果汇总");
151
169
  info.push("| 类型 | 数量 |");
152
170
  info.push("| ------ | ------ |");
153
- info.push(`| 语法异常文件数 | ${errList.length}个 |`);
171
+ info.push(`| 语法异常文件数Error | ${errKeys.length}个 |`);
172
+ info.push(`| 语法警告文件数Warn | ${warnKeys.length}个 |`);
173
+ info.push(`| 语法提示文件数Info | ${warnKeys.length}个 |`);
154
174
  info.push(`| 非utf8文件数 | ${notUtf8List.length}个 |`);
155
175
  info.push(`| 超过${fileSize}kb的文件数 | ${bigList.length}个 |`);
156
176
  info.push(`| gspx建议优化数 | ${warnGspxCount}个 |`);
157
- info.push(`| gspx错误数 | ${gspxData.errorList.length}个 |`);
177
+ info.push(`| gspx语法错误数 | ${gspxData.errorList.length}个 |`);
158
178
 
159
179
 
180
+ webhookList.push(`1. 助手版本: ${config.Version} `);
181
+ webhookList.push(`1. 共检测 ${jsFiles.length}个js文件 `);
182
+ webhookList.push(`1. 共检测 ${gspxData.count}个gspx文件 `);
183
+
160
184
  // 输出到钉钉的简易报告
161
- if (errList.length > 0) {
162
- webhookList.push(`1. 语法异常文件数:${errList.length}个`);
163
- }
185
+ //if (errKeys.length > 0) {
186
+ webhookList.push(`1. 语法异常文件数Error:${errKeys.length}个`);
187
+ //}
188
+ //if (warnKeys.length > 0) {
189
+ webhookList.push(`1. 语法警告文件数Warn:${warnKeys.length}个`);
190
+ //}
191
+ webhookList.push(`1. 语法提示文件数Info:${infoKeys.length}个`);
164
192
  if (notUtf8List.length > 0) {
165
193
  webhookList.push(`1. 非utf8文件数:${notUtf8List.length}个`);
166
194
  }
167
195
  if (bigList.length > 0) {
168
196
  webhookList.push(`1. 超过${fileSize}kb的文件数:${bigList.length}个`);
169
197
  }
170
- if (warnGspxCount > 0) {
171
- webhookList.push(`1. gspx建议优化数:${warnGspxCount}个`);
172
- }
198
+ //if (warnGspxCount > 0) {
199
+ webhookList.push(`1. gspx建议优化数:${warnGspxCount}个`);
200
+ //}
173
201
  if (gspxData.errorList.length > 0) {
174
- webhookList.push(`1. gspx出错数:${gspxData.errorList.length}个`);
202
+ webhookList.push(`1. gspx语法错误数:${gspxData.errorList.length}个`);
175
203
  }
176
204
 
177
205
  // 代码质量管理需要格式
@@ -180,22 +208,57 @@ module.exports.start = async function() {
180
208
  };
181
209
 
182
210
  var detail = [];
183
- if (errList.length > 0) {
184
- detail.push("");
185
- detail.push('# js语法异常清单如下');
186
- errList.forEach((s, index) => {
211
+ //if (errKeys.length > 0) {
212
+ detail.push("");
213
+ detail.push(`# ${errKeys.length}个必须修复异常清单`);
214
+ errKeys.forEach((fileName, index) => {
215
+
216
+ detail.push(`${index + 1}. ${fileName}`);
217
+
218
+ var infoList = errDatas[fileName];
219
+ detail.push("| 异常字符 | 行号 | 列号 | 说明 |");
220
+ detail.push("| ----- | ------ | ---- | ---- |");
221
+ infoList.forEach((item) => {
222
+ detail.push(`| ${item.char.trim()} | ${item.line || '-'} | ${item.column || '-'} | ${item.msg || '-'} |`);
223
+ sonar.issues.push(getSonarEntity('语法异常', modName, item.char.trim(), fileName, -1, item.line, item.column, item.endLine));
224
+ });
225
+ });
226
+ //}
187
227
 
188
- detail.push(`${index + 1}. ${s}`);
228
+ //if (warnKeys.length > 0) {
229
+ detail.push("");
230
+ detail.push(`# ${warnKeys.length}个建议修复警告清单`);
231
+ warnKeys.forEach((fileName, index) => {
189
232
 
190
- var err = errRegList[index];
191
- detail.push("| 异常字符 | 行号 | 列号 | 说明 |");
192
- detail.push("| ----- | ------ | ---- | ---- |");
193
- err.list.forEach((item) => {
194
- detail.push(`| ${item.char.trim()} | ${item.line || '-'} | ${item.column || '-'} | ${item.msg || '-'} |`);
195
- sonar.issues.push(getSonarEntity('语法异常', modName, item.char.trim(), s, -1, item.line, item.column, item.endLine));
196
- });
233
+ detail.push(`${index + 1}. ${fileName}`);
234
+
235
+ var infoList = warnDatas[fileName];
236
+ detail.push("| 警告字符 | 行号 | 列号 | 说明 |");
237
+ detail.push("| ----- | ------ | ---- | ---- |");
238
+ infoList.forEach((item) => {
239
+ detail.push(`| ${item.char.trim()} | ${item.line || '-'} | ${item.column || '-'} | ${item.msg || '-'} |`);
240
+ sonar.issues.push(getSonarEntity('语法警告', modName, item.char.trim(), fileName, -1, item.line, item.column, item.endLine));
197
241
  });
198
- }
242
+ });
243
+ //}
244
+
245
+
246
+ //if (infoKeys.length > 0) {
247
+ detail.push("");
248
+ detail.push(`# ${infoKeys.length}个可选修复清单`);
249
+ infoKeys.forEach((fileName, index) => {
250
+
251
+ detail.push(`${index + 1}. ${fileName}`);
252
+
253
+ var infoList = infoDatas[fileName];
254
+ detail.push("| 提示字符 | 行号 | 列号 | 说明 |");
255
+ detail.push("| ----- | ------ | ---- | ---- |");
256
+ infoList.forEach((item) => {
257
+ detail.push(`| ${item.char.trim()} | ${item.line || '-'} | ${item.column || '-'} | ${item.msg || '-'} |`);
258
+ sonar.issues.push(getSonarEntity('语法提示', modName, item.char.trim(), fileName, -1, item.line, item.column, item.endLine));
259
+ });
260
+ });
261
+ //}
199
262
 
200
263
  if (notUtf8List.length > 0) {
201
264
  detail.push("");
@@ -218,7 +281,7 @@ module.exports.start = async function() {
218
281
  }
219
282
 
220
283
  if (gspxData.errorList.length > 0) {
221
- detail.push(`# 出错误页面清单如下`);
284
+ detail.push(`# 出错页面清单如下`);
222
285
  gspxData.errorList.forEach((info, index) => {
223
286
  detail.push(`${index + 1}. ${info.name}`);
224
287
  detail.push(`> 错误标签: ${info.tag}`);
@@ -298,7 +361,7 @@ function getMathReuslts(content, nreg, filterFun) {
298
361
  while (!v.done) {
299
362
  var value = v.value[0];
300
363
  if (!filterFun || filterFun(value)) {
301
- list.push({ "char": value, "column": v.value.index, 'msg': '兼容性问题,不推荐使用' });
364
+ list.push({ "char": value, "column": v.value.index, 'msg': '兼容性字符,不推荐使用' });
302
365
  }
303
366
  v = all.next();
304
367
  }