Applying PR suggestions and cleaning up
This commit is contained in:
parent
b740a04dc4
commit
f810c11d3c
@ -92,25 +92,26 @@ macro_rules! define_Conf {
|
||||
|
||||
#[cfg(feature = "metadata-collector-lint")]
|
||||
pub mod metadata {
|
||||
use crate::utils::internal_lints::metadata_collector::ClippyConfigurationBasicInfo;
|
||||
use crate::utils::internal_lints::metadata_collector::ClippyConfiguration;
|
||||
|
||||
pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfigurationBasicInfo> {
|
||||
macro_rules! wrap_option {
|
||||
() => (None);
|
||||
($x:literal) => (Some($x));
|
||||
}
|
||||
|
||||
pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
|
||||
vec![
|
||||
$(
|
||||
{
|
||||
#[allow(unused_mut, unused_assignments)]
|
||||
let mut deprecation_reason = None;
|
||||
let deprecation_reason = wrap_option!($($dep)?);
|
||||
|
||||
// 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,
|
||||
ClippyConfiguration::new(
|
||||
stringify!($name),
|
||||
stringify!($ty),
|
||||
format!("{:?}", super::defaults::$name()),
|
||||
$doc,
|
||||
deprecation_reason,
|
||||
}
|
||||
)
|
||||
},
|
||||
)+
|
||||
]
|
||||
|
@ -149,7 +149,8 @@ impl MetadataCollector {
|
||||
fn get_lint_configs(&self, lint_name: &str) -> Option<String> {
|
||||
self.config
|
||||
.iter()
|
||||
.filter_map(|x| x.lints.iter().any(|x| x == lint_name).then(|| format!("{}", x)))
|
||||
.filter(|config| config.lints.iter().any(|lint| lint == lint_name))
|
||||
.map(ToString::to_string)
|
||||
.reduce(|acc, x| acc + &x)
|
||||
.map(|configurations| format!(CONFIGURATION_SECTION_TEMPLATE!(), configurations = configurations))
|
||||
}
|
||||
@ -261,52 +262,40 @@ impl Serialize for ApplicabilityInfo {
|
||||
// ==================================================================
|
||||
// Configuration
|
||||
// ==================================================================
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ClippyConfigurationBasicInfo {
|
||||
pub name: &'static str,
|
||||
pub config_type: &'static str,
|
||||
pub default: &'static str,
|
||||
pub doc_comment: &'static str,
|
||||
pub deprecation_reason: Option<&'static str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct ClippyConfiguration {
|
||||
pub struct ClippyConfiguration {
|
||||
name: String,
|
||||
lints: Vec<String>,
|
||||
doc: String,
|
||||
config_type: &'static str,
|
||||
default: String,
|
||||
lints: Vec<String>,
|
||||
doc: String,
|
||||
deprecation_reason: Option<&'static str>,
|
||||
}
|
||||
|
||||
fn collect_configs() -> Vec<ClippyConfiguration> {
|
||||
let cons = crate::utils::conf::metadata::get_configuration_metadata();
|
||||
cons.iter()
|
||||
.map(move |x| {
|
||||
let (lints, doc) = parse_config_field_doc(x.doc_comment)
|
||||
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
|
||||
impl ClippyConfiguration {
|
||||
pub fn new(
|
||||
name: &'static str,
|
||||
config_type: &'static str,
|
||||
default: String,
|
||||
doc_comment: &'static str,
|
||||
deprecation_reason: Option<&'static str>,
|
||||
) -> Self {
|
||||
let (lints, doc) = parse_config_field_doc(doc_comment)
|
||||
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
|
||||
|
||||
ClippyConfiguration {
|
||||
name: to_kebab(x.name),
|
||||
lints,
|
||||
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((init, _end)) = init.split_once(']') {
|
||||
return format!("[{}]", init);
|
||||
Self {
|
||||
name: to_kebab(name),
|
||||
lints,
|
||||
doc,
|
||||
config_type,
|
||||
default,
|
||||
deprecation_reason,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default.to_string()
|
||||
fn collect_configs() -> Vec<ClippyConfiguration> {
|
||||
crate::utils::conf::metadata::get_configuration_metadata()
|
||||
}
|
||||
|
||||
/// This parses the field documentation of the config struct.
|
||||
|
Loading…
x
Reference in New Issue
Block a user