]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/lib.rs
Auto merge of #7782 - dswij:shadow-unrelated-block, r=flip1995
[rust.git] / clippy_dev / src / lib.rs
1 #![feature(once_cell)]
2 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 // warn on lints, that are included in `rust-lang/rust`s bootstrap
4 #![warn(rust_2018_idioms, unused_lifetimes)]
5
6 use std::path::PathBuf;
7
8 pub mod bless;
9 pub mod fmt;
10 pub mod new_lint;
11 pub mod serve;
12 pub mod setup;
13 pub mod update_lints;
14
15 /// Returns the path to the Clippy project directory
16 ///
17 /// # Panics
18 ///
19 /// Panics if the current directory could not be retrieved, there was an error reading any of the
20 /// Cargo.toml files or ancestor directory is the clippy root directory
21 #[must_use]
22 pub fn clippy_project_root() -> PathBuf {
23     let current_dir = std::env::current_dir().unwrap();
24     for path in current_dir.ancestors() {
25         let result = std::fs::read_to_string(path.join("Cargo.toml"));
26         if let Err(err) = &result {
27             if err.kind() == std::io::ErrorKind::NotFound {
28                 continue;
29             }
30         }
31
32         let content = result.unwrap();
33         if content.contains("[package]\nname = \"clippy\"") {
34             return path.to_path_buf();
35         }
36     }
37     panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
38 }