use std::collections::HashSet;
use serde::Deserialize;
use serde::Serialize;
macro_rules! define_lint_rule_config {
(
$(#[$meta:meta])*
pub struct $name:ident {
$(
$(#[doc = $doc:literal])+
#[lints($($lints:ident),+ $(,)?)]
$field:ident: $ty:ty = $default:expr,
)+
}
) => {
$(#[$meta])*
pub struct $name {
$(
$(#[doc = $doc])+
pub $field: $ty,
)+
}
impl Default for $name {
fn default() -> Self {
Self {
$(
$field: $default,
)+
}
}
}
impl $name {
#[doc(hidden)]
pub fn fields() -> Vec<ConfigField> {
vec![
$(
ConfigField {
name: stringify!($field),
description: concat!($($doc, '\n',)*),
default: {
let default: $ty = $default;
let mut text = String::new();
default.serialize(toml::ser::ValueSerializer::new(&mut text)).unwrap();
text
},
applicable_lints: &[$(stringify!($lints)),+,]
}
),+
]
}
}
}
}
#[doc(hidden)]
#[derive(Debug, Serialize)]
pub struct ConfigField {
pub name: &'static str,
pub description: &'static str,
pub default: String,
pub applicable_lints: &'static [&'static str],
}
define_lint_rule_config! {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct Config {
#[lints(ExpectedRuntimeKeys)]
allowed_runtime_keys: HashSet<String> = HashSet::default(),
#[lints(SnakeCase, DeclarationName)]
allowed_names: HashSet<String> = HashSet::default(),
}
}