MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / data_handle

Method data_handle

client/tool/eslint.py:432–494  ·  view source on GitHub ↗

处理结果文件 :param params: :param error_output: :param rule_filte_flag: :return:

(self, params, error_output, rule_filte_flag)

Source from the content-addressed store, hash-verified

430 raise ConfigError("JS堆溢出错误,麻烦设置过滤库文件或者设置增加JS堆")
431
432 def data_handle(self, params, error_output, rule_filte_flag):
433 """
434 处理结果文件
435 :param params:
436 :param error_output:
437 :param rule_filte_flag:
438 :return:
439 """
440 source_dir = params.source_dir
441 filter_mgr = FilterPathUtil(params)
442 pos = len(source_dir) + 1
443 rules = params.get("rules", [])
444
445 if not os.path.exists(error_output) or os.stat(error_output).st_size == 0:
446 LogPrinter.info("result is empty ")
447 return []
448
449 # 处理unicode字符,否则会导致解析失败, 并非所有有效的Unicode字符在XML中都有效
450 text = open(error_output, "r").read()
451 # 替换所有无效Unicode字符
452 text = re.sub(
453 r"&#([0-8]);|&#1([1-24-9]);|&#2([0-9]);|&#3([0-1]);|&#x0?([0-8bcBCefEF]);|&#x1([0-9a-fA-F])",
454 "",
455 text,
456 count=0,
457 flags=re.I,
458 )
459 raw_warning = ET.fromstring(text)
460 issues = []
461 for file in raw_warning.findall("file"):
462 # tag, attrib
463 path = file.attrib.get("name")[pos:]
464 if filter_mgr.should_filter_path(path):
465 continue
466 for error in file:
467 # 若解析文件失败,便可能会line为undefined,该结果无效
468 if error.attrib.get("line") == "undefined":
469 continue
470 line = int(error.attrib.get("line"))
471 column = error.attrib.get("column")
472 if column in ("NaN",):
473 column = 0
474 # need rule real name
475 tmp = error.attrib.get("source").split(".")
476 rule = tmp[-1]
477 msg = error.attrib.get("message")
478 # 记录解析错误带来的问题
479 if rule == "" and msg.startswith("Parsing error:"):
480 rule = "parse-error"
481 # parse-error规则,移除msg中的代码块
482 if msg.find(".\n\n") != -1:
483 msg = "".join(msg.split(".\n\n")[:-1])
484 # 兼容旧版typescript的规则
485 # if alloy_version == "2.0.5" and rule.startswith("@typescript-eslint/"):
486 if rule.startswith("@typescript-eslint/"):
487 rule = rule.replace("@typescript-eslint/", "typescript/")
488 # 若使用客户的配置文件,不进行规则过滤
489 if rule_filte_flag and rule not in rules:

Callers 4

analyzeMethod · 0.95
analyzeMethod · 0.95
analyzeMethod · 0.95
analyzeMethod · 0.45

Calls 3

getMethod · 0.45
infoMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected