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 #[must_use]
31 pub fn is_file_excluded(&self, cli: &Cli) -> bool {
32 match &cli.exclude_file {
33 Some(list) => {
34 for file in list {
35 if self.path.contains(file) {
36 return true;
37 }
38 }
39 false
40 }
41 None => false,
42 }
43 }
44
45 #[must_use]
47 pub fn is_typo_excluded(&self, cli: &Cli) -> bool {
48 match &cli.exclude_typo {
49 Some(list) => {
50 for t in list {
51 if self.typo.contains(t) {
52 return true;
53 }
54 }
55 false
56 }
57 None => false,
58 }
59 }
60
61 #[must_use]
63 pub fn is_correction_excluded(&self, cli: &Cli) -> bool {
64 match &cli.exclude_correction {
65 Some(list) => {
66 for t in list {
67 for correction in &self.corrections {
68 if correction.contains(t) {
69 return true;
70 }
71 }
72 }
73 false
74 }
75 None => false,
76 }
77 }
78
79 #[must_use]
82 pub fn is_excluded(&self, cli: &Cli) -> bool {
83 self.is_typo_excluded(cli) || self.is_correction_excluded(cli) || self.is_file_excluded(cli)
84 }
85}