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                "ratatui", // https://crates.io/crates/ratatui
75            ],
76            ignore_words: &[
77                "ser", // serde::ser, serde_json::ser, etc.
78            ],
79        },
80    ),
81    (
82        "sh",
83        StaticDictConfig {
84            ignore_idents: &[
85                "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)
86                "stap", // command from SystemTap (see https://sourceware.org/systemtap/man/stap.1.html)
87            ],
88            ignore_words: &[],
89        },
90    ),
91    (
92        "vimscript",
93        StaticDictConfig {
94            ignore_idents: &[
95                "windo", // https://vimdoc.sourceforge.net/htmldoc/windows.html#:windo
96            ],
97            ignore_words: &[],
98        },
99    ),
100];
101
102pub(crate) struct StaticDictConfig {
103    pub(crate) ignore_idents: &'static [&'static str],
104    pub(crate) ignore_words: &'static [&'static str],
105}
106
107#[cfg(test)]
108mod tests {
109    use itertools::Itertools;
110    use snapbox::prelude::*;
111
112    use super::TYPE_SPECIFIC_DICTS;
113
114    #[test]
115    fn test_type_specific_dicts_contains_no_duplicates() {
116        let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
117        let types_unique: Vec<_> = types.clone().into_iter().unique().collect();
118
119        snapbox::assert_data_eq!(types_unique.join("\n"), types.join("\n").raw());
120    }
121
122    #[test]
123    fn test_type_specific_dicts_is_sorted() {
124        // The order of the entries in TYPE_SPECIFIC_DICTS actually doesn't
125        // affect the runtime behavior, we just want them ordered
126        // so that it's easier to find entries for contributors.
127
128        let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
129        let types_sorted: Vec<_> = types.iter().cloned().sorted().collect();
130
131        snapbox::assert_data_eq!(types_sorted.join("\n"), types.join("\n").raw());
132    }
133}