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