X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=util%2Flintlib.py;h=1c49ab770d5e3e8175eecd2530c65d772f092a4d;hb=256b6419762e662c5d9e6e7e41241b6bb9110e9f;hp=45a7110b6a9779c9cd1f4da4782d5791701a0033;hpb=9a221402e6086678c921b77eef4b676cbdefb8ae;p=rust.git diff --git a/util/lintlib.py b/util/lintlib.py index 45a7110b6a9..1c49ab770d5 100644 --- a/util/lintlib.py +++ b/util/lintlib.py @@ -7,19 +7,33 @@ import collections import logging as log log.basicConfig(level=log.INFO, format='%(levelname)s: %(message)s') -Lint = collections.namedtuple('Lint', 'name level doc sourcefile') +Lint = collections.namedtuple('Lint', 'name level doc sourcefile group') Config = collections.namedtuple('Config', 'name ty doc default') lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''') -level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''') +group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''') conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE) confvar_re = re.compile( - r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''') + r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE) + +lint_levels = { + "correctness": 'Deny', + "style": 'Warn', + "complexity": 'Warn', + "perf": 'Warn', + "restriction": 'Allow', + "pedantic": 'Allow', + "nursery": 'Allow', + "cargo": 'Allow', +} def parse_lints(lints, filepath): last_comment = [] comment = True + clippy = False + deprecated = False + name = "" with open(filepath) as fp: for line in fp: @@ -29,43 +43,51 @@ def parse_lints(lints, filepath): elif line.startswith("///"): last_comment.append(line[3:]) elif line.startswith("declare_lint!"): + import sys + print("don't use `declare_lint!` in Clippy, use `declare_clippy_lint!` instead") + sys.exit(42) + elif line.startswith("declare_clippy_lint!"): comment = False deprecated = False - restriction = False - elif line.startswith("declare_restriction_lint!"): - comment = False - deprecated = False - restriction = True + clippy = True + name = "" elif line.startswith("declare_deprecated_lint!"): comment = False deprecated = True + clippy = False else: last_comment = [] if not comment: m = lintname_re.search(line) + if m: name = m.group(1).lower() + line = next(fp) if deprecated: level = "Deprecated" - elif restriction: - level = "Allow" + group = "deprecated" else: while True: - m = level_re.search(line) - if m: - level = m.group(0) + g = group_re.search(line) + if g: + group = g.group(1).lower() + level = lint_levels.get(group, None) break line = next(fp) + if level is None: + continue + log.info("found %s with level %s in %s", name, level, filepath) - lints.append(Lint(name, level, last_comment, filepath)) + lints.append(Lint(name, level, last_comment, filepath, group)) last_comment = [] comment = True - if "}" in line: - log.warn("Warning: missing Lint-Name in %s", filepath) - comment = True + + if "}" in line: + log.warn("Warning: missing Lint-Name in %s", filepath) + comment = True def parse_configs(path): @@ -77,16 +99,18 @@ def parse_configs(path): confvars = re.findall(confvar_re, match.group(1)) for (lint, doc, name, default, ty) in confvars: - configs[lint.lower()] = Config(name, ty, doc, default) + configs[lint.lower()] = Config(name.replace("_", "-"), ty, doc, default) return configs def parse_all(path="clippy_lints/src"): lints = [] - for filename in os.listdir(path): - if filename.endswith(".rs"): - parse_lints(lints, os.path.join(path, filename)) + for root, dirs, files in os.walk(path): + for fn in files: + if fn.endswith('.rs'): + parse_lints(lints, os.path.join(root, fn)) + log.info("got %s lints", len(lints)) configs = parse_configs(path)