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