From d52af53e04379adbdef6cdaef5d43e64c45d6a2a Mon Sep 17 00:00:00 2001 From: mcarton Date: Tue, 25 Oct 2016 19:41:24 +0200 Subject: [PATCH] Search for `clippy.toml` recursively --- clippy_lints/src/lib.rs | 16 ++++++---- clippy_lints/src/utils/conf.rs | 54 +++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 4c97c5d465f..2b2ecac9cdb 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -136,17 +136,23 @@ mod reexport { #[cfg_attr(rustfmt, rustfmt_skip)] pub fn register_plugins(reg: &mut rustc_plugin::Registry) { - let conf = match utils::conf::file(reg.args()) { + let conf = match utils::conf::file_from_args(reg.args()) { Ok(file_name) => { // if the user specified a file, it must exist, otherwise default to `clippy.toml` but // do not require the file to exist - let (file_name, must_exist) = if let Some(ref file_name) = file_name { - (&**file_name, true) + let file_name = if let Some(file_name) = file_name { + Some(file_name) } else { - ("clippy.toml", false) + match utils::conf::lookup_conf_file() { + Ok(path) => path, + Err(error) => { + reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit(); + None + } + } }; - let (conf, errors) = utils::conf::read(file_name, must_exist); + let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref())); // all conf errors are non-fatal, we just use the default conf in case of error for error in errors { diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 59913fd7115..0dccaec8ed8 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -2,14 +2,13 @@ #![deny(missing_docs_in_private_items)] -use std::{fmt, fs, io}; +use std::{env, fmt, fs, io, path}; use std::io::Read; use syntax::{ast, codemap}; -use syntax::parse::token; use toml; /// Get the configuration file from arguments. -pub fn file(args: &[codemap::Spanned]) -> Result, (&'static str, codemap::Span)> { +pub fn file_from_args(args: &[codemap::Spanned]) -> Result, (&'static str, codemap::Span)> { for arg in args.iter().filter_map(|a| a.meta_item()) { match arg.node { ast::MetaItemKind::Word(ref name) | @@ -21,7 +20,7 @@ pub fn file(args: &[codemap::Spanned]) -> Result