|
7 | 7 | level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
|
8 | 8 | conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
|
9 | 9 | confvar_re = re.compile(r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''')
|
10 |
| -lint_subheadline = re.compile(r'''^\*\*([\w\s]+)[:?.!]\*\*(.*)''') |
| 10 | +lint_subheadline = re.compile(r'''^\*\*([\w\s]+?)[:?.!]?\*\*(.*)''') |
| 11 | + |
| 12 | +conf_template = """ |
| 13 | +This lint has the following configuration variables: |
| 14 | +
|
| 15 | +* `%s: %s`: %s (defaults to `%s`). |
| 16 | +""" |
11 | 17 |
|
12 | 18 | # TODO: actual logging
|
13 | 19 | def warn(*args): print(args)
|
14 | 20 | def debug(*args): print(args)
|
15 | 21 | def info(*args): print(args)
|
16 | 22 |
|
17 | 23 | def parse_path(p="clippy_lints/src"):
|
18 |
| - d = [] |
| 24 | + lints = [] |
19 | 25 | for f in os.listdir(p):
|
20 | 26 | if f.endswith(".rs"):
|
21 |
| - parse_file(d, os.path.join(p, f)) |
22 |
| - return (d, parse_conf(p)) |
| 27 | + parse_file(lints, os.path.join(p, f)) |
| 28 | + |
| 29 | + conf = parse_conf(p) |
| 30 | + info(conf) |
| 31 | + |
| 32 | + for lint_id in conf: |
| 33 | + lint = next(l for l in lints if l['id'] == lint_id) |
| 34 | + if lint: |
| 35 | + lint['docs']['Configuration'] = (conf_template % conf[lint_id]).strip() |
| 36 | + |
| 37 | + return lints |
23 | 38 |
|
24 | 39 |
|
25 | 40 | def parse_conf(p):
|
@@ -120,7 +135,7 @@ def parse_file(d, f):
|
120 | 135 | comment = True
|
121 | 136 |
|
122 | 137 | def main():
|
123 |
| - (lints, config) = parse_path() |
| 138 | + lints = parse_path() |
124 | 139 | info("got %s lints" % len(lints))
|
125 | 140 | with open("util/gh-pages/lints.json", "w") as file:
|
126 | 141 | json.dump(lints, file, indent=2)
|
|
0 commit comments