1+ use clippy_dev:: clippy_project_root;
12use std:: fs:: { File , OpenOptions } ;
23use std:: io;
34use std:: io:: prelude:: * ;
45use std:: io:: ErrorKind ;
5- use std:: path:: { Path , PathBuf } ;
6+ use std:: path:: Path ;
67
78pub 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
5758fn 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]\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-
10386fn to_camel_case ( name : & str ) -> String {
10487 name. split ( '_' )
10588 . map ( |s| {
0 commit comments