3 # Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
20 from lintlib import parse_all, log
22 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
25 This lint has the following configuration variables:
27 * `%s: %s`: %s (defaults to `%s`)."""
30 def parse_lint_def(lint):
32 lint_dict['id'] = lint.name
33 lint_dict['group'] = lint.group
34 lint_dict['level'] = lint.level
35 lint_dict['docs'] = {}
40 if len(line.strip()) == 0 and not last_section.startswith("Example"):
43 match = re.match(lint_subheadline, line)
45 last_section = match.groups()[0]
47 text = match.groups()[1]
52 log.warn("Skipping comment line as it was not preceded by a heading")
53 log.debug("in lint `%s`, line `%s`", lint.name, line)
55 fragment = lint_dict['docs'].get(last_section, "")
57 line = fragment + text
59 line = (fragment + "\n" + text).strip()
61 lint_dict['docs'][last_section] = line
67 lintlist, configs = parse_all()
70 lints[lint.name] = parse_lint_def(lint)
71 if lint.name in configs:
72 lints[lint.name]['docs']['Configuration'] = \
73 CONF_TEMPLATE % configs[lint.name]
75 outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
76 with open(outfile, "w") as fp:
77 json.dump(list(lints.values()), fp, indent=2)
78 log.info("wrote JSON for great justice")
81 if __name__ == "__main__":