]> git.lizzy.rs Git - rust.git/blob - util/export.py
Auto merge of #4266 - uHOOCCOOHu:fix/async_fn_lifetime, r=flip1995
[rust.git] / util / export.py
1 #!/usr/bin/env python
2
3 # Build the gh-pages
4
5 from collections import OrderedDict
6 import re
7 import sys
8 import json
9
10 from lintlib import parse_all, log
11
12 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
13
14 CONF_TEMPLATE = """\
15 This lint has the following configuration variables:
16
17 * `%s: %s`: %s (defaults to `%s`)."""
18
19
20 def parse_lint_def(lint):
21     lint_dict = {}
22     lint_dict['id'] = lint.name
23     lint_dict['group'] = lint.group
24     lint_dict['level'] = lint.level
25     lint_dict['docs'] = OrderedDict()
26
27     last_section = None
28
29     for line in lint.doc:
30         match = re.match(lint_subheadline, line)
31         if match:
32             last_section = match.groups()[0]
33             text = match.groups()[1]
34         else:
35             text = line
36
37         if not last_section:
38             log.warning("Skipping comment line as it was not preceded by a heading")
39             log.debug("in lint `%s`, line `%s`", lint.name, line)
40
41         if last_section not in lint_dict['docs']:
42             lint_dict['docs'][last_section] = ""
43
44         lint_dict['docs'][last_section] += text + "\n"
45
46     for section in lint_dict['docs']:
47         lint_dict['docs'][section] = lint_dict['docs'][section].strip()
48
49     return lint_dict
50
51
52 def main():
53     lintlist, configs = parse_all()
54     lints = {}
55     for lint in lintlist:
56         lints[lint.name] = parse_lint_def(lint)
57         if lint.name in configs:
58             lints[lint.name]['docs']['Configuration'] = \
59                 CONF_TEMPLATE % configs[lint.name]
60
61     outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
62     with open(outfile, "w") as fp:
63         json.dump(list(lints.values()), fp, indent=2)
64         log.info("wrote JSON for great justice")
65
66
67 if __name__ == "__main__":
68     main()