Skip to content

Commit 8948ed9

Browse files
committed
Applying PR suggestions and cleaning up
1 parent b740a04 commit 8948ed9

File tree

2 files changed

+39
-49
lines changed

2 files changed

+39
-49
lines changed

clippy_lints/src/utils/conf.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,26 @@ macro_rules! define_Conf {
9292

9393
#[cfg(feature = "metadata-collector-lint")]
9494
pub mod metadata {
95-
use crate::utils::internal_lints::metadata_collector::ClippyConfigurationBasicInfo;
95+
use crate::utils::internal_lints::metadata_collector::ClippyConfiguration;
9696

97-
pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfigurationBasicInfo> {
97+
macro_rules! wrap_option {
98+
() => (None);
99+
($x:literal) => (Some($x));
100+
}
101+
102+
pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
98103
vec![
99104
$(
100105
{
101-
#[allow(unused_mut, unused_assignments)]
102-
let mut deprecation_reason = None;
106+
let deprecation_reason = wrap_option!($($dep)?);
103107

104-
// only set if a deprecation reason was set
105-
$(deprecation_reason = Some(stringify!($dep));)?
106-
107-
ClippyConfigurationBasicInfo {
108-
name: stringify!($name),
109-
config_type: stringify!($ty),
110-
default: stringify!($default),
111-
doc_comment: $doc,
108+
ClippyConfiguration::new(
109+
stringify!($name),
110+
stringify!($ty),
111+
format!("{:?}", super::defaults::$name()),
112+
$doc,
112113
deprecation_reason,
113-
}
114+
)
114115
},
115116
)+
116117
]

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+25-36
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ impl MetadataCollector {
149149
fn get_lint_configs(&self, lint_name: &str) -> Option<String> {
150150
self.config
151151
.iter()
152-
.filter_map(|x| x.lints.iter().any(|x| x == lint_name).then(|| format!("{}", x)))
152+
.filter(|config| config.lints.iter().any(|lint| lint == lint_name))
153+
.map(ToString::to_string)
153154
.reduce(|acc, x| acc + &x)
154155
.map(|configurations| format!(CONFIGURATION_SECTION_TEMPLATE!(), configurations = configurations))
155156
}
@@ -261,52 +262,40 @@ impl Serialize for ApplicabilityInfo {
261262
// ==================================================================
262263
// Configuration
263264
// ==================================================================
264-
#[derive(Debug)]
265-
pub(crate) struct ClippyConfigurationBasicInfo {
266-
pub name: &'static str,
267-
pub config_type: &'static str,
268-
pub default: &'static str,
269-
pub doc_comment: &'static str,
270-
pub deprecation_reason: Option<&'static str>,
271-
}
272-
273265
#[derive(Debug, Clone, Default)]
274-
struct ClippyConfiguration {
266+
pub struct ClippyConfiguration {
275267
name: String,
276-
lints: Vec<String>,
277-
doc: String,
278268
config_type: &'static str,
279269
default: String,
270+
lints: Vec<String>,
271+
doc: String,
280272
deprecation_reason: Option<&'static str>,
281273
}
282274

283-
fn collect_configs() -> Vec<ClippyConfiguration> {
284-
let cons = crate::utils::conf::metadata::get_configuration_metadata();
285-
cons.iter()
286-
.map(move |x| {
287-
let (lints, doc) = parse_config_field_doc(x.doc_comment)
288-
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
289-
290-
ClippyConfiguration {
291-
name: to_kebab(x.name),
292-
lints,
293-
doc,
294-
config_type: x.config_type,
295-
default: clarify_default(x.default),
296-
deprecation_reason: x.deprecation_reason,
297-
}
298-
})
299-
.collect()
300-
}
275+
impl ClippyConfiguration {
276+
pub fn new(
277+
name: &'static str,
278+
config_type: &'static str,
279+
default: String,
280+
doc_comment: &'static str,
281+
deprecation_reason: Option<&'static str>,
282+
) -> Self {
283+
let (lints, doc) = parse_config_field_doc(doc_comment)
284+
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
301285

302-
fn clarify_default(default: &'static str) -> String {
303-
if let Some((_start, init)) = default.split_once('[') {
304-
if let Some((init, _end)) = init.split_once(']') {
305-
return format!("[{}]", init);
286+
Self {
287+
name: to_kebab(name),
288+
lints,
289+
doc,
290+
config_type,
291+
default,
292+
deprecation_reason,
306293
}
307294
}
295+
}
308296

309-
default.to_string()
297+
fn collect_configs() -> Vec<ClippyConfiguration> {
298+
crate::utils::conf::metadata::get_configuration_metadata()
310299
}
311300

312301
/// This parses the field documentation of the config struct.

0 commit comments

Comments
 (0)