1- use crate :: utils:: { clippy_project_root , clippy_version } ;
1+ use crate :: utils:: Version ;
22use clap:: ValueEnum ;
33use indoc:: { formatdoc, writedoc} ;
44use std:: fmt:: { self , Write as _} ;
@@ -22,11 +22,11 @@ impl fmt::Display for Pass {
2222}
2323
2424struct LintData < ' a > {
25+ clippy_version : Version ,
2526 pass : Pass ,
2627 name : & ' a str ,
2728 category : & ' a str ,
2829 ty : Option < & ' a str > ,
29- project_root : PathBuf ,
3030}
3131
3232trait Context {
@@ -50,18 +50,25 @@ impl<T> Context for io::Result<T> {
5050/// # Errors
5151///
5252/// This function errors out if the files couldn't be created or written to.
53- pub fn create ( pass : Pass , name : & str , category : & str , mut ty : Option < & str > , msrv : bool ) -> io:: Result < ( ) > {
53+ pub fn create (
54+ clippy_version : Version ,
55+ pass : Pass ,
56+ name : & str ,
57+ category : & str ,
58+ mut ty : Option < & str > ,
59+ msrv : bool ,
60+ ) -> io:: Result < ( ) > {
5461 if category == "cargo" && ty. is_none ( ) {
5562 // `cargo` is a special category, these lints should always be in `clippy_lints/src/cargo`
5663 ty = Some ( "cargo" ) ;
5764 }
5865
5966 let lint = LintData {
67+ clippy_version,
6068 pass,
6169 name,
6270 category,
6371 ty,
64- project_root : clippy_project_root ( ) ,
6572 } ;
6673
6774 create_lint ( & lint, msrv) . context ( "Unable to create lint implementation" ) ?;
@@ -88,7 +95,7 @@ fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
8895 } else {
8996 let lint_contents = get_lint_file_contents ( lint, enable_msrv) ;
9097 let lint_path = format ! ( "clippy_lints/src/{}.rs" , lint. name) ;
91- write_file ( lint . project_root . join ( & lint_path) , lint_contents. as_bytes ( ) ) ?;
98+ write_file ( & lint_path, lint_contents. as_bytes ( ) ) ?;
9299 println ! ( "Generated lint file: `{lint_path}`" ) ;
93100
94101 Ok ( ( ) )
@@ -115,8 +122,7 @@ fn create_test(lint: &LintData<'_>, msrv: bool) -> io::Result<()> {
115122 }
116123
117124 if lint. category == "cargo" {
118- let relative_test_dir = format ! ( "tests/ui-cargo/{}" , lint. name) ;
119- let test_dir = lint. project_root . join ( & relative_test_dir) ;
125+ let test_dir = format ! ( "tests/ui-cargo/{}" , lint. name) ;
120126 fs:: create_dir ( & test_dir) ?;
121127
122128 create_project_layout (
@@ -134,11 +140,11 @@ fn create_test(lint: &LintData<'_>, msrv: bool) -> io::Result<()> {
134140 false ,
135141 ) ?;
136142
137- println ! ( "Generated test directories: `{relative_test_dir }/pass`, `{relative_test_dir }/fail`" ) ;
143+ println ! ( "Generated test directories: `{test_dir }/pass`, `{test_dir }/fail`" ) ;
138144 } else {
139145 let test_path = format ! ( "tests/ui/{}.rs" , lint. name) ;
140146 let test_contents = get_test_file_contents ( lint. name , msrv) ;
141- write_file ( lint . project_root . join ( & test_path) , test_contents) ?;
147+ write_file ( & test_path, test_contents) ?;
142148
143149 println ! ( "Generated test file: `{test_path}`" ) ;
144150 }
@@ -193,11 +199,6 @@ fn to_camel_case(name: &str) -> String {
193199 . collect ( )
194200}
195201
196- pub ( crate ) fn get_stabilization_version ( ) -> String {
197- let ( minor, patch) = clippy_version ( ) ;
198- format ! ( "{minor}.{patch}.0" )
199- }
200-
201202fn get_test_file_contents ( lint_name : & str , msrv : bool ) -> String {
202203 let mut test = formatdoc ! (
203204 r"
@@ -292,7 +293,11 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
292293 ) ;
293294 }
294295
295- let _: fmt:: Result = writeln ! ( result, "{}" , get_lint_declaration( & name_upper, category) ) ;
296+ let _: fmt:: Result = writeln ! (
297+ result,
298+ "{}" ,
299+ get_lint_declaration( lint. clippy_version, & name_upper, category)
300+ ) ;
296301
297302 if enable_msrv {
298303 let _: fmt:: Result = writedoc ! (
@@ -330,7 +335,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
330335 result
331336}
332337
333- fn get_lint_declaration ( name_upper : & str , category : & str ) -> String {
338+ fn get_lint_declaration ( version : Version , name_upper : & str , category : & str ) -> String {
334339 let justification_heading = if category == "restriction" {
335340 "Why restrict this?"
336341 } else {
@@ -357,7 +362,7 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
357362 "default lint description"
358363 }}
359364 "# ,
360- get_stabilization_version ( ) ,
365+ version . rust_display ( ) ,
361366 )
362367}
363368
@@ -371,7 +376,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
371376 _ => { } ,
372377 }
373378
374- let ty_dir = lint . project_root . join ( format ! ( "clippy_lints/src/{ty}" ) ) ;
379+ let ty_dir = PathBuf :: from ( format ! ( "clippy_lints/src/{ty}" ) ) ;
375380 assert ! (
376381 ty_dir. exists( ) && ty_dir. is_dir( ) ,
377382 "Directory `{}` does not exist!" ,
@@ -529,7 +534,10 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
529534 file_contents. replace_range (
530535 // Remove the trailing newline, which should always be present
531536 last_decl_curly_offset..=last_decl_curly_offset,
532- & format ! ( "\n \n {}" , get_lint_declaration( & lint_name_upper, lint. category) ) ,
537+ & format ! (
538+ "\n \n {}" ,
539+ get_lint_declaration( lint. clippy_version, & lint_name_upper, lint. category)
540+ ) ,
533541 ) ;
534542
535543 // Add the lint to `impl_lint_pass`/`declare_lint_pass`
0 commit comments