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