]> git.lizzy.rs Git - rust.git/blobdiff - util/update_lints.py
Merge #3353
[rust.git] / util / update_lints.py
index abc8e5dee980dfc9b8e90b63c91cf3369f1aa80d..221069d353cb3093063b1b0eefc60b46435475e4 100755 (executable)
@@ -1,4 +1,16 @@
 #!/usr/bin/env python
+
+# 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 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+
 # Generate a Markdown table of all lints, and put it in README.md.
 # With -n option, only print the new table to stdout.
 # With -c option, print a warning and set exit status to 1 if a file would be
@@ -7,6 +19,7 @@
 import os
 import re
 import sys
+from subprocess import call
 
 declare_deprecated_lint_re = re.compile(r'''
     declare_deprecated_lint! \s* [{(] \s*
@@ -45,7 +58,12 @@ def collect(deprecated_lints, clippy_lints, fn):
         # remove \-newline escapes from description string
         desc = nl_escape_re.sub('', match.group('desc'))
         cat = match.group('cat')
-        clippy_lints[cat].append((os.path.splitext(os.path.basename(fn))[0],
+        if cat in ('internal', 'internal_warn'):
+            continue
+        module_name = os.path.splitext(os.path.basename(fn))[0]
+        if module_name == 'mod':
+            module_name = os.path.basename(os.path.dirname(fn))
+        clippy_lints[cat].append((module_name,
                                   match.group('name').lower(),
                                   "allow",
                                   desc.replace('\\"', '"')))
@@ -137,10 +155,11 @@ def main(print_only=False, check=False):
         return
 
     # collect all lints from source files
-    for fn in os.listdir('clippy_lints/src'):
-        if fn.endswith('.rs'):
-            collect(deprecated_lints, clippy_lints,
-                    os.path.join('clippy_lints', 'src', fn))
+    for root, dirs, files in os.walk('clippy_lints/src'):
+        for fn in files:
+            if fn.endswith('.rs'):
+                collect(deprecated_lints, clippy_lints,
+                        os.path.join(root, fn))
 
     # determine version
     with open('Cargo.toml') as fp:
@@ -166,19 +185,7 @@ def main(print_only=False, check=False):
         all_lints += value
 
     if print_only:
-        print_clippy_lint_groups = [
-            "correctness",
-            "style",
-            "complexity",
-            "perf",
-            "pedantic",
-            "nursery",
-            "restriction"
-        ]
-        for group in print_clippy_lint_groups:
-            sys.stdout.write('\n## ' + group + '\n')
-            for (_, name, _, descr) in sorted(clippy_lints[group]):
-                sys.stdout.write('* [' + name + '](https://rust-lang-nursery.github.io/rust-clippy/master/index.html#' + name + ') (' + descr + ')\n')
+        call(["./util/dev", "update_lints", "--print-only"])
         return
 
     # update the lint counter in README.md
@@ -218,22 +225,22 @@ def main(print_only=False, check=False):
         lambda: gen_mods(all_lints),
         replace_start=False, write_back=not check)
 
-    # same for "clippy_*" lint collections
+    # same for "clippy::*" lint collections
     changed |= replace_region(
-        'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy"', r'\]\);',
+        'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy::all"', r'\]\);',
         lambda: gen_group(clippy_lint_list),
         replace_start=False, write_back=not check)
 
     for key, value in clippy_lints.iteritems():
-        # same for "clippy_*" lint collections
+        # same for "clippy::*" lint collections
         changed |= replace_region(
-            'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy_' + key + r'"', r'\]\);',
+            'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy::' + key + r'"', r'\]\);',
             lambda: gen_group(value),
             replace_start=False, write_back=not check)
 
     # same for "deprecated" lint collection
     changed |= replace_region(
-        'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints',
+        'clippy_lints/src/lib.rs', r'begin deprecated lints', r'end deprecated lints',
         lambda: gen_deprecated(deprecated_lints),
         replace_start=False,
         write_back=not check)