mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Show multiple clippy.toml warnings with sess.warn
instead of eprintln!
This commit is contained in:
parent
e903af506f
commit
afdfbf8fde
4 changed files with 24 additions and 17 deletions
|
@ -348,13 +348,17 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn read_conf(sess: &Session, path: &io::Result<Option<PathBuf>>) -> Conf {
|
||||
pub fn read_conf(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>) -> Conf {
|
||||
if let Ok((_, warnings)) = path {
|
||||
for warning in warnings {
|
||||
sess.warn(warning);
|
||||
}
|
||||
}
|
||||
let file_name = match path {
|
||||
Ok(Some(path)) => path,
|
||||
Ok(None) => return Conf::default(),
|
||||
Ok((Some(path), _)) => path,
|
||||
Ok((None, _)) => return Conf::default(),
|
||||
Err(error) => {
|
||||
sess.struct_err(format!("error finding Clippy's configuration file: {error}"))
|
||||
.emit();
|
||||
sess.err(format!("error finding Clippy's configuration file: {error}"));
|
||||
return Conf::default();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -470,7 +470,7 @@ define_Conf! {
|
|||
/// # Errors
|
||||
///
|
||||
/// Returns any unexpected filesystem error encountered when searching for the config file
|
||||
pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
|
||||
pub fn lookup_conf_file() -> io::Result<(Option<PathBuf>, Vec<String>)> {
|
||||
/// Possible filename to search for.
|
||||
const CONFIG_FILE_NAMES: [&str; 2] = [".clippy.toml", "clippy.toml"];
|
||||
|
||||
|
@ -481,6 +481,7 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
|
|||
.map_or_else(|| PathBuf::from("."), PathBuf::from);
|
||||
|
||||
let mut found_config: Option<PathBuf> = None;
|
||||
let mut warnings = vec![];
|
||||
|
||||
loop {
|
||||
for config_file_name in &CONFIG_FILE_NAMES {
|
||||
|
@ -491,12 +492,12 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
|
|||
Ok(md) if md.is_dir() => {},
|
||||
Ok(_) => {
|
||||
// warn if we happen to find two config files #8323
|
||||
if let Some(ref found_config_) = found_config {
|
||||
eprintln!(
|
||||
"Using config file `{}`\nWarning: `{}` will be ignored.",
|
||||
found_config_.display(),
|
||||
config_file.display(),
|
||||
);
|
||||
if let Some(ref found_config) = found_config {
|
||||
warnings.push(format!(
|
||||
"using config file `{}`, `{}` will be ignored",
|
||||
found_config.display(),
|
||||
config_file.display()
|
||||
));
|
||||
} else {
|
||||
found_config = Some(config_file);
|
||||
}
|
||||
|
@ -506,12 +507,12 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
|
|||
}
|
||||
|
||||
if found_config.is_some() {
|
||||
return Ok(found_config);
|
||||
return Ok((found_config, warnings));
|
||||
}
|
||||
|
||||
// If the current directory has no parent, we're done searching.
|
||||
if !current.pop() {
|
||||
return Ok(None);
|
||||
return Ok((None, warnings));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
|
|||
#[allow(rustc::bad_opt_access)]
|
||||
fn config(&mut self, config: &mut interface::Config) {
|
||||
let conf_path = clippy_lints::lookup_conf_file();
|
||||
let conf_path_string = if let Ok(Some(path)) = &conf_path {
|
||||
let conf_path_string = if let Ok((Some(path), _)) = &conf_path {
|
||||
path.to_str().map(String::from)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
Using config file `$SRC_DIR/.clippy.toml`
|
||||
Warning: `$SRC_DIR/clippy.toml` will be ignored.
|
||||
warning: using config file `$SRC_DIR/.clippy.toml`, `$SRC_DIR/clippy.toml` will be ignored
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
Loading…
Reference in a new issue