Update update_wiki.py
to extract default lint level
This commit is contained in:
parent
83a82a1d86
commit
f2a7c8cca0
1 changed files with 34 additions and 7 deletions
|
@ -8,6 +8,9 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
|
||||||
|
|
||||||
|
|
||||||
def parse_path(p="src"):
|
def parse_path(p="src"):
|
||||||
d = {}
|
d = {}
|
||||||
for f in os.listdir(p):
|
for f in os.listdir(p):
|
||||||
|
@ -38,9 +41,20 @@ def parse_file(d, f):
|
||||||
if not comment:
|
if not comment:
|
||||||
l = line.strip()
|
l = line.strip()
|
||||||
m = re.search(r"pub\s+([A-Z_]+)", l)
|
m = re.search(r"pub\s+([A-Z_]+)", l)
|
||||||
|
|
||||||
if m:
|
if m:
|
||||||
print("found %s in %s" % (m.group(1).lower(), f))
|
name = m.group(1).lower()
|
||||||
d[m.group(1).lower()] = last_comment
|
|
||||||
|
while True:
|
||||||
|
m = re.search(level_re, line)
|
||||||
|
if m:
|
||||||
|
level = m.group(0)
|
||||||
|
break
|
||||||
|
|
||||||
|
line = next(rs)
|
||||||
|
|
||||||
|
print("found %s with level %s in %s" % (name, level, f))
|
||||||
|
d[name] = (level, last_comment)
|
||||||
last_comment = []
|
last_comment = []
|
||||||
comment = True
|
comment = True
|
||||||
if "}" in l:
|
if "}" in l:
|
||||||
|
@ -51,7 +65,6 @@ PREFIX = """Welcome to the rust-clippy wiki!
|
||||||
|
|
||||||
Here we aim to collect further explanations on the lints clippy provides. So \
|
Here we aim to collect further explanations on the lints clippy provides. So \
|
||||||
without further ado:
|
without further ado:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
WARNING = """
|
WARNING = """
|
||||||
|
@ -61,7 +74,16 @@ Clippy works as a *plugin* to the compiler, which means using an unstable \
|
||||||
internal API. We have gotten quite good at keeping pace with the API \
|
internal API. We have gotten quite good at keeping pace with the API \
|
||||||
evolution, but the consequence is that clippy absolutely needs to be compiled \
|
evolution, but the consequence is that clippy absolutely needs to be compiled \
|
||||||
with the version of `rustc` it will run on, otherwise you will get strange \
|
with the version of `rustc` it will run on, otherwise you will get strange \
|
||||||
errors of missing symbols."""
|
errors of missing symbols.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
template = """# `%s`
|
||||||
|
|
||||||
|
**Default level:** %s
|
||||||
|
|
||||||
|
%s"""
|
||||||
|
|
||||||
|
|
||||||
def write_wiki_page(d, f):
|
def write_wiki_page(d, f):
|
||||||
|
@ -69,11 +91,16 @@ def write_wiki_page(d, f):
|
||||||
keys.sort()
|
keys.sort()
|
||||||
with open(f, "w") as w:
|
with open(f, "w") as w:
|
||||||
w.write(PREFIX)
|
w.write(PREFIX)
|
||||||
for k in keys:
|
|
||||||
w.write("[`%s`](#%s)\n" % (k, k))
|
for level in ('Deny', 'Warn', 'Allow'):
|
||||||
|
w.write("\n**Those lints are %s by default**:\n\n" % level)
|
||||||
|
for k in keys:
|
||||||
|
if d[k][0] == level:
|
||||||
|
w.write("[`%s`](#%s)\n" % (k, k))
|
||||||
|
|
||||||
w.write(WARNING)
|
w.write(WARNING)
|
||||||
for k in keys:
|
for k in keys:
|
||||||
w.write("\n# `%s`\n\n%s" % (k, "".join(d[k])))
|
w.write(template % (k, d[k][0], "".join(d[k][1])))
|
||||||
|
|
||||||
|
|
||||||
def check_wiki_page(d, f):
|
def check_wiki_page(d, f):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue