2 # Generate the wiki Home.md page from the contained doc comments
3 # requires the checked out wiki in ../rust-clippy.wiki/
4 # with -c option, print a warning and set exit status 1 if the file would be
11 level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
14 def parse_path(p="src"):
16 for f in os.listdir(p):
18 parse_file(d, os.path.join(p, f))
32 if line.startswith("///"):
33 if line.startswith("/// "):
34 last_comment.append(line[4:])
36 last_comment.append(line[3:])
37 elif line.startswith("declare_lint!"):
43 m = re.search(r"pub\s+([A-Z_]+)", l)
46 name = m.group(1).lower()
49 m = re.search(level_re, line)
56 print("found %s with level %s in %s" % (name, level, f))
57 d[name] = (level, last_comment)
61 print("Warning: Missing Lint-Name in", f)
64 PREFIX = """Welcome to the rust-clippy wiki!
66 Here we aim to collect further explanations on the lints clippy provides. So \
73 Clippy works as a *plugin* to the compiler, which means using an unstable \
74 internal API. We have gotten quite good at keeping pace with the API \
75 evolution, but the consequence is that clippy absolutely needs to be compiled \
76 with the version of `rustc` it will run on, otherwise you will get strange \
77 errors of missing symbols.
82 template = """\n# `%s`
89 def write_wiki_page(d, f):
92 with open(f, "w") as w:
95 for level in ('Deny', 'Warn', 'Allow'):
96 w.write("\n**Those lints are %s by default**:\n\n" % level)
99 w.write("[`%s`](#%s)\n" % (k, k))
103 w.write(template % (k, d[k][0], "".join(d[k][1])))
106 def check_wiki_page(d, f):
110 m = re.match("# `([a-z_]+)`", line)
112 v = d.pop(m.group(1), "()")
114 errors.append("Missing wiki entry: " + m.group(1))
115 keys = list(d.keys())
118 errors.append("Spurious wiki entry: " + k)
120 print("\n".join(errors))
127 check_wiki_page(d, "../rust-clippy.wiki/Home.md")
129 write_wiki_page(d, "../rust-clippy.wiki/Home.md")
131 if __name__ == "__main__":