Skip to content

Commit 7d9b21b

Browse files
author
Michael Wright
committed
Use indoc for formatting
1 parent b878225 commit 7d9b21b

File tree

2 files changed

+80
-73
lines changed

2 files changed

+80
-73
lines changed

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
bytecount = "0.6"
88
clap = "2.33"
9+
indoc = "1.0"
910
itertools = "0.10"
1011
opener = "0.5"
1112
regex = "1.5"

clippy_dev/src/new_lint.rs

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::clippy_project_root;
2+
use indoc::indoc;
23
use std::fs::{self, OpenOptions};
34
use std::io::prelude::*;
45
use std::io::{self, ErrorKind};
@@ -105,12 +106,13 @@ fn to_camel_case(name: &str) -> String {
105106

106107
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
107108
let mut contents = format!(
108-
"#![warn(clippy::{})]
109+
indoc! {"
110+
#![warn(clippy::{})]
109111
110-
fn main() {{
111-
// test code goes here
112-
}}
113-
",
112+
fn main() {{
113+
// test code goes here
114+
}}
115+
"},
114116
lint_name
115117
);
116118

@@ -123,16 +125,16 @@ fn main() {{
123125

124126
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
125127
format!(
126-
r#"
127-
# {}
128+
indoc! {r#"
129+
# {}
128130
129-
[package]
130-
name = "{}"
131-
version = "0.1.0"
132-
publish = false
131+
[package]
132+
name = "{}"
133+
version = "0.1.0"
134+
publish = false
133135
134-
[workspace]
135-
"#,
136+
[workspace]
137+
"#},
136138
hint, lint_name
137139
)
138140
}
@@ -156,78 +158,82 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
156158

157159
result.push_str(&if enable_msrv {
158160
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+
"},
166169
pass_type = pass_type,
167170
pass_import = pass_import,
168171
context_import = context_import,
169172
)
170173
} else {
171174
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}};
175179
176-
",
180+
"},
177181
pass_import = pass_import,
178182
pass_type = pass_type,
179183
context_import = context_import
180184
)
181185
});
182186

183187
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+
"},
201207
name_upper = name_upper,
202208
category = category,
203209
));
204210

205211
result.push_str(&if enable_msrv {
206212
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+
"},
231237
pass_type = pass_type,
232238
pass_lifetimes = pass_lifetimes,
233239
pass_name = pass_name,
@@ -238,14 +244,14 @@ impl {pass_type}{pass_lifetimes} for {name_camel} {{
238244
)
239245
} else {
240246
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+
"},
249255
pass_type = pass_type,
250256
pass_lifetimes = pass_lifetimes,
251257
pass_name = pass_name,

0 commit comments

Comments
 (0)