格式化工具执行结果
(self, source_dir, scan_result_path, rules, supported_rules)
| 299 | # self.print_log(line) |
| 300 | |
| 301 | def _format_result(self, source_dir, scan_result_path, rules, supported_rules): |
| 302 | """格式化工具执行结果""" |
| 303 | issues = [] |
| 304 | relpos = len(source_dir) + 1 |
| 305 | with open(scan_result_path, "rb") as rf: |
| 306 | lines = rf.readlines() |
| 307 | for line in lines: |
| 308 | try: |
| 309 | line = line.decode("utf-8") |
| 310 | except: |
| 311 | line = line.decode("gbk") |
| 312 | error = line.split("[CODEDOG]") |
| 313 | if len(error) != 5: |
| 314 | LogPrinter.info("该error信息不全或格式有误: %s" % line) |
| 315 | continue |
| 316 | if "" in error: |
| 317 | LogPrinter.info("忽略error: %s" % line) |
| 318 | continue |
| 319 | rule = error[2] |
| 320 | if rule not in supported_rules: # 没有指定规则时,过滤不在当前版本cppcheck支持的规则中的结果 |
| 321 | LogPrinter.debug("rule not in supported_rules: %s" % rule) |
| 322 | continue |
| 323 | if rule in ["missingInclude", "MissingIncludeSystem"]: |
| 324 | LogPrinter.info("unsupported rule:%s" % rule) |
| 325 | continue |
| 326 | if rule not in rules: |
| 327 | continue |
| 328 | # 格式为{file}[CODEDOG]{line}[CODEDOG]{id}[CODEDOG]{severity}[CODEDOG]{message} |
| 329 | issue = {} |
| 330 | issue["path"] = error[0][relpos:] |
| 331 | issue["line"] = int(error[1]) |
| 332 | issue["column"] = "1" |
| 333 | issue["msg"] = error[4] |
| 334 | issue["rule"] = rule |
| 335 | issues.append(issue) |
| 336 | return issues |
| 337 | |
| 338 | def check_tool_usable(self, tool_params): |
| 339 | """ |
no test coverage detected