mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +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)]
|
#[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 {
|
let file_name = match path {
|
||||||
Ok(Some(path)) => path,
|
Ok((Some(path), _)) => path,
|
||||||
Ok(None) => return Conf::default(),
|
Ok((None, _)) => return Conf::default(),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
sess.struct_err(format!("error finding Clippy's configuration file: {error}"))
|
sess.err(format!("error finding Clippy's configuration file: {error}"));
|
||||||
.emit();
|
|
||||||
return Conf::default();
|
return Conf::default();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -470,7 +470,7 @@ define_Conf! {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns any unexpected filesystem error encountered when searching for the config file
|
/// 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.
|
/// Possible filename to search for.
|
||||||
const CONFIG_FILE_NAMES: [&str; 2] = [".clippy.toml", "clippy.toml"];
|
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);
|
.map_or_else(|| PathBuf::from("."), PathBuf::from);
|
||||||
|
|
||||||
let mut found_config: Option<PathBuf> = None;
|
let mut found_config: Option<PathBuf> = None;
|
||||||
|
let mut warnings = vec![];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
for config_file_name in &CONFIG_FILE_NAMES {
|
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(md) if md.is_dir() => {},
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// warn if we happen to find two config files #8323
|
// warn if we happen to find two config files #8323
|
||||||
if let Some(ref found_config_) = found_config {
|
if let Some(ref found_config) = found_config {
|
||||||
eprintln!(
|
warnings.push(format!(
|
||||||
"Using config file `{}`\nWarning: `{}` will be ignored.",
|
"using config file `{}`, `{}` will be ignored",
|
||||||
found_config_.display(),
|
found_config.display(),
|
||||||
config_file.display(),
|
config_file.display()
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
found_config = Some(config_file);
|
found_config = Some(config_file);
|
||||||
}
|
}
|
||||||
|
@ -506,12 +507,12 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if found_config.is_some() {
|
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 the current directory has no parent, we're done searching.
|
||||||
if !current.pop() {
|
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)]
|
#[allow(rustc::bad_opt_access)]
|
||||||
fn config(&mut self, config: &mut interface::Config) {
|
fn config(&mut self, config: &mut interface::Config) {
|
||||||
let conf_path = clippy_lints::lookup_conf_file();
|
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)
|
path.to_str().map(String::from)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
Using config file `$SRC_DIR/.clippy.toml`
|
warning: using config file `$SRC_DIR/.clippy.toml`, `$SRC_DIR/clippy.toml` will be ignored
|
||||||
Warning: `$SRC_DIR/clippy.toml` will be ignored.
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue