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

Method scan_line

client/tool/regexscan.py:32–60  ·  view source on GitHub ↗

对单行代码执行正则匹配扫描

(line, rules)

Source from the content-addressed store, hash-verified

30 """
31 @staticmethod
32 def scan_line(line, rules):
33 """ 对单行代码执行正则匹配扫描
34 """
35 issues = []
36 for name, params in rules.items():
37 msg_template = params['msg']
38 pattern = params['reg_pattern']
39 match = pattern.search(line)
40 if match:
41 # msg_template里不包含%s,则不需要匹配,直接显示信息
42 if '%s' not in msg_template:
43 message = msg_template
44 else:
45 cap_text_list = match.groups()
46 try:
47 message = msg_template % cap_text_list
48 except:
49 cap_text_list = match.group()
50 try:
51 message = msg_template % cap_text_list
52 except:
53 message = u"Irregular codes found: %s" % cap_text_list
54 issue = {
55 'rule': name,
56 'msg': message,
57 'column': 1
58 }
59 issues.append(issue)
60 return issues
61
62 @staticmethod
63 def scan_file(source_dir, file_path, rules):

Callers 1

scan_file_textMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected