lib: add clippy_pedantic group with all Allow by default lints (fixes #265)

This commit is contained in:
Georg Brandl 2015-09-01 17:53:56 +02:00
parent 2abc5ab97c
commit 88dd38de87
5 changed files with 36 additions and 28 deletions

View file

@ -77,10 +77,19 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_lint_pass(box matches::MatchPass as LintPassObject);
reg.register_lint_pass(box misc::PatternPass as LintPassObject);
reg.register_lint_group("shadow", vec![
reg.register_lint_group("clippy_pedantic", vec![
methods::OPTION_UNWRAP_USED,
methods::RESULT_UNWRAP_USED,
ptr_arg::PTR_ARG,
shadow::SHADOW_REUSE,
shadow::SHADOW_SAME,
shadow::SHADOW_UNRELATED,
strings::STRING_ADD,
strings::STRING_ADD_ASSIGN,
types::CAST_POSSIBLE_TRUNCATION,
types::CAST_POSSIBLE_WRAP,
types::CAST_PRECISION_LOSS,
types::CAST_SIGN_LOSS,
unicode::NON_ASCII_LITERAL,
]);
reg.register_lint_group("clippy", vec![
@ -102,8 +111,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
loops::WHILE_LET_LOOP,
matches::MATCH_REF_PATS,
matches::SINGLE_MATCH,
methods::OPTION_UNWRAP_USED,
methods::RESULT_UNWRAP_USED,
methods::SHOULD_IMPLEMENT_TRAIT,
methods::STR_TO_STRING,
methods::STRING_TO_STRING,
@ -116,25 +123,15 @@ pub fn plugin_registrar(reg: &mut Registry) {
mut_mut::MUT_MUT,
needless_bool::NEEDLESS_BOOL,
precedence::PRECEDENCE,
ptr_arg::PTR_ARG,
ranges::RANGE_STEP_BY_ZERO,
returns::LET_AND_RETURN,
returns::NEEDLESS_RETURN,
shadow::SHADOW_REUSE,
shadow::SHADOW_SAME,
shadow::SHADOW_UNRELATED,
strings::STRING_ADD,
strings::STRING_ADD_ASSIGN,
types::BOX_VEC,
types::CAST_POSSIBLE_TRUNCATION,
types::CAST_POSSIBLE_WRAP,
types::CAST_PRECISION_LOSS,
types::CAST_SIGN_LOSS,
types::LET_UNIT_VALUE,
types::LINKEDLIST,
types::TYPE_COMPLEXITY,
types::UNIT_CMP,
unicode::NON_ASCII_LITERAL,
unicode::ZERO_WIDTH_SPACE,
]);
}

View file

@ -2,7 +2,7 @@
#![plugin(clippy)]
#![allow(unused)]
#![deny(clippy)]
#![deny(clippy, clippy_pedantic)]
use std::ops::Mul;

6
tests/compile-fail/shadow.rs Normal file → Executable file
View file

@ -2,7 +2,7 @@
#![plugin(clippy)]
#![allow(unused_parens, unused_variables)]
#![deny(shadow)]
#![deny(clippy, clippy_pedantic)]
fn id<T>(x: T) -> T { x }
@ -19,9 +19,9 @@ fn main() {
let x = first(x); //~ERROR: x is shadowed by first(x) which reuses
let y = 1;
let x = y; //~ERROR: x is shadowed by y in this declaration
let o = Some(1u8);
if let Some(p) = o { assert_eq!(1, p); }
match o {
Some(p) => p, // no error, because the p above is in its own scope

View file

@ -1,5 +1,5 @@
#!/bin/sh
rm -rf target*/*so
cargo build --lib && cp -R target target_recur && cargo rustc -- -Zextra-plugins=clippy -Ltarget_recur/debug -Dclippy || exit 1
cargo build --lib && cp -R target target_recur && cargo rustc -- -Zextra-plugins=clippy -Ltarget_recur/debug -Dclippy_pedantic -Dclippy || exit 1
rm -rf target_recur

View file

@ -38,7 +38,7 @@ def gen_table(lints, link=None):
"""Write lint table in Markdown format."""
if link:
lints = [(p, '[%s](%s#%s)' % (l, link, l), lvl, d)
for (p, l, lvl, d) in lints]
for (p, l, lvl, d) in lints]
# first and third column widths
w_name = max(len(l[1]) for l in lints)
w_desc = max(len(l[3]) for l in lints)
@ -50,8 +50,10 @@ def gen_table(lints, link=None):
yield '%-*s | %-7s | %s\n' % (w_name, name, default, meaning)
def gen_group(lints):
def gen_group(lints, levels=None):
"""Write lint group (list of all lints in the form module::NAME)."""
if levels:
lints = [tup for tup in lints if tup[2] in levels]
for (module, name, _, _) in sorted(lints):
yield ' %s::%s,\n' % (module, name.upper())
@ -113,19 +115,28 @@ def main(print_only=False, check=False):
return
# replace table in README.md
changed = replace_region('README.md', r'^name +\|', '^$',
lambda: gen_table(lints, link=wiki_link),
write_back=not check)
changed = replace_region(
'README.md', r'^name +\|', '^$',
lambda: gen_table(lints, link=wiki_link),
write_back=not check)
changed |= replace_region('README.md',
changed |= replace_region(
'README.md',
r'^There are \d+ lints included in this crate:', "",
lambda: ['There are %d lints included in this crate:\n' % len(lints)],
write_back=not check)
# same for "clippy" lint collection
changed |= replace_region('src/lib.rs', r'reg.register_lint_group\("clippy"', r'\]\);',
lambda: gen_group(lints), replace_start=False,
write_back=not check)
changed |= replace_region(
'src/lib.rs', r'reg.register_lint_group\("clippy"', r'\]\);',
lambda: gen_group(lints, levels=('warn', 'deny')),
replace_start=False, write_back=not check)
# same for "clippy_pedantic" lint collection
changed |= replace_region(
'src/lib.rs', r'reg.register_lint_group\("clippy_pedantic"', r'\]\);',
lambda: gen_group(lints, levels=('allow',)),
replace_start=False, write_back=not check)
if check and changed:
print('Please run util/update_lints.py to regenerate lints lists.')