8 from lintlib import parse_all, log
10 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
13 This lint has the following configuration variables:
15 * `%s: %s`: %s (defaults to `%s`)."""
18 def parse_lint_def(lint):
20 lint_dict['id'] = lint.name
21 lint_dict['group'] = lint.group
22 lint_dict['level'] = lint.level
23 lint_dict['docs'] = {}
28 if len(line.strip()) == 0 and not last_section.startswith("Example"):
31 match = re.match(lint_subheadline, line)
33 last_section = match.groups()[0]
35 text = match.groups()[1]
40 log.warn("Skipping comment line as it was not preceded by a heading")
41 log.debug("in lint `%s`, line `%s`", lint.name, line)
43 fragment = lint_dict['docs'].get(last_section, "")
45 line = fragment + text
47 line = (fragment + "\n" + text).strip()
49 lint_dict['docs'][last_section] = line
55 lintlist, configs = parse_all()
58 lints[lint.name] = parse_lint_def(lint)
59 if lint.name in configs:
60 lints[lint.name]['docs']['Configuration'] = \
61 CONF_TEMPLATE % configs[lint.name]
63 outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
64 with open(outfile, "w") as fp:
65 json.dump(list(lints.values()), fp, indent=2)
66 log.info("wrote JSON for great justice")
69 if __name__ == "__main__":