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 "Rela32", // https://pkg.go.dev/debug/elf#Rela32
43 "Rela64", // https://pkg.go.dev/debug/elf#Rela64
44 "NewCBCEncrypter", // https://pkg.go.dev/crypto/cipher#NewCBCEncrypter
45 "NewCFBEncrypter", // https://pkg.go.dev/crypto/cipher#NewCFBEncrypter
46 "O_WRONLY", // https://pkg.go.dev/os#O_WRONLY and https://pkg.go.dev/syscall#O_WRONLY
47 "NOTE_FFOR", // https://pkg.go.dev/syscall?GOOS=darwin#NOTE_FFOR
48 "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", // https://pkg.go.dev/crypto/tls#TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
49 "TLS_RSA_WITH_3DES_EDE_CBC_SHA", // https://pkg.go.dev/crypto/tls#TLS_RSA_WITH_3DES_EDE_CBC_SHA
50 ],
51 ignore_words: &[],
52 },
53 ),
54 (
55 "jl",
56 StaticDictConfig {
57 ignore_idents: &[],
58 ignore_words: &[
59 "egal", // name for `===` operator
60 "egals", // name for `===` operator
61 "modul", // stand-in for `module` when needing to avoid the keyword
62 "usig", // stand-in for `using` when needing to avoid the keyword
63 ],
64 },
65 ),
66 (
67 "man",
68 StaticDictConfig {
69 ignore_idents: &[
70 "Nd", // .Nd macro of mdoc (see https://man.openbsd.org/mdoc.7#Nd)
71 ],
72 ignore_words: &[],
73 },
74 ),
75 (
76 "py",
77 StaticDictConfig {
78 ignore_idents: &[
79 "NDArray", // numpy.typing.NDArray
80 "EOFError", // std
81 "arange", // torch.arange, numpy.arange
82 "certifi", // popular package
83 ],
84 ignore_words: &[],
85 },
86 ),
87 (
88 "rust",
89 StaticDictConfig {
90 ignore_idents: &[
91 "flate2", // https://crates.io/crates/flate2
92 "ratatui", // https://crates.io/crates/ratatui
93 ],
94 ignore_words: &[
95 "ser", // serde::ser, serde_json::ser, etc.
96 ],
97 },
98 ),
99 (
100 "sh",
101 StaticDictConfig {
102 ignore_idents: &[
103 "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)
104 "stap", // command from SystemTap (see https://sourceware.org/systemtap/man/stap.1.html)
105 ],
106 ignore_words: &[],
107 },
108 ),
109 (
110 "vimscript",
111 StaticDictConfig {
112 ignore_idents: &[
113 "windo", // https://vimdoc.sourceforge.net/htmldoc/windows.html#:windo
114 ],
115 ignore_words: &[],
116 },
117 ),
118];
119
120pub(crate) struct StaticDictConfig {
121 pub(crate) ignore_idents: &'static [&'static str],
122 pub(crate) ignore_words: &'static [&'static str],
123}
124
125#[cfg(test)]
126mod tests {
127 use itertools::Itertools;
128 use snapbox::prelude::*;
129
130 use super::TYPE_SPECIFIC_DICTS;
131
132 #[test]
133 fn test_type_specific_dicts_contains_no_duplicates() {
134 let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
135 let types_unique: Vec<_> = types.clone().into_iter().unique().collect();
136
137 snapbox::assert_data_eq!(types_unique.join("\n"), types.join("\n").raw());
138 }
139
140 #[test]
141 fn test_type_specific_dicts_is_sorted() {
142 // The order of the entries in TYPE_SPECIFIC_DICTS actually doesn't
143 // affect the runtime behavior, we just want them ordered
144 // so that it's easier to find entries for contributors.
145
146 let types: Vec<_> = TYPE_SPECIFIC_DICTS.iter().map(|(typ, _)| *typ).collect();
147 let types_sorted: Vec<_> = types.iter().cloned().sorted().collect();
148
149 snapbox::assert_data_eq!(types_sorted.join("\n"), types.join("\n").raw());
150 }
151}