forked from crate-ci/typos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_type_specifics.rs
111 lines (101 loc) · 3.38 KB
/
file_type_specifics.rs
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
//! 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 const NO_CHECK_TYPES: &[&str] = &["cert", "lock"];
pub const TYPE_SPECIFIC_DICTS: &[(&str, StaticDictConfig)] = &[
(
"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: &[],
},
),
(
"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
],
ignore_words: &[],
},
),
(
"rust",
StaticDictConfig {
ignore_idents: &[
"flate2", // https://crates.io/crates/flate2
],
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 struct StaticDictConfig {
pub ignore_idents: &'static [&'static str],
pub ignore_words: &'static [&'static str],
}
#[cfg(test)]
mod tests {
use itertools::Itertools;
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_eq(types.join("\n"), types_unique.join("\n"));
}
#[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_eq(types.join("\n"), types_sorted.join("\n"));
}
}