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