1
1
use crate :: clippy_project_root;
2
+ use indoc:: indoc;
2
3
use std:: fs:: { self , OpenOptions } ;
3
4
use std:: io:: prelude:: * ;
4
5
use std:: io:: { self , ErrorKind } ;
@@ -105,12 +106,13 @@ fn to_camel_case(name: &str) -> String {
105
106
106
107
fn get_test_file_contents ( lint_name : & str , header_commands : Option < & str > ) -> String {
107
108
let mut contents = format ! (
108
- "#![warn(clippy::{})]
109
+ indoc! { "
110
+ #![warn(clippy::{})]
109
111
110
- fn main() {{
111
- // test code goes here
112
- }}
113
- " ,
112
+ fn main() {{
113
+ // test code goes here
114
+ }}
115
+ " } ,
114
116
lint_name
115
117
) ;
116
118
@@ -123,16 +125,16 @@ fn main() {{
123
125
124
126
fn get_manifest_contents ( lint_name : & str , hint : & str ) -> String {
125
127
format ! (
126
- r#"
127
- # {}
128
+ indoc! { r#"
129
+ # {}
128
130
129
- [package]
130
- name = "{}"
131
- version = "0.1.0"
132
- publish = false
131
+ [package]
132
+ name = "{}"
133
+ version = "0.1.0"
134
+ publish = false
133
135
134
- [workspace]
135
- "# ,
136
+ [workspace]
137
+ "# } ,
136
138
hint, lint_name
137
139
)
138
140
}
@@ -156,78 +158,82 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
156
158
157
159
result. push_str ( & if enable_msrv {
158
160
format ! (
159
- "use clippy_utils::msrvs;
160
- {pass_import}
161
- use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
162
- use rustc_semver::RustcVersion;
163
- use rustc_session::{{declare_tool_lint, impl_lint_pass}};
164
-
165
- " ,
161
+ indoc! { "
162
+ use clippy_utils::msrvs;
163
+ {pass_import}
164
+ use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
165
+ use rustc_semver::RustcVersion;
166
+ use rustc_session::{{declare_tool_lint, impl_lint_pass}};
167
+
168
+ " } ,
166
169
pass_type = pass_type,
167
170
pass_import = pass_import,
168
171
context_import = context_import,
169
172
)
170
173
} else {
171
174
format ! (
172
- "{pass_import}
173
- use rustc_lint::{{{context_import}, {pass_type}}};
174
- use rustc_session::{{declare_lint_pass, declare_tool_lint}};
175
+ indoc! { "
176
+ {pass_import}
177
+ use rustc_lint::{{{context_import}, {pass_type}}};
178
+ use rustc_session::{{declare_lint_pass, declare_tool_lint}};
175
179
176
- " ,
180
+ " } ,
177
181
pass_import = pass_import,
178
182
pass_type = pass_type,
179
183
context_import = context_import
180
184
)
181
185
} ) ;
182
186
183
187
result. push_str ( & format ! (
184
- "declare_clippy_lint! {{
185
- /// ### What it does
186
- ///
187
- /// ### Why is this bad?
188
- ///
189
- /// ### Example
190
- /// ```rust
191
- /// // example code where clippy issues a warning
192
- /// ```
193
- /// Use instead:
194
- /// ```rust
195
- /// // example code which does not raise clippy warning
196
- /// ```
197
- pub {name_upper},
198
- {category},
199
- \" default lint description\"
200
- }}" ,
188
+ indoc! { "
189
+ declare_clippy_lint! {{
190
+ /// ### What it does
191
+ ///
192
+ /// ### Why is this bad?
193
+ ///
194
+ /// ### Example
195
+ /// ```rust
196
+ /// // example code where clippy issues a warning
197
+ /// ```
198
+ /// Use instead:
199
+ /// ```rust
200
+ /// // example code which does not raise clippy warning
201
+ /// ```
202
+ pub {name_upper},
203
+ {category},
204
+ \" default lint description\"
205
+ }}
206
+ " } ,
201
207
name_upper = name_upper,
202
208
category = category,
203
209
) ) ;
204
210
205
211
result. push_str ( & if enable_msrv {
206
212
format ! (
207
- "
208
- pub struct {name_camel} {{
209
- msrv: Option<RustcVersion>,
210
- }}
211
-
212
- impl {name_camel} {{
213
- #[must_use]
214
- pub fn new(msrv: Option<RustcVersion>) -> Self {{
215
- Self {{ msrv }}
216
- }}
217
- }}
218
-
219
- impl_lint_pass!({name_camel} => [{name_upper}]);
220
-
221
- impl {pass_type}{pass_lifetimes} for {name_camel} {{
222
- extract_msrv_attr!({context_import});
223
- }}
224
-
225
- // TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
226
- // e.g. store.register_{pass_name}_pass(move || Box::new({module_name}::{name_camel}::new(msrv)));
227
- // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
228
- // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
229
- // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
230
- " ,
213
+ indoc! { "
214
+ pub struct {name_camel} {{
215
+ msrv: Option<RustcVersion>,
216
+ }}
217
+
218
+ impl {name_camel} {{
219
+ #[must_use]
220
+ pub fn new(msrv: Option<RustcVersion>) -> Self {{
221
+ Self {{ msrv }}
222
+ }}
223
+ }}
224
+
225
+ impl_lint_pass!({name_camel} => [{name_upper}]);
226
+
227
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{
228
+ extract_msrv_attr!({context_import});
229
+ }}
230
+
231
+ // TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
232
+ // e.g. store.register_{pass_name}_pass(move || Box::new({module_name}::{name_camel}::new(msrv)));
233
+ // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
234
+ // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
235
+ // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
236
+ " } ,
231
237
pass_type = pass_type,
232
238
pass_lifetimes = pass_lifetimes,
233
239
pass_name = pass_name,
@@ -238,14 +244,14 @@ impl {pass_type}{pass_lifetimes} for {name_camel} {{
238
244
)
239
245
} else {
240
246
format ! (
241
- "
242
- declare_lint_pass!({name_camel} => [{name_upper}]);
243
-
244
- impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
245
- //
246
- // TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
247
- // e.g. store.register_{pass_name}_pass(|| Box::new({module_name}::{name_camel}));
248
- " ,
247
+ indoc! { "
248
+ declare_lint_pass!({name_camel} => [{name_upper}]);
249
+
250
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
251
+ //
252
+ // TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
253
+ // e.g. store.register_{pass_name}_pass(|| Box::new({module_name}::{name_camel}));
254
+ " } ,
249
255
pass_type = pass_type,
250
256
pass_lifetimes = pass_lifetimes,
251
257
pass_name = pass_name,
0 commit comments