]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_dev/src/lib.rs
59fde447547145f3093b5054112bd58dd6ec8b7e
[rust.git] / src / tools / clippy / 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 lint;
11 pub mod new_lint;
12 pub mod serve;
13 pub mod setup;
14 pub mod update_lints;
15
16 /// Returns the path to the Clippy project directory
17 ///
18 /// # Panics
19 ///
20 /// Panics if the current directory could not be retrieved, there was an error reading any of the
21 /// Cargo.toml files or ancestor directory is the clippy root directory
22 #[must_use]
23 pub fn clippy_project_root() -> PathBuf {
24     let current_dir = std::env::current_dir().unwrap();
25     for path in current_dir.ancestors() {
26         let result = std::fs::read_to_string(path.join("Cargo.toml"));
27         if let Err(err) = &result {
28             if err.kind() == std::io::ErrorKind::NotFound {
29                 continue;
30             }
31         }
32
33         let content = result.unwrap();
34         if content.contains("[package]\nname = \"clippy\"") {
35             return path.to_path_buf();
36         }
37     }
38     panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
39 }