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)''')
12 conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
13 confvar_re = re.compile(r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''')
16 def parse_path(p="src"):
18 for f in os.listdir(p):
20 parse_file(d, os.path.join(p, f))
21 return (d, parse_conf(p))
26 with open(p + '/utils/conf.rs') as f:
29 m = re.search(conf_re, f)
32 m = re.findall(confvar_re, m)
34 for (lint, doc, name, default, ty) in m:
35 c[lint.lower()] = (name, ty, doc, default)
47 if line.startswith("///"):
48 if line.startswith("/// "):
49 last_comment.append(line[4:])
51 last_comment.append(line[3:])
52 elif line.startswith("declare_lint!"):
58 m = re.search(r"pub\s+([A-Z_]+)", l)
61 name = m.group(1).lower()
64 m = re.search(level_re, line)
71 print("found %s with level %s in %s" % (name, level, f))
72 d[name] = (level, last_comment)
76 print("Warning: Missing Lint-Name in", f)
79 PREFIX = """Welcome to the rust-clippy wiki!
81 Here we aim to collect further explanations on the lints clippy provides. So \
88 Clippy works as a *plugin* to the compiler, which means using an unstable \
89 internal API. We have gotten quite good at keeping pace with the API \
90 evolution, but the consequence is that clippy absolutely needs to be compiled \
91 with the version of `rustc` it will run on, otherwise you will get strange \
92 errors of missing symbols.
97 template = """\n# `%s`
104 **Configuration:** This lint has the following configuration variables:
106 * `%s: %s`: %s (defaults to `%s`).
110 def write_wiki_page(d, c, f):
111 keys = list(d.keys())
113 with open(f, "w") as w:
116 for level in ('Deny', 'Warn', 'Allow'):
117 w.write("\n**Those lints are %s by default**:\n\n" % level)
120 w.write("[`%s`](#%s)\n" % (k, k))
124 w.write(template % (k, d[k][0], "".join(d[k][1])))
127 w.write(conf_template % c[k])
130 def check_wiki_page(d, c, f):
134 m = re.match("# `([a-z_]+)`", line)
136 v = d.pop(m.group(1), "()")
138 errors.append("Missing wiki entry: " + m.group(1))
139 keys = list(d.keys())
142 errors.append("Spurious wiki entry: " + k)
144 print("\n".join(errors))
149 (d, c) = parse_path()
151 check_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
153 write_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
155 if __name__ == "__main__":