|
7 | 7 | import logging as log |
8 | 8 | log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s') |
9 | 9 |
|
10 | | -Lint = collections.namedtuple('Lint', 'name level doc sourcefile') |
| 10 | +Lint = collections.namedtuple('Lint', 'name level doc sourcefile group') |
11 | 11 | Config = collections.namedtuple('Config', 'name ty doc default') |
12 | 12 |
|
13 | 13 | 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]+)''') |
16 | 15 | conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE) |
17 | 16 | confvar_re = re.compile( |
18 | 17 | r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE) |
|
27 | 26 | "nursery": 'Allow', |
28 | 27 | } |
29 | 28 |
|
| 29 | + |
30 | 30 | def parse_lints(lints, filepath): |
31 | 31 | last_comment = [] |
32 | 32 | comment = True |
@@ -57,36 +57,30 @@ def parse_lints(lints, filepath): |
57 | 57 | else: |
58 | 58 | last_comment = [] |
59 | 59 | 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 | + |
90 | 84 | if "}" in line: |
91 | 85 | log.warn("Warning: missing Lint-Name in %s", filepath) |
92 | 86 | comment = True |
|
0 commit comments