-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pre-commit-config.yaml
160 lines (146 loc) · 4.67 KB
/
.pre-commit-config.yaml
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
152
153
154
155
156
157
158
159
160
repos:
- repo: local
hooks:
- id: rustfmt
name: rustfmt
language: system
entry: rustfmt
args: ["--edition", "2024", "--check"]
pass_filenames: true
files: \.rs$
- id: cargo clippy
name: cargo clippy
language: system
entry: cargo
args:
[
"clippy",
"--all",
"--tests",
"--all-features",
"--no-deps",
"--",
"-D",
"warnings",
]
pass_filenames: false
- id: cargo-deny
name: cargo-deny
language: system
entry: cargo-deny
args: ["check"]
pass_filenames: false
# link validation
- id: lychee
name: link validation
language: system
entry: lychee
args: ["--no-progress"] # , "--cache"
- id: typos
name: typos
language: system
entry: typos
- id: sorted-dictionary-check
name: make sure dictionary words are sorted and unique
language: system
entry: bash
args:
- -c
- |
FILE="spellcheck.dic"
# Verify the first line is an integer.
first_line=$(head -n 1 "$FILE")
if ! [[ "$first_line" =~ ^[0-9]+$ ]]; then
echo "Error: The first line of $FILE must be an integer, but got: '$first_line'"
exit 1
fi
expected_count="$first_line"
# Verify the last line is completely empty (no spaces).
last_line=$(tail -n 1 "$FILE")
if [ -n "$last_line" ]; then
echo "Error: The last line of $FILE must be empty (without spaces)."
exit 1
fi
# Check that the number of lines between the first and last matches the integer.
# xargs (with no arguments) will strip leading/trailing whitespace from wc's output.
actual_count=$(sed '1d;$d' "$FILE" | wc -l | xargs)
if [ "$expected_count" -ne "$actual_count" ]; then
echo "Error: The number of lines between the first and last ($actual_count) does not match $expected_count."
exit 1
fi
(
# Remove the first and last lines
sed '1d; $d' $FILE | LC_ALL=C sort -uc
) || {
echo "Dictionary is not in sorted order. Correct order is:"
# Show the correct order
LC_ALL=C sort -u <(sed '1d; $d' $FILE)
false
}
pass_filenames: false
- id: cargo-spellcheck
name: cargo-spellcheck
language: system
entry: bash
args:
- -c
- |
if ! cargo-spellcheck check --code 1
then
echo ''
echo ''
echo 'If this is a Rust method/type/variable name, then you should'
echo 'enclose it in backticks like this: `MyRustType`.'
echo ''
echo 'If this is a real word, then you can add it to spellcheck.dic'
exit 1
fi
pass_filenames: false
- id: detect-trailing-whitespace-rg
name: detect trailing whitespace
language: system
entry: bash
args:
- -c
- |
# We'll search for trailing whitespace with a pattern like `[ \t]+$`
# `\s$` is okay too, but `[ \t]+$` can be more explicit.
# By default, rg respects .gitignore, so node_modules is skipped if it's ignored.
if rg --line-number --no-heading '[ \t]+$' .
then
echo ''
echo 'Please remove trailing whitespace from these lines.'
exit 1
fi
# We don't pass filenames in pre-commit, because we want to search the entire repo
pass_filenames: false
- id: taplo-check
name: taplo TOML check
language: system
entry: bash
args:
- -c
- |
# Pre-commit passes a list of changed .toml files
for file in "$@"; do
echo "Checking TOML: $file"
taplo check "$file" || exit 1
done
- ""
pass_filenames: true
types_or: [toml]
- id: custom-yaml-check
name: custom Rust YAML checker
language: system
entry: bash
args:
- -c
- |
cargo run --bin checker_util -- "$@"
- ""
pass_filenames: true
types: [yaml]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.43.0
hooks:
- id: markdownlint