use schemars::JsonSchema;
use toml_spanner::Toml;
use crate::rules::BashSetOption;
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])*
#[toml(Toml)]
pub struct $name {
$(
$(#[doc = $doc])+
#[toml(default)]
#[schemars(default)]
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',)*).trim(),
default: {
let default: $ty = $default;
serde_json::to_string(&default).unwrap()
},
applicable_lints: &[$(stringify!($lints)),+,]
}
),+
]
}
}
}
}
#[doc(hidden)]
#[derive(Debug)]
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, Eq, Toml, JsonSchema)]
#[schemars(rename = "WdlLintConfig")]
pub struct Config {
#[lints(ExpectedRuntimeKeys)]
allowed_runtime_keys: Vec<String> = Vec::default(),
#[lints(SnakeCase, DeclarationName)]
allowed_names: Vec<String> = Vec::default(),
#[lints(BashSetSyntax)]
bash_set_options: Vec<BashSetOption> = vec![BashSetOption::ErrExit, BashSetOption::NoUnset, BashSetOption::Pipefail],
}
}