typos_git_commit/
typosjsonline.rs1use crate::cli::Cli;
2use serde::Deserialize;
3
4#[derive(Deserialize, Debug, Clone)]
8pub struct TyposJsonLine {
9    #[serde(default, rename = "type")]
10    pub type_id: String,
11
12    #[serde(default)]
13    pub path: String,
14
15    #[serde(default)]
16    pub line_num: u32,
17
18    #[serde(default)]
19    pub byte_offset: u32,
20
21    #[serde(default)]
22    pub typo: String,
23
24    #[serde(default)]
25    pub corrections: Vec<String>,
26}
27
28impl TyposJsonLine {
29    pub fn is_file_excluded(&self, cli: &Cli) -> bool {
31        match &cli.exclude_file {
32            Some(list) => {
33                for file in list {
34                    if self.path.contains(file) {
35                        return true;
36                    }
37                }
38                false
39            }
40            None => false,
41        }
42    }
43
44    pub fn is_typo_excluded(&self, cli: &Cli) -> bool {
46        match &cli.exclude_typo {
47            Some(list) => {
48                for t in list {
49                    if self.typo.contains(t) {
50                        return true;
51                    }
52                }
53                false
54            }
55            None => false,
56        }
57    }
58
59    pub fn is_correction_excluded(&self, cli: &Cli) -> bool {
61        match &cli.exclude_correction {
62            Some(list) => {
63                for t in list {
64                    for correction in &self.corrections {
65                        if correction.contains(t) {
66                            return true;
67                        }
68                    }
69                }
70                false
71            }
72            None => false,
73        }
74    }
75
76    pub fn is_excluded(&self, cli: &Cli) -> bool {
79        self.is_typo_excluded(cli) || self.is_correction_excluded(cli) || self.is_file_excluded(cli)
80    }
81}