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
10 from lintlib import log, parse_all
12 PREFIX = """Welcome to the rust-clippy wiki!
14 Here we aim to collect further explanations on the lints clippy provides. So \
21 Clippy works as a *plugin* to the compiler, which means using an unstable \
22 internal API. We have gotten quite good at keeping pace with the API \
23 evolution, but the consequence is that clippy absolutely needs to be compiled \
24 with the version of `rustc` it will run on, otherwise you will get strange \
25 errors of missing symbols.
29 TEMPLATE = """\n# `%s`
36 **Configuration:** This lint has the following configuration variables:
38 * `%s: %s`: %s (defaults to `%s`).
42 def level_message(level):
43 if level == "Deprecated":
44 return "\n**Those lints are deprecated**:\n\n"
46 return "\n**Those lints are %s by default**:\n\n" % level
49 def write_wiki_page(lints, configs, filepath):
51 with open(filepath, "w") as fp:
54 for level in ('Deny', 'Warn', 'Allow', 'Deprecated'):
55 fp.write(level_message(level))
57 if lint.level == level:
58 fp.write("[`%s`](#%s)\n" % (lint.name, lint.name))
62 fp.write(TEMPLATE % (lint.name, lint.level, "".join(lint.doc)))
64 if lint.name in configs:
65 fp.write(CONF_TEMPLATE % configs[lint.name])
68 def check_wiki_page(lints, configs, filepath):
69 lintdict = dict((lint.name, lint) for lint in lints)
71 with open(filepath) as fp:
73 m = re.match("# `([a-z_0-9]+)`", line)
75 v = lintdict.pop(m.group(1), None)
77 log.error("Spurious wiki entry: %s", m.group(1))
79 for n in sorted(lintdict):
80 log.error("Missing wiki entry: %s", n)
87 lints, configs = parse_all()
89 check_wiki_page(lints, configs, "../rust-clippy.wiki/Home.md")
91 write_wiki_page(lints, configs, "../rust-clippy.wiki/Home.md")
94 if __name__ == "__main__":