5 from collections import OrderedDict
10 from lintlib import parse_all, log
12 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
15 This lint has the following configuration variables:
17 * `%s: %s`: %s (defaults to `%s`)."""
20 def parse_lint_def(lint):
22 lint_dict['id'] = lint.name
23 lint_dict['group'] = lint.group
24 lint_dict['level'] = lint.level
25 lint_dict['docs'] = OrderedDict()
30 match = re.match(lint_subheadline, line)
32 last_section = match.groups()[0]
33 text = match.groups()[1]
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)
41 if last_section not in lint_dict['docs']:
42 lint_dict['docs'][last_section] = ""
44 lint_dict['docs'][last_section] += text + "\n"
46 for section in lint_dict['docs']:
47 lint_dict['docs'][section] = lint_dict['docs'][section].strip()
53 lintlist, configs = parse_all()
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]
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")
67 if __name__ == "__main__":