tnipv_lint/modifiers/
default_annotation.rs1use annotate_snippets::snippet::AnnotationType;
8
9use std::fmt::Debug;
10
11use crate::lints::Context;
12use crate::LintSettings;
13
14use serde::{Deserialize, Serialize};
15
16use super::{Error, Modifier};
17
18#[derive(Serialize, Deserialize)]
19#[serde(remote = "AnnotationType", rename_all = "kebab-case")]
20enum AnnotationTypeDef {
21 Error,
22 Warning,
23 Info,
24 Note,
25 Help,
26}
27
28#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
29pub struct SetDefaultAnnotation<S> {
30 pub name: S,
31 pub value: S,
32
33 #[serde(with = "AnnotationTypeDef")]
34 pub annotation_type: AnnotationType,
35}
36
37impl<S> Modifier for SetDefaultAnnotation<S>
38where
39 S: Debug + AsRef<str>,
40{
41 fn modify(&self, context: &Context, settings: &mut LintSettings) -> Result<(), Error> {
42 let value = match context.preamble().by_name(self.name.as_ref()) {
43 Some(v) => v.value().trim(),
44 None => return Ok(()),
45 };
46
47 if value == self.value.as_ref() {
48 settings.default_annotation_type = self.annotation_type;
49 }
50
51 Ok(())
52 }
53}