Skip to content

Commit 4ef7238

Browse files
authored
Merge pull request #2601 from flip1995/export
Fix lintlib script
2 parents b7a0b97 + 2a52527 commit 4ef7238

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

util/lintlib.py

+27-33
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
import logging as log
88
log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s')
99

10-
Lint = collections.namedtuple('Lint', 'name level doc sourcefile')
10+
Lint = collections.namedtuple('Lint', 'name level doc sourcefile group')
1111
Config = collections.namedtuple('Config', 'name ty doc default')
1212

1313
lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''')
14-
level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
15-
group_re = re.compile(r'''([a-z_][a-z_0-9]+)''')
14+
group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''')
1615
conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
1716
confvar_re = re.compile(
1817
r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE)
@@ -27,6 +26,7 @@
2726
"nursery": 'Allow',
2827
}
2928

29+
3030
def parse_lints(lints, filepath):
3131
last_comment = []
3232
comment = True
@@ -57,36 +57,30 @@ def parse_lints(lints, filepath):
5757
else:
5858
last_comment = []
5959
if not comment:
60-
if name:
61-
g = group_re.search(line)
62-
if g:
63-
group = g.group(1).lower()
64-
level = lint_levels[group]
65-
log.info("found %s with level %s in %s",
66-
name, level, filepath)
67-
lints.append(Lint(name, level, last_comment, filepath, group))
68-
last_comment = []
69-
comment = True
70-
else:
71-
m = lintname_re.search(line)
72-
if m:
73-
name = m.group(1).lower()
74-
75-
if deprecated:
76-
level = "Deprecated"
77-
else:
78-
while True:
79-
m = level_re.search(line)
80-
if m:
81-
level = m.group(0)
82-
break
83-
line = next(fp)
84-
if not clippy:
85-
log.info("found %s with level %s in %s",
86-
name, level, filepath)
87-
lints.append(Lint(name, level, last_comment, filepath, "deprecated"))
88-
last_comment = []
89-
comment = True
60+
m = lintname_re.search(line)
61+
62+
if m:
63+
name = m.group(1).lower()
64+
line = next(fp)
65+
66+
if deprecated:
67+
level = "Deprecated"
68+
group = "deprecated"
69+
else:
70+
while True:
71+
g = group_re.search(line)
72+
if g:
73+
group = g.group(1).lower()
74+
level = lint_levels[group]
75+
break
76+
line = next(fp)
77+
78+
log.info("found %s with level %s in %s",
79+
name, level, filepath)
80+
lints.append(Lint(name, level, last_comment, filepath, group))
81+
last_comment = []
82+
comment = True
83+
9084
if "}" in line:
9185
log.warn("Warning: missing Lint-Name in %s", filepath)
9286
comment = True

0 commit comments

Comments
 (0)