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

Method scan_file_path

client/tool/regexfilescan.py:31–64  ·  view source on GitHub ↗

对文件相对路径执行正则匹配分析

(rel_path, rules)

Source from the content-addressed store, hash-verified

29 """
30 @staticmethod
31 def scan_file_path(rel_path, rules):
32 """ 对文件相对路径执行正则匹配分析
33 """
34 rel_path = rel_path.replace(os.sep, '/')
35 issues = []
36 for name, params in rules.items():
37 msg_template = params['msg']
38 pattern = params['reg_pattern']
39 match = pattern.search(rel_path)
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 # 如果捕获的分组和msg不匹配(分组为空;或msg中的%s数和分组数不相等),则捕获匹配的整个字符串
50 cap_text_list = match.group()
51 # 再次尝试与msg匹配,如果还是不匹配,则使用默认提示信息进行匹配
52 try:
53 message = msg_template % cap_text_list
54 except:
55 message = u"发现不规范文件: %s" % cap_text_list
56 issue = {
57 'path': rel_path,
58 'rule': name,
59 'msg': message,
60 'line': 0,
61 'column': 0
62 }
63 issues.append(issue)
64 return issues
65
66 @staticmethod
67 def scan_file(source_dir, file_path, rules):

Callers 1

scan_fileMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected