1
+ use clippy_dev:: clippy_project_root;
1
2
use std:: fs:: { File , OpenOptions } ;
2
3
use std:: io;
3
4
use std:: io:: prelude:: * ;
4
5
use std:: io:: ErrorKind ;
5
- use std:: path:: { Path , PathBuf } ;
6
+ use std:: path:: Path ;
6
7
7
8
pub fn create ( pass : Option < & str > , lint_name : Option < & str > , category : Option < & str > ) -> Result < ( ) , io:: Error > {
8
9
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
55
56
}
56
57
57
58
fn open_files ( lint_name : & str ) -> Result < ( File , File ) , io:: Error > {
58
- let project_root = project_root ( ) ? ;
59
+ let project_root = clippy_project_root ( ) ;
59
60
60
61
let test_file_path = project_root. join ( "tests" ) . join ( "ui" ) . join ( format ! ( "{}.rs" , lint_name) ) ;
61
62
let lint_file_path = project_root
@@ -82,24 +83,6 @@ fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
82
83
Ok ( ( test_file, lint_file) )
83
84
}
84
85
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]\n name = \" clippy\" " ) {
97
- return Ok ( path. to_path_buf ( ) ) ;
98
- }
99
- }
100
- Err ( io:: Error :: new ( ErrorKind :: Other , "Unable to find project root" ) )
101
- }
102
-
103
86
fn to_camel_case ( name : & str ) -> String {
104
87
name. split ( '_' )
105
88
. map ( |s| {
0 commit comments