Skip to content

Commit

Permalink
Metadata collection collecting configuration deprecation reason
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed May 12, 2021
1 parent b03642e commit b740a04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
21 changes: 15 additions & 6 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ macro_rules! define_Conf {
pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfigurationBasicInfo> {
vec![
$(
ClippyConfigurationBasicInfo {
name: stringify!($name),
config_type: stringify!($ty),
default: stringify!($default),
doc_comment: $doc,
{
#[allow(unused_mut, unused_assignments)]
let mut deprecation_reason = None;

// only set if a deprecation reason was set
$(deprecation_reason = Some(stringify!($dep));)?

ClippyConfigurationBasicInfo {
name: stringify!($name),
config_type: stringify!($ty),
default: stringify!($default),
doc_comment: $doc,
deprecation_reason,
}
},
)+
]
Expand All @@ -118,7 +127,7 @@ define_Conf! {
(blacklisted_names: Vec<String> = ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
(cognitive_complexity_threshold: u64 = 25),
/// Lint: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead")]
(cyclomatic_complexity_threshold: Option<u64> = None),
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
Expand Down
7 changes: 5 additions & 2 deletions clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub(crate) struct ClippyConfigurationBasicInfo {
pub config_type: &'static str,
pub default: &'static str,
pub doc_comment: &'static str,
pub deprecation_reason: Option<&'static str>,
}

#[derive(Debug, Clone, Default)]
Expand All @@ -276,6 +277,7 @@ struct ClippyConfiguration {
doc: String,
config_type: &'static str,
default: String,
deprecation_reason: Option<&'static str>,
}

fn collect_configs() -> Vec<ClippyConfiguration> {
Expand All @@ -291,18 +293,19 @@ fn collect_configs() -> Vec<ClippyConfiguration> {
doc,
config_type: x.config_type,
default: clarify_default(x.default),
deprecation_reason: x.deprecation_reason,
}
})
.collect()
}

fn clarify_default(default: &'static str) -> String {
if let Some((_start, init)) = default.split_once('[') {
if let Some((_start, init)) = default.split_once('[') {
if let Some((init, _end)) = init.split_once(']') {
return format!("[{}]", init);
}
}

default.to_string()
}

Expand Down

0 comments on commit b740a04

Please sign in to comment.