#!/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
import os
import re
import sys
+from subprocess import call
declare_deprecated_lint_re = re.compile(r'''
declare_deprecated_lint! \s* [{(] \s*
# 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('\\"', '"')))
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:
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
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)