2022-08-20 20:40:08 +02:00
|
|
|
#![feature(let_chains)]
|
2022-04-07 18:39:59 +01:00
|
|
|
#![feature(let_else)]
|
2020-10-09 12:45:29 +02:00
|
|
|
#![feature(once_cell)]
|
2022-04-07 18:39:59 +01:00
|
|
|
#![feature(rustc_private)]
|
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
|
|
|
|
2022-04-07 18:39:59 +01:00
|
|
|
extern crate rustc_lexer;
|
|
|
|
|
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;
|
2022-07-18 09:39:37 +02:00
|
|
|
pub mod dogfood;
|
2020-03-31 15:09:11 +02:00
|
|
|
pub mod fmt;
|
2021-12-06 12:33:31 +01:00
|
|
|
pub mod lint;
|
2020-03-31 15:09:11 +02:00
|
|
|
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;
|
|
|
|
|
2022-04-07 18:39:59 +01:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
|
|
|
|
#[cfg(windows)]
|
|
|
|
static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
|
|
|
|
|
|
|
|
/// Returns the path to the `cargo-clippy` binary
|
|
|
|
#[must_use]
|
|
|
|
pub fn cargo_clippy_path() -> PathBuf {
|
|
|
|
let mut path = std::env::current_exe().expect("failed to get current executable name");
|
|
|
|
path.set_file_name(CARGO_CLIPPY_EXE);
|
|
|
|
path
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|