]> git.lizzy.rs Git - rust.git/blobdiff - util/lintlib.py
Make indexing_slicing a restriction lint (fixes #2933)
[rust.git] / util / lintlib.py
index 1fddcbdc3fad026b76ce2d50079ec6d1d2241f1a..00826805e1617b5e80db08168b668f8e1f5b087d 100644 (file)
@@ -7,12 +7,11 @@ 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'''([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)
@@ -25,8 +24,10 @@ lint_levels = {
     "restriction": 'Allow',
     "pedantic": 'Allow',
     "nursery": 'Allow',
+    "cargo": 'Allow',
 }
 
+
 def parse_lints(lints, filepath):
     last_comment = []
     comment = True
@@ -43,7 +44,7 @@ def parse_lints(lints, filepath):
                     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"
+                    print "don't use `declare_lint!` in Clippy, use `declare_clippy_lint!` instead"
                     sys.exit(42)
                 elif line.startswith("declare_clippy_lint!"):
                     comment = False
@@ -57,36 +58,30 @@ def parse_lints(lints, filepath):
                 else:
                     last_comment = []
             if not comment:
-                if name:
-                    g = group_re.search(line)
-                    if g:
-                        group = g.group(1).lower()
-                        level = lint_levels[group]
-                        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
-                else:
-                    m = lintname_re.search(line)
-                    if m:
-                        name = m.group(1).lower()
-
-                        if deprecated:
-                            level = "Deprecated"
-                        else:
-                            while True:
-                                m = level_re.search(line)
-                                if m:
-                                    level = m.group(0)
-                                    break
-                                line = next(fp)
-                        if not clippy:
-                            log.info("found %s with level %s in %s",
-                                    name, level, filepath)
-                            lints.append(Lint(name, level, last_comment, filepath, "deprecated"))
-                            last_comment = []
-                            comment = True
+                m = lintname_re.search(line)
+
+                if m:
+                    name = m.group(1).lower()
+                    line = next(fp)
+
+                    if deprecated:
+                        level = "Deprecated"
+                        group = "deprecated"
+                    else:
+                        while True:
+                            g = group_re.search(line)
+                            if g:
+                                group = g.group(1).lower()
+                                level = lint_levels[group]
+                                break
+                            line = next(fp)
+
+                    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
+
                     if "}" in line:
                         log.warn("Warning: missing Lint-Name in %s", filepath)
                         comment = True