1 # Common utils for the several housekeeping scripts.
8 log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s')
10 Lint = collections.namedtuple('Lint', 'name level doc sourcefile')
11 Config = collections.namedtuple('Config', 'name ty doc default')
13 lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''')
14 level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
15 conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
16 confvar_re = re.compile(
17 r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE)
20 def parse_lints(lints, filepath):
24 with open(filepath) as fp:
27 if line.startswith("/// "):
28 last_comment.append(line[4:])
29 elif line.startswith("///"):
30 last_comment.append(line[3:])
31 elif line.startswith("declare_lint!"):
35 elif line.startswith("declare_restriction_lint!"):
39 elif line.startswith("declare_deprecated_lint!"):
45 m = lintname_re.search(line)
47 name = m.group(1).lower()
55 m = level_re.search(line)
61 log.info("found %s with level %s in %s",
62 name, level, filepath)
63 lints.append(Lint(name, level, last_comment, filepath))
67 log.warn("Warning: missing Lint-Name in %s", filepath)
71 def parse_configs(path):
73 with open(os.path.join(path, 'utils/conf.rs')) as fp:
76 match = re.search(conf_re, contents)
77 confvars = re.findall(confvar_re, match.group(1))
79 for (lint, doc, name, default, ty) in confvars:
80 configs[lint.lower()] = Config(name.replace("_", "-"), ty, doc, default)
85 def parse_all(path="clippy_lints/src"):
87 for filename in os.listdir(path):
88 if filename.endswith(".rs"):
89 parse_lints(lints, os.path.join(path, filename))
90 log.info("got %s lints", len(lints))
92 configs = parse_configs(path)
93 log.info("got %d configs", len(configs))