1
1
use crate :: clippy_project_root;
2
- use indoc:: { indoc , writedoc} ;
2
+ use indoc:: { formatdoc , writedoc} ;
3
3
use std:: fmt:: Write as _;
4
4
use std:: fs:: { self , OpenOptions } ;
5
5
use std:: io:: prelude:: * ;
@@ -23,7 +23,7 @@ impl<T> Context for io::Result<T> {
23
23
match self {
24
24
Ok ( t) => Ok ( t) ,
25
25
Err ( e) => {
26
- let message = format ! ( "{}: {}" , text. as_ref( ) , e ) ;
26
+ let message = format ! ( "{}: {e }" , text. as_ref( ) ) ;
27
27
Err ( io:: Error :: new ( ErrorKind :: Other , message) )
28
28
} ,
29
29
}
@@ -72,7 +72,7 @@ fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
72
72
let lint_contents = get_lint_file_contents ( lint, enable_msrv) ;
73
73
let lint_path = format ! ( "clippy_lints/src/{}.rs" , lint. name) ;
74
74
write_file ( lint. project_root . join ( & lint_path) , lint_contents. as_bytes ( ) ) ?;
75
- println ! ( "Generated lint file: `{}`" , lint_path ) ;
75
+ println ! ( "Generated lint file: `{lint_path }`" ) ;
76
76
77
77
Ok ( ( ) )
78
78
}
@@ -86,7 +86,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
86
86
87
87
path. push ( "src" ) ;
88
88
fs:: create_dir ( & path) ?;
89
- let header = format ! ( "// compile-flags: --crate-name={}" , lint_name ) ;
89
+ let header = format ! ( "// compile-flags: --crate-name={lint_name}" ) ;
90
90
write_file ( path. join ( "main.rs" ) , get_test_file_contents ( lint_name, Some ( & header) ) ) ?;
91
91
92
92
Ok ( ( ) )
@@ -106,7 +106,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
106
106
let test_contents = get_test_file_contents ( lint. name , None ) ;
107
107
write_file ( lint. project_root . join ( & test_path) , test_contents) ?;
108
108
109
- println ! ( "Generated test file: `{}`" , test_path ) ;
109
+ println ! ( "Generated test file: `{test_path }`" ) ;
110
110
}
111
111
112
112
Ok ( ( ) )
@@ -184,38 +184,36 @@ pub(crate) fn get_stabilization_version() -> String {
184
184
}
185
185
186
186
fn get_test_file_contents ( lint_name : & str , header_commands : Option < & str > ) -> String {
187
- let mut contents = format ! (
188
- indoc! { "
189
- #![allow(unused)]
190
- #![warn(clippy::{})]
191
-
192
- fn main() {{
193
- // test code goes here
194
- }}
195
- " } ,
196
- lint_name
187
+ let mut contents = formatdoc ! (
188
+ r#"
189
+ #![allow(unused)]
190
+ #![warn(clippy::{lint_name})]
191
+
192
+ fn main() {{
193
+ // test code goes here
194
+ }}
195
+ "#
197
196
) ;
198
197
199
198
if let Some ( header) = header_commands {
200
- contents = format ! ( "{}\n {}" , header , contents ) ;
199
+ contents = format ! ( "{header }\n {contents}" ) ;
201
200
}
202
201
203
202
contents
204
203
}
205
204
206
205
fn get_manifest_contents ( lint_name : & str , hint : & str ) -> String {
207
- format ! (
208
- indoc! { r#"
209
- # {}
210
-
211
- [package]
212
- name = "{}"
213
- version = "0.1.0"
214
- publish = false
215
-
216
- [workspace]
217
- "# } ,
218
- hint, lint_name
206
+ formatdoc ! (
207
+ r#"
208
+ # {hint}
209
+
210
+ [package]
211
+ name = "{lint_name}"
212
+ version = "0.1.0"
213
+ publish = false
214
+
215
+ [workspace]
216
+ "#
219
217
)
220
218
}
221
219
@@ -236,85 +234,70 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
236
234
let name_upper = lint_name. to_uppercase ( ) ;
237
235
238
236
result. push_str ( & if enable_msrv {
239
- format ! (
240
- indoc! { "
241
- use clippy_utils::msrvs;
242
- {pass_import}
243
- use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
244
- use rustc_semver::RustcVersion;
245
- use rustc_session::{{declare_tool_lint, impl_lint_pass}};
237
+ formatdoc ! (
238
+ r# "
239
+ use clippy_utils::msrvs;
240
+ {pass_import}
241
+ use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
242
+ use rustc_semver::RustcVersion;
243
+ use rustc_session::{{declare_tool_lint, impl_lint_pass}};
246
244
247
- " } ,
248
- pass_type = pass_type,
249
- pass_import = pass_import,
250
- context_import = context_import,
245
+ "#
251
246
)
252
247
} else {
253
- format ! (
254
- indoc! { "
255
- {pass_import}
256
- use rustc_lint::{{{context_import}, {pass_type}}};
257
- use rustc_session::{{declare_lint_pass, declare_tool_lint}};
258
-
259
- " } ,
260
- pass_import = pass_import,
261
- pass_type = pass_type,
262
- context_import = context_import
248
+ formatdoc ! (
249
+ r#"
250
+ {pass_import}
251
+ use rustc_lint::{{{context_import}, {pass_type}}};
252
+ use rustc_session::{{declare_lint_pass, declare_tool_lint}};
253
+
254
+ "#
263
255
)
264
256
} ) ;
265
257
266
258
let _ = write ! ( result, "{}" , get_lint_declaration( & name_upper, category) ) ;
267
259
268
260
result. push_str ( & if enable_msrv {
269
- format ! (
270
- indoc! { "
271
- pub struct {name_camel} {{
272
- msrv: Option<RustcVersion>,
273
- }}
261
+ formatdoc ! (
262
+ r# "
263
+ pub struct {name_camel} {{
264
+ msrv: Option<RustcVersion>,
265
+ }}
274
266
275
- impl {name_camel} {{
276
- #[must_use]
277
- pub fn new(msrv: Option<RustcVersion>) -> Self {{
278
- Self {{ msrv }}
279
- }}
267
+ impl {name_camel} {{
268
+ #[must_use]
269
+ pub fn new(msrv: Option<RustcVersion>) -> Self {{
270
+ Self {{ msrv }}
280
271
}}
272
+ }}
281
273
282
- impl_lint_pass!({name_camel} => [{name_upper}]);
274
+ impl_lint_pass!({name_camel} => [{name_upper}]);
283
275
284
- impl {pass_type}{pass_lifetimes} for {name_camel} {{
285
- extract_msrv_attr!({context_import});
286
- }}
276
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{
277
+ extract_msrv_attr!({context_import});
278
+ }}
287
279
288
- // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
289
- // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
290
- // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
291
- " } ,
292
- pass_type = pass_type,
293
- pass_lifetimes = pass_lifetimes,
294
- name_upper = name_upper,
295
- name_camel = name_camel,
296
- context_import = context_import,
280
+ // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
281
+ // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
282
+ // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
283
+ "#
297
284
)
298
285
} else {
299
- format ! (
300
- indoc! { "
301
- declare_lint_pass!({name_camel} => [{name_upper}]);
286
+ formatdoc ! (
287
+ r# "
288
+ declare_lint_pass!({name_camel} => [{name_upper}]);
302
289
303
- impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
304
- " } ,
305
- pass_type = pass_type,
306
- pass_lifetimes = pass_lifetimes,
307
- name_upper = name_upper,
308
- name_camel = name_camel,
290
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
291
+ "#
309
292
)
310
293
} ) ;
311
294
312
295
result
313
296
}
314
297
315
298
fn get_lint_declaration ( name_upper : & str , category : & str ) -> String {
316
- format ! (
317
- indoc! { r#"
299
+ formatdoc ! (
300
+ r#"
318
301
declare_clippy_lint! {{
319
302
/// ### What it does
320
303
///
@@ -328,15 +311,13 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
328
311
/// ```rust
329
312
/// // example code which does not raise clippy warning
330
313
/// ```
331
- #[clippy::version = "{version }"]
314
+ #[clippy::version = "{}"]
332
315
pub {name_upper},
333
316
{category},
334
317
"default lint description"
335
318
}}
336
- "# } ,
337
- version = get_stabilization_version( ) ,
338
- name_upper = name_upper,
339
- category = category,
319
+ "# ,
320
+ get_stabilization_version( ) ,
340
321
)
341
322
}
342
323
@@ -350,7 +331,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
350
331
_ => { } ,
351
332
}
352
333
353
- let ty_dir = lint. project_root . join ( format ! ( "clippy_lints/src/{}" , ty ) ) ;
334
+ let ty_dir = lint. project_root . join ( format ! ( "clippy_lints/src/{ty}" ) ) ;
354
335
assert ! (
355
336
ty_dir. exists( ) && ty_dir. is_dir( ) ,
356
337
"Directory `{}` does not exist!" ,
@@ -410,10 +391,10 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
410
391
}
411
392
412
393
write_file ( lint_file_path. as_path ( ) , lint_file_contents) ?;
413
- println ! ( "Generated lint file: `clippy_lints/src/{}/{}.rs`" , ty , lint. name) ;
394
+ println ! ( "Generated lint file: `clippy_lints/src/{ty }/{}.rs`" , lint. name) ;
414
395
println ! (
415
- "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!" ,
416
- lint. name, ty
396
+ "Be sure to add a call to `{}::check` in `clippy_lints/src/{ty }/mod.rs`!" ,
397
+ lint. name
417
398
) ;
418
399
419
400
Ok ( ( ) )
@@ -540,7 +521,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
540
521
. chain ( std:: iter:: once ( & * lint_name_upper) )
541
522
. filter ( |s| !s. is_empty ( ) )
542
523
{
543
- let _ = write ! ( new_arr_content, "\n {}," , ident ) ;
524
+ let _ = write ! ( new_arr_content, "\n {ident }," ) ;
544
525
}
545
526
new_arr_content. push ( '\n' ) ;
546
527
0 commit comments