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!"):
55 elif line.startswith("declare_deprecated_lint!"):
62 m = re.search(r"pub\s+([A-Z_]+)", l)
65 name = m.group(1).lower()
67 # Intentionally either a never looping or infinite loop
69 m = re.search(level_re, line)
79 print("found %s with level %s in %s" % (name, level, f))
80 d[name] = (level, last_comment)
84 print("Warning: Missing Lint-Name in", f)
87 PREFIX = """Welcome to the rust-clippy wiki!
89 Here we aim to collect further explanations on the lints clippy provides. So \
96 Clippy works as a *plugin* to the compiler, which means using an unstable \
97 internal API. We have gotten quite good at keeping pace with the API \
98 evolution, but the consequence is that clippy absolutely needs to be compiled \
99 with the version of `rustc` it will run on, otherwise you will get strange \
100 errors of missing symbols.
105 template = """\n# `%s`
107 **Default level:** %s
112 **Configuration:** This lint has the following configuration variables:
114 * `%s: %s`: %s (defaults to `%s`).
118 def level_message(level):
119 if level == "Deprecated":
120 return "\n**Those lints are deprecated**:\n\n"
122 return "\n**Those lints are %s by default**:\n\n" % level
125 def write_wiki_page(d, c, f):
126 keys = list(d.keys())
128 with open(f, "w") as w:
131 for level in ('Deny', 'Warn', 'Allow', 'Deprecated'):
132 w.write(level_message(level))
135 w.write("[`%s`](#%s)\n" % (k, k))
139 w.write(template % (k, d[k][0], "".join(d[k][1])))
142 w.write(conf_template % c[k])
145 def check_wiki_page(d, c, f):
149 m = re.match("# `([a-z_]+)`", line)
151 v = d.pop(m.group(1), "()")
153 errors.append("Missing wiki entry: " + m.group(1))
154 keys = list(d.keys())
157 errors.append("Spurious wiki entry: " + k)
159 print("\n".join(errors))
164 (d, c) = parse_path()
166 check_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
168 write_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
170 if __name__ == "__main__":