Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn if we find multiple clippy configs #8326

Merged
merged 3 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,36 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
let mut current = env::var_os("CLIPPY_CONF_DIR")
.or_else(|| env::var_os("CARGO_MANIFEST_DIR"))
.map_or_else(|| PathBuf::from("."), PathBuf::from);

let mut found_config: Option<PathBuf> = None;

loop {
for config_file_name in &CONFIG_FILE_NAMES {
if let Ok(config_file) = current.join(config_file_name).canonicalize() {
match fs::metadata(&config_file) {
Err(e) if e.kind() == io::ErrorKind::NotFound => {},
Err(e) => return Err(e),
Ok(md) if md.is_dir() => {},
Ok(_) => return Ok(Some(config_file)),
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(),
);
} else {
found_config = Some(config_file);
}
},
}
}
}

if found_config.is_some() {
return Ok(found_config);
}

// If the current directory has no parent, we're done searching.
if !current.pop() {
return Ok(None);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui-cargo/multiple_config_files/no_warn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "no_warn"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions tests/ui-cargo/multiple_config_files/no_warn/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
avoid-breaking-exported-api = false
3 changes: 3 additions & 0 deletions tests/ui-cargo/multiple_config_files/no_warn/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
1 change: 1 addition & 0 deletions tests/ui-cargo/multiple_config_files/warn/.clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
avoid-breaking-exported-api = false
8 changes: 8 additions & 0 deletions tests/ui-cargo/multiple_config_files/warn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "warn"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions tests/ui-cargo/multiple_config_files/warn/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
avoid-breaking-exported-api = false
5 changes: 5 additions & 0 deletions tests/ui-cargo/multiple_config_files/warn/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ignore-windows

fn main() {
println!("Hello, world!");
}
2 changes: 2 additions & 0 deletions tests/ui-cargo/multiple_config_files/warn/src/main.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Using config file `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/.clippy.toml`
Warning: `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/clippy.toml` will be ignored.