This commit is contained in:
Michael Wright 2018-08-15 08:11:07 +02:00
parent bac76afb5a
commit bbd67c9b78
6 changed files with 41 additions and 50 deletions

View file

@ -173,18 +173,14 @@ pub mod write;
pub mod zero_div_zero; pub mod zero_div_zero;
// end lints modules, do not remove this comment, its used in `update_lints` // end lints modules, do not remove this comment, its used in `update_lints`
use crate::utils::conf::Conf;
mod reexport { mod reexport {
crate use syntax::ast::{Name, NodeId}; crate use syntax::ast::{Name, NodeId};
} }
pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &mut rustc::lint::LintStore) { pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
store.register_pre_expansion_pass(Some(session), box write::Pass); match utils::conf::file_from_args(reg.args()) {
store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
}
#[rustfmt::skip]
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
let conf = match utils::conf::file_from_args(reg.args()) {
Ok(file_name) => { Ok(file_name) => {
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but // if the user specified a file, it must exist, otherwise default to `clippy.toml` but
// do not require the file to exist // do not require the file to exist
@ -226,8 +222,19 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
.emit(); .emit();
toml::from_str("").expect("we never error on empty config files") toml::from_str("").expect("we never error on empty config files")
} }
}; }
}
pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &mut rustc::lint::LintStore, conf: &Conf) {
store.register_pre_expansion_pass(Some(session), box write::Pass);
store.register_pre_expansion_pass(Some(session), box redundant_field_names::RedundantFieldNames);
store.register_pre_expansion_pass(Some(session), box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
});
}
#[rustfmt::skip]
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
let mut store = reg.sess.lint_store.borrow_mut(); let mut store = reg.sess.lint_store.borrow_mut();
store.register_removed( store.register_removed(
"should_assert_eq", "should_assert_eq",
@ -329,9 +336,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
reg.register_late_lint_pass(box derive::Derive); reg.register_late_lint_pass(box derive::Derive);
reg.register_late_lint_pass(box types::CharLitAsU8); reg.register_late_lint_pass(box types::CharLitAsU8);
reg.register_late_lint_pass(box vec::Pass); reg.register_late_lint_pass(box vec::Pass);
reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
});
reg.register_late_lint_pass(box drop_forget_ref::Pass); reg.register_late_lint_pass(box drop_forget_ref::Pass);
reg.register_late_lint_pass(box empty_enum::EmptyEnum); reg.register_late_lint_pass(box empty_enum::EmptyEnum);
reg.register_late_lint_pass(box types::AbsurdExtremeComparisons); reg.register_late_lint_pass(box types::AbsurdExtremeComparisons);
@ -347,9 +351,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional); reg.register_late_lint_pass(box overflow_check_conditional::OverflowCheckConditional);
reg.register_late_lint_pass(box unused_label::UnusedLabel); reg.register_late_lint_pass(box unused_label::UnusedLabel);
reg.register_late_lint_pass(box new_without_default::NewWithoutDefault); reg.register_late_lint_pass(box new_without_default::NewWithoutDefault);
reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names)); reg.register_late_lint_pass(box blacklisted_name::BlackListedName::new(conf.blacklisted_names.clone()));
reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold)); reg.register_late_lint_pass(box functions::Functions::new(conf.too_many_arguments_threshold));
reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents)); reg.register_early_lint_pass(box doc::Doc::new(conf.doc_valid_idents.clone()));
reg.register_late_lint_pass(box neg_multiply::NegMultiply); reg.register_late_lint_pass(box neg_multiply::NegMultiply);
reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval); reg.register_early_lint_pass(box unsafe_removed_from_name::UnsafeNameRemoval);
reg.register_late_lint_pass(box mem_forget::MemForget); reg.register_late_lint_pass(box mem_forget::MemForget);

View file

@ -5,7 +5,7 @@ use syntax::symbol::LocalInternedString;
use syntax::ast::*; use syntax::ast::*;
use syntax::attr; use syntax::attr;
use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor}; use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor};
use crate::utils::{in_macro, span_lint, span_lint_and_then}; use crate::utils::{span_lint, span_lint_and_then};
/// **What it does:** Checks for names that are very similar and thus confusing. /// **What it does:** Checks for names that are very similar and thus confusing.
/// ///
@ -147,9 +147,6 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
} }
} }
fn check_name(&mut self, span: Span, name: Name) { fn check_name(&mut self, span: Span, name: Name) {
if in_macro(span) {
return;
}
let interned_name = name.as_str(); let interned_name = name.as_str();
if interned_name.chars().any(char::is_uppercase) { if interned_name.chars().any(char::is_uppercase) {
return; return;
@ -309,6 +306,9 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
fn visit_item(&mut self, _: &Item) { fn visit_item(&mut self, _: &Item) {
// do not recurse into inner items // do not recurse into inner items
} }
fn visit_mac(&mut self, _mac: &Mac) {
// do not check macs
}
} }
impl EarlyLintPass for NonExpressiveNames { impl EarlyLintPass for NonExpressiveNames {
@ -323,7 +323,6 @@ impl EarlyLintPass for NonExpressiveNames {
do_check(self, cx, &item.attrs, &sig.decl, blk); do_check(self, cx, &item.attrs, &sig.decl, blk);
} }
} }
} }
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) { fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {

View file

@ -96,7 +96,9 @@ pub fn main() {
.span, .span,
); );
registry.args_hidden = Some(Vec::new()); registry.args_hidden = Some(Vec::new());
clippy_lints::register_plugins(&mut registry);
let conf = clippy_lints::read_conf(&registry);
clippy_lints::register_plugins(&mut registry, &conf);
let rustc_plugin::registry::Registry { let rustc_plugin::registry::Registry {
early_lint_passes, early_lint_passes,
@ -118,7 +120,7 @@ pub fn main() {
for (name, to) in lint_groups { for (name, to) in lint_groups {
ls.register_group(Some(sess), true, name, to); ls.register_group(Some(sess), true, name, to);
} }
clippy_lints::register_pre_expansion_lints(sess, &mut ls); clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes); sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
sess.plugin_attributes.borrow_mut().extend(attributes); sess.plugin_attributes.borrow_mut().extend(attributes);

View file

@ -25,7 +25,8 @@ pub fn plugin_registrar(reg: &mut Registry<'_>) {
} }
}); });
clippy_lints::register_plugins(reg); let conf = clippy_lints::read_conf(reg);
clippy_lints::register_plugins(reg, &conf);
} }
// only exists to let the dogfood integration test works. // only exists to let the dogfood integration test works.

View file

@ -1,7 +1,7 @@
#![warn(clippy,similar_names)] #![warn(clippy,similar_names)]
#![allow(unused)] #![allow(unused, println_empty_string)]
struct Foo { struct Foo {
@ -142,6 +142,11 @@ fn underscores_and_numbers() {
let _1_ok= 1; let _1_ok= 1;
} }
fn issue2927() {
let args = 1;
format!("{:?}", 2);
}
struct Bar; struct Bar;
impl Bar { impl Bar {

View file

@ -1,23 +1,3 @@
error: using `println!("")`
--> $DIR/non_expressive_names.rs:60:14
|
60 | _ => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
|
= note: `-D println-empty-string` implied by `-D warnings`
error: using `println!("")`
--> $DIR/non_expressive_names.rs:128:18
|
128 | 1 => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
error: using `println!("")`
--> $DIR/non_expressive_names.rs:132:18
|
132 | 1 => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`
error: binding's name is too similar to existing binding error: binding's name is too similar to existing binding
--> $DIR/non_expressive_names.rs:18:9 --> $DIR/non_expressive_names.rs:18:9
| |
@ -170,22 +150,22 @@ error: consider choosing a more descriptive name
| ^^^^^^^ | ^^^^^^^
error: consider choosing a more descriptive name error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:149:13 --> $DIR/non_expressive_names.rs:154:13
| |
149 | let _1 = 1; 154 | let _1 = 1;
| ^^ | ^^
error: consider choosing a more descriptive name error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:150:13 --> $DIR/non_expressive_names.rs:155:13
| |
150 | let ____1 = 1; 155 | let ____1 = 1;
| ^^^^^ | ^^^^^
error: consider choosing a more descriptive name error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:151:13 --> $DIR/non_expressive_names.rs:156:13
| |
151 | let __1___2 = 12; 156 | let __1___2 = 12;
| ^^^^^^^ | ^^^^^^^
error: aborting due to 20 previous errors error: aborting due to 17 previous errors