]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/util/export.py
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 # fix syntax highlighting for headers like ```rust,ignore
26 if line
.startswith('```rust'):
27 lines
.append('```rust')
28 elif not line
.startswith('# '):
31 return '\n'.join(lines
)
34 def parse_lint_def(lint
):
36 lint_dict
['id'] = lint
.name
37 lint_dict
['group'] = lint
.group
38 lint_dict
['level'] = lint
.level
39 lint_dict
['docs'] = OrderedDict()
44 match
= re
.match(lint_subheadline
, line
)
46 last_section
= match
.groups()[0]
47 text
= match
.groups()[1]
52 log
.warning("Skipping comment line as it was not preceded by a heading")
53 log
.debug("in lint `%s`, line `%s`", lint
.name
, line
)
55 if last_section
not in lint_dict
['docs']:
56 lint_dict
['docs'][last_section
] = ""
58 lint_dict
['docs'][last_section
] += text
+ "\n"
60 for section
in lint_dict
['docs']:
61 lint_dict
['docs'][section
] = re
.sub(rust_code_block
, parse_code_block
, lint_dict
['docs'][section
].strip())
67 lintlist
, configs
= parse_all()
70 lints
[lint
.name
] = parse_lint_def(lint
)
71 if lint
.name
in configs
:
72 lints
[lint
.name
]['docs']['Configuration'] = \
73 CONF_TEMPLATE
% configs
[lint
.name
]
75 outfile
= sys
.argv
[1] if len(sys
.argv
) > 1 else "util/gh-pages/lints.json"
76 with
open(outfile
, "w") as fp
:
77 lints
= list(lints
.values())
78 lints
.sort(key
=lambda x
: x
['id'])
79 json
.dump(lints
, fp
, indent
=2)
80 log
.info("wrote JSON for great justice")
83 if __name__
== "__main__":