2015-12-11 01:22:27 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Generate the wiki Home.md page from the contained doc comments
|
|
|
|
# requires the checked out wiki in ../rust-clippy.wiki/
|
2016-01-29 22:24:08 +01:00
|
|
|
# with -c option, print a warning and set exit status 1 if the file would be
|
|
|
|
# changed.
|
2016-08-06 10:40:35 +02:00
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
from lintlib import log, parse_all
|
2015-12-11 01:22:27 +01:00
|
|
|
|
|
|
|
PREFIX = """Welcome to the rust-clippy wiki!
|
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
Here we aim to collect further explanations on the lints clippy provides. So \
|
|
|
|
without further ado:
|
2015-12-11 01:22:27 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
WARNING = """
|
|
|
|
# A word of warning
|
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
Clippy works as a *plugin* to the compiler, which means using an unstable \
|
|
|
|
internal API. We have gotten quite good at keeping pace with the API \
|
|
|
|
evolution, but the consequence is that clippy absolutely needs to be compiled \
|
|
|
|
with the version of `rustc` it will run on, otherwise you will get strange \
|
2016-02-06 00:42:55 +01:00
|
|
|
errors of missing symbols.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
TEMPLATE = """\n# `%s`
|
2016-02-06 00:42:55 +01:00
|
|
|
|
|
|
|
**Default level:** %s
|
|
|
|
|
|
|
|
%s"""
|
2016-01-29 22:24:08 +01:00
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
CONF_TEMPLATE = """
|
2016-02-22 14:25:51 +01:00
|
|
|
**Configuration:** This lint has the following configuration variables:
|
2015-12-11 01:22:27 +01:00
|
|
|
|
2016-02-22 14:25:51 +01:00
|
|
|
* `%s: %s`: %s (defaults to `%s`).
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2016-03-24 19:25:59 +01:00
|
|
|
def level_message(level):
|
|
|
|
if level == "Deprecated":
|
|
|
|
return "\n**Those lints are deprecated**:\n\n"
|
|
|
|
else:
|
|
|
|
return "\n**Those lints are %s by default**:\n\n" % level
|
|
|
|
|
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
def write_wiki_page(lints, configs, filepath):
|
|
|
|
lints.sort()
|
|
|
|
with open(filepath, "w") as fp:
|
|
|
|
fp.write(PREFIX)
|
2016-02-06 00:42:55 +01:00
|
|
|
|
2016-03-24 19:25:59 +01:00
|
|
|
for level in ('Deny', 'Warn', 'Allow', 'Deprecated'):
|
2016-08-06 10:40:35 +02:00
|
|
|
fp.write(level_message(level))
|
|
|
|
for lint in lints:
|
|
|
|
if lint.level == level:
|
|
|
|
fp.write("[`%s`](#%s)\n" % (lint.name, lint.name))
|
2016-02-06 00:42:55 +01:00
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
fp.write(WARNING)
|
|
|
|
for lint in lints:
|
|
|
|
fp.write(TEMPLATE % (lint.name, lint.level, "".join(lint.doc)))
|
2015-12-11 01:22:27 +01:00
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
if lint.name in configs:
|
|
|
|
fp.write(CONF_TEMPLATE % configs[lint.name])
|
2016-02-22 14:25:51 +01:00
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
|
2016-08-06 10:40:35 +02:00
|
|
|
def check_wiki_page(lints, configs, filepath):
|
|
|
|
lintdict = dict((lint.name, lint) for lint in lints)
|
|
|
|
errors = False
|
|
|
|
with open(filepath) as fp:
|
|
|
|
for line in fp:
|
|
|
|
m = re.match("# `([a-z_0-9]+)`", line)
|
2015-12-11 01:22:27 +01:00
|
|
|
if m:
|
2016-08-06 10:40:35 +02:00
|
|
|
v = lintdict.pop(m.group(1), None)
|
|
|
|
if v is None:
|
|
|
|
log.error("Spurious wiki entry: %s", m.group(1))
|
|
|
|
errors = True
|
|
|
|
for n in sorted(lintdict):
|
|
|
|
log.error("Missing wiki entry: %s", n)
|
|
|
|
errors = True
|
2015-12-11 01:22:27 +01:00
|
|
|
if errors:
|
2016-08-06 10:40:35 +02:00
|
|
|
return 1
|
2015-12-11 01:22:27 +01:00
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
|
|
|
|
def main():
|
2016-08-06 10:40:35 +02:00
|
|
|
lints, configs = parse_all()
|
2015-12-11 01:22:27 +01:00
|
|
|
if "-c" in sys.argv:
|
2016-08-06 10:40:35 +02:00
|
|
|
check_wiki_page(lints, configs, "../rust-clippy.wiki/Home.md")
|
2015-12-11 01:22:27 +01:00
|
|
|
else:
|
2016-08-06 10:40:35 +02:00
|
|
|
write_wiki_page(lints, configs, "../rust-clippy.wiki/Home.md")
|
|
|
|
|
2016-01-29 22:24:08 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|