typos_cli/
file_type_specifics.rs

1//! This module specifies [`EngineConfig`] defaults for the file types defined in [`default_types`].
2//!
3//! [`EngineConfig`]: crate::config::EngineConfig
4//! [`default_types`]: crate::default_types
5
6/// Set `check_file` to `false` for these types.
7pub(crate) const NO_CHECK_TYPES: &[&str] = &["cert", "lock"];
8
9pub(crate) const TYPE_SPECIFIC_DICTS: &[(&str, StaticDictConfig)] = &[
10    (
11        "cpp",
12        StaticDictConfig {
13            ignore_idents: &[
14                "countr_one", // `std::countr_one`
15            ],
16            ignore_words: &[],
17        },
18    ),
19    (
20        "css",
21        StaticDictConfig {
22            ignore_idents: &[
23                "nd", // CSS class used by pygments (see https://github.com/pygments/pygments/blob/2.16.1/pygments/token.py#L146)
24            ],
25            ignore_words: &[],
26        },
27    ),
28    (
29        "go",
30        StaticDictConfig {
31            ignore_idents: &[
32                "flate", // https://pkg.go.dev/compress/flate
33            ],
34            ignore_words: &[],
35        },
36    ),
37    (
38        "jl",
39        StaticDictConfig {
40            ignore_idents: &[],
41            ignore_words: &[
42                "egal",  // name for `===` operator
43                "egals", // name for `===` operator
44                "modul", // stand-in for `module` when needing to avoid the keyword
45                "usig",  // stand-in for `using` when needing to avoid the keyword
46            ],
47        },
48    ),
49    (
50        "man",
51        StaticDictConfig {
52            ignore_idents: &[
53                "Nd", // .Nd macro of mdoc (see https://man.openbsd.org/mdoc.7#Nd)
54            ],
55            ignore_words: &[],
56        },
57    ),
58    (
59        "py",
60        StaticDictConfig {
61            ignore_idents: &[
62                "NDArray",  // numpy.typing.NDArray
63                "EOFError", // std
64                "arange",   // torch.arange, numpy.arange
65            ],
66            ignore_words: &[],
67        },
68    ),
69    (
70        "rust",
71        StaticDictConfig {
72            ignore_idents: &[
73                "flate2", // https://crates.io/crates/flate2
74            ],
75            ignore_words: &[
76                "ser", // serde::ser, serde_json::ser, etc.
77            ],
78        },
79    ),
80    (
81        "sh",
82        StaticDictConfig {
83            ignore_idents: &[
84                "ot", // the test command from GNU coreutils supports an -ot argument (see https://www.gnu.org/software/coreutils/manual/html_node/File-characteristic-tests.html)
85                "stap", // command from SystemTap (see https://sourceware.org/systemtap/man/stap.1.html)
86            ],
87            ignore_words: &[],
88        },
89    ),
90    (
91        "vimscript",
92        StaticDictConfig {
93            ignore_idents: &[
94                "windo", // https://vimdoc.sourceforge.net/htmldoc/windows.html#:windo
95            ],
96            ignore_words: &[],
97        },
98    ),
99];
100
101pub(crate) struct StaticDictConfig {
102    pub(crate) ignore_idents: &'static [&'static str],
103    pub(crate) ignore_words: &'static [&'static str],
104}
105
106#[cfg(test)]
107mod tests {
108    use itertools::Itertools;
109    use snapbox::prelude::*;
110
111    use super::TYPE_SPECIFIC_DICTS;
112
113    #[test]
114    fn test_type_specific_dicts_contains_no_duplicates() {
115        let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
116        let types_unique: Vec<_> = types.clone().into_iter().unique().collect();
117
118        snapbox::assert_data_eq!(types_unique.join("\n"), types.join("\n").raw());
119    }
120
121    #[test]
122    fn test_type_specific_dicts_is_sorted() {
123        // The order of the entries in TYPE_SPECIFIC_DICTS actually doesn't
124        // affect the runtime behavior, we just want them ordered
125        // so that it's easier to find entries for contributors.
126
127        let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
128        let types_sorted: Vec<_> = types.iter().cloned().sorted().collect();
129
130        snapbox::assert_data_eq!(types_sorted.join("\n"), types.join("\n").raw());
131    }
132}