2020-10-09 12:45:29 +02:00
|
|
|
#![feature(once_cell)]
|
2021-05-20 12:30:31 +02:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
|
|
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2019-11-25 17:23:48 +01:00
|
|
|
|
2021-10-07 11:21:30 +02:00
|
|
|
use std::path::PathBuf;
|
2018-07-17 22:50:17 +02:00
|
|
|
|
2020-12-20 17:19:49 +01:00
|
|
|
pub mod bless;
|
2020-03-31 15:09:11 +02:00
|
|
|
pub mod fmt;
|
|
|
|
pub mod new_lint;
|
2020-10-09 12:45:29 +02:00
|
|
|
pub mod serve;
|
2021-07-01 18:17:38 +02:00
|
|
|
pub mod setup;
|
2020-03-31 15:09:11 +02:00
|
|
|
pub mod update_lints;
|
|
|
|
|
2020-01-30 08:33:48 +01:00
|
|
|
/// Returns the path to the Clippy project directory
|
2021-02-02 20:43:30 -08:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the current directory could not be retrieved, there was an error reading any of the
|
|
|
|
/// Cargo.toml files or ancestor directory is the clippy root directory
|
2020-01-31 07:32:53 +01:00
|
|
|
#[must_use]
|
2020-01-30 21:29:21 +01:00
|
|
|
pub fn clippy_project_root() -> PathBuf {
|
|
|
|
let current_dir = std::env::current_dir().unwrap();
|
|
|
|
for path in current_dir.ancestors() {
|
|
|
|
let result = std::fs::read_to_string(path.join("Cargo.toml"));
|
|
|
|
if let Err(err) = &result {
|
|
|
|
if err.kind() == std::io::ErrorKind::NotFound {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let content = result.unwrap();
|
|
|
|
if content.contains("[package]\nname = \"clippy\"") {
|
|
|
|
return path.to_path_buf();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
|
2020-01-30 08:33:48 +01:00
|
|
|
}
|