X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=util%2Flintlib.py;h=5707cf0ce0f8c08177f68866b7065c6c9feb2182;hb=cd0db8a4599619dd43af5f39834a7566d06e5b50;hp=098fcf256a6e5db4a3eb70b5a6a87cda19059c6d;hpb=a16edf84ce17095ebeebccb5662441ef1c824905;p=rust.git diff --git a/util/lintlib.py b/util/lintlib.py index 098fcf256a6..5707cf0ce0f 100644 --- a/util/lintlib.py +++ b/util/lintlib.py @@ -1,13 +1,3 @@ -# Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - # Common utils for the several housekeeping scripts. import os @@ -24,7 +14,8 @@ lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''') 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\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE) + r'''/// Lint: ([\w,\s]+)\. (.*)\n\s*\(([^:]+):\s*([^\s=]+)\s*=\s*([^\.\)]+).*\),''', re.MULTILINE) +comment_re = re.compile(r'''\s*/// ?(.*)''') lint_levels = { "correctness": 'Deny', @@ -39,37 +30,15 @@ lint_levels = { def parse_lints(lints, filepath): - last_comment = [] - comment = True + comment = [] clippy = False deprecated = False name = "" with open(filepath) as fp: for line in fp: - if comment: - if line.startswith("/// "): - last_comment.append(line[4:]) - 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 - clippy = True - name = "" - elif line.startswith("declare_deprecated_lint!"): - comment = False - deprecated = True - clippy = False - else: - last_comment = [] - if not comment: + if clippy or deprecated: m = lintname_re.search(line) - if m: name = m.group(1).lower() line = next(fp) @@ -91,13 +60,29 @@ def parse_lints(lints, filepath): log.info("found %s with level %s in %s", name, level, filepath) - lints.append(Lint(name, level, last_comment, filepath, group)) - last_comment = [] - comment = True + lints.append(Lint(name, level, comment, filepath, group)) + comment = [] - if "}" in line: - log.warn("Warning: missing Lint-Name in %s", filepath) - comment = True + clippy = False + deprecated = False + name = "" + else: + m = comment_re.search(line) + if m: + comment.append(m.group(1)) + elif line.startswith("declare_clippy_lint!"): + clippy = True + deprecated = False + elif line.startswith("declare_deprecated_lint!"): + clippy = False + deprecated = True + elif line.startswith("declare_lint!"): + import sys + print( + "don't use `declare_lint!` in Clippy, " + "use `declare_clippy_lint!` instead" + ) + sys.exit(42) def parse_configs(path): @@ -108,9 +93,9 @@ def parse_configs(path): match = re.search(conf_re, contents) confvars = re.findall(confvar_re, match.group(1)) - for (lint, doc, name, default, ty) in confvars: - configs[lint.lower()] = Config(name.replace("_", "-"), ty, doc, default) - + for (lints, doc, name, ty, default) in confvars: + for lint in lints.split(','): + configs[lint.strip().lower()] = Config(name.replace("_", "-"), ty, doc, default) return configs