swc/crates/swc_ecma_lints/src/config.rs
Artur 987213797f
feat(es/lints): Implement "no-console" rule (#3269)
swc_ecma_lints:
 - Add types for general configuration.
 - Add `no-console`rule.

swc:
 - Expose the lint config via `jsc.lints`.
2022-01-26 20:39:19 +09:00

42 lines
963 B
Rust

use crate::rules::no_console::NoConsoleConfig;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum LintRuleReaction {
Off,
Warning,
Error,
}
impl Default for LintRuleReaction {
fn default() -> Self {
Self::Off
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RuleConfig<T: Debug + Clone + Serialize + Default>(
#[serde(default)] LintRuleReaction,
#[serde(default)] T,
);
impl<T: Debug + Clone + Serialize + Default> RuleConfig<T> {
pub(crate) fn get_rule_reaction(&self) -> &LintRuleReaction {
&self.0
}
pub(crate) fn get_rule_config(&self) -> &T {
&self.1
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(rename_all = "camelCase")]
pub struct LintConfig {
#[serde(default)]
pub no_console: RuleConfig<NoConsoleConfig>,
}