Skip to content

Commit 3f2532b

Browse files
committed
Replace one more copy-pasted clippy_project_root fn
1 parent 3036a2c commit 3f2532b

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

clippy_dev/src/new_lint.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use clippy_dev::clippy_project_root;
12
use std::fs::{File, OpenOptions};
23
use std::io;
34
use std::io::prelude::*;
45
use std::io::ErrorKind;
5-
use std::path::{Path, PathBuf};
6+
use std::path::Path;
67

78
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
89
let pass = pass.expect("`pass` argument is validated by clap");
@@ -55,7 +56,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
5556
}
5657

5758
fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
58-
let project_root = project_root()?;
59+
let project_root = clippy_project_root();
5960

6061
let test_file_path = project_root.join("tests").join("ui").join(format!("{}.rs", lint_name));
6162
let lint_file_path = project_root
@@ -82,24 +83,6 @@ fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
8283
Ok((test_file, lint_file))
8384
}
8485

85-
fn project_root() -> Result<PathBuf, io::Error> {
86-
let current_dir = std::env::current_dir()?;
87-
for path in current_dir.ancestors() {
88-
let result = std::fs::read_to_string(path.join("Cargo.toml"));
89-
if let Err(err) = &result {
90-
if err.kind() == io::ErrorKind::NotFound {
91-
continue;
92-
}
93-
}
94-
95-
let content = result?;
96-
if content.contains("[package]\nname = \"clippy\"") {
97-
return Ok(path.to_path_buf());
98-
}
99-
}
100-
Err(io::Error::new(ErrorKind::Other, "Unable to find project root"))
101-
}
102-
10386
fn to_camel_case(name: &str) -> String {
10487
name.split('_')
10588
.map(|s| {

0 commit comments

Comments
 (0)