5 from collections import OrderedDict
10 from lintlib import parse_all, log
12 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
13 rust_code_block = re.compile(r'''```rust.+?```''', flags=re.DOTALL)
16 This lint has the following configuration variables:
18 * `%s: %s`: %s (defaults to `%s`)."""
21 def parse_code_block(match):
24 for line in match.group(0).split('\n'):
25 if not line.startswith('# '):
28 return '\n'.join(lines)
31 def parse_lint_def(lint):
33 lint_dict['id'] = lint.name
34 lint_dict['group'] = lint.group
35 lint_dict['level'] = lint.level
36 lint_dict['docs'] = OrderedDict()
41 match = re.match(lint_subheadline, line)
43 last_section = match.groups()[0]
44 text = match.groups()[1]
49 log.warning("Skipping comment line as it was not preceded by a heading")
50 log.debug("in lint `%s`, line `%s`", lint.name, line)
52 if last_section not in lint_dict['docs']:
53 lint_dict['docs'][last_section] = ""
55 lint_dict['docs'][last_section] += text + "\n"
57 for section in lint_dict['docs']:
58 lint_dict['docs'][section] = re.sub(rust_code_block, parse_code_block, lint_dict['docs'][section].strip())
64 lintlist, configs = parse_all()
67 lints[lint.name] = parse_lint_def(lint)
68 if lint.name in configs:
69 lints[lint.name]['docs']['Configuration'] = \
70 CONF_TEMPLATE % configs[lint.name]
72 outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
73 with open(outfile, "w") as fp:
74 lints = list(lints.values())
75 lints.sort(key=lambda x: x['id'])
76 json.dump(lints, fp, indent=2)
77 log.info("wrote JSON for great justice")
80 if __name__ == "__main__":