9 from lintlib import parse_all, log
11 lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''')
14 This lint has the following configuration variables:
16 * `%s: %s`: %s (defaults to `%s`)."""
19 def parse_lint_def(lint):
21 lint_dict['id'] = lint.name
22 lint_dict['group'] = lint.group
23 lint_dict['level'] = lint.level
24 lint_dict['docs'] = {}
29 if len(line.strip()) == 0 and not last_section.startswith("Example"):
32 match = re.match(lint_subheadline, line)
34 last_section = match.groups()[0]
36 text = match.groups()[1]
41 log.warn("Skipping comment line as it was not preceded by a heading")
42 log.debug("in lint `%s`, line `%s`", lint.name, line)
44 fragment = lint_dict['docs'].get(last_section, "")
46 line = fragment + text
48 line = (fragment + "\n" + text).strip()
50 lint_dict['docs'][last_section] = line
56 lintlist, configs = parse_all()
59 lints[lint.name] = parse_lint_def(lint)
60 if lint.name in configs:
61 lints[lint.name]['docs']['Configuration'] = \
62 CONF_TEMPLATE % configs[lint.name]
64 outfile = sys.argv[1] if len(sys.argv) > 1 else "util/gh-pages/lints.json"
65 with open(outfile, "w") as fp:
66 json.dump(list(lints.values()), fp, indent=2)
67 log.info("wrote JSON for great justice")
70 if __name__ == "__main__":