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="clippy_lints/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!"):
56 elif line.startswith("declare_restriction_lint!"):
60 elif line.startswith("declare_deprecated_lint!"):
67 m = re.search(r"pub\s+([A-Z_][A-Z_0-9]*)", l)
70 name = m.group(1).lower()
72 # Intentionally either a never looping or infinite loop
73 while not deprecated and not restriction:
74 m = re.search(level_re, line)
86 print("found %s with level %s in %s" % (name, level, f))
87 d[name] = (level, last_comment)
91 print("Warning: Missing Lint-Name in", f)
94 PREFIX = """Welcome to the rust-clippy wiki!
96 Here we aim to collect further explanations on the lints clippy provides. So \
103 Clippy works as a *plugin* to the compiler, which means using an unstable \
104 internal API. We have gotten quite good at keeping pace with the API \
105 evolution, but the consequence is that clippy absolutely needs to be compiled \
106 with the version of `rustc` it will run on, otherwise you will get strange \
107 errors of missing symbols.
112 template = """\n# `%s`
114 **Default level:** %s
119 **Configuration:** This lint has the following configuration variables:
121 * `%s: %s`: %s (defaults to `%s`).
125 def level_message(level):
126 if level == "Deprecated":
127 return "\n**Those lints are deprecated**:\n\n"
129 return "\n**Those lints are %s by default**:\n\n" % level
132 def write_wiki_page(d, c, f):
133 keys = list(d.keys())
135 with open(f, "w") as w:
138 for level in ('Deny', 'Warn', 'Allow', 'Deprecated'):
139 w.write(level_message(level))
142 w.write("[`%s`](#%s)\n" % (k, k))
146 w.write(template % (k, d[k][0], "".join(d[k][1])))
149 w.write(conf_template % c[k])
152 def check_wiki_page(d, c, f):
156 m = re.match("# `([a-z_]+)`", line)
158 v = d.pop(m.group(1), "()")
160 errors.append("Missing wiki entry: " + m.group(1))
161 keys = list(d.keys())
164 errors.append("Spurious wiki entry: " + k)
166 print("\n".join(errors))
171 (d, c) = parse_path()
172 print('Found %s lints' % len(d))
174 check_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
176 write_wiki_page(d, c, "../rust-clippy.wiki/Home.md")
178 if __name__ == "__main__":