-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.pre-commit-config.yaml
151 lines (140 loc) · 4.25 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
# See https://pre-commit.com/hooks.html for more hooks
#
fail_fast: true
# always exclude list (see .gitattributes)
exclude: |
(?x)^(
.git-crypt/.*|
files/ssh/.*|
files/routemonitor/.*|
files/git/allowed_signers|
bin/my-restic|
setup.md
)$
repos:
# base hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
args: ['--maxkb=200']
- id: check-case-conflict
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-yaml
- id: check-json
exclude: |
(?x)^(
files/nvim/coc-settings.json
)$
# nvim: lua
- repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.20.0
hooks:
- id: stylua-github
name: "[lua] stylua"
args: ["--config-path=files/lua/stylua.toml"]
# python: black
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
name: "[py] black"
# python: flake8
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
name: "[py] flake8"
args: ["--config=files/python/flake8_global.cfg"]
# python: isort
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
name: "[py] isort"
args: ["--profile", "black"]
# shell: shellcheck
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
name: "[sh] shellcheck"
exclude: |
(?x)^(
files/p10k/p10k.zsh|
files/zsh/navi_keybindings.zsh|
files/zsh/keybindings.zsh
)$
# shell: shfmt - requires golang to build
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.8.0-1
hooks:
- id: shfmt
name: "[sh] shfmt"
exclude: |
(?x)^(
files/p10k/p10k.zsh|
files/zsh/navi_keybindings.zsh
)$
# -w Write result to file instead of stdout.
# -i indent two spaces.
# -ci Switch cases will be indented.
# -bn Binary ops like && and | may start a line.
# -sr Redirect operators will be followed by a space.
args: ['-w', '-i=2', '-ci', '-bn', '-sr']
# ansible: ansible-lint
- repo: https://github.com/ansible-community/ansible-lint
rev: v24.7.0
hooks:
- id: ansible-lint
name: "[ansible] ansible-lint"
# ansible-lint doesn't yet accept files/exclude for pre-commit.
# https://github.com/ansible/ansible-lint/issues/611
# when fixed, just run this on the yml files in the system dir.
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: custom-rule-check-text
name: "[custom] check text in content"
description: check certain text not exist in the content
language: system
entry: |
python -c '''
import sys, os, re
files = sys.argv[1:]
# check text list
# - no user or home variable exist literally
check_text = [os.environ["USER"], os.environ["HOME"]]
for file in files:
with open(file) as f:
try:
content = f.read()
except Exception as exc:
print(file, file=sys.stderr)
raise Exception from exc
for text in check_text:
is_exist = bool(re.search(text, content))
if (is_exist):
raise ValueError(file, text)
'''
- repo: local
hooks:
- id: custom-rule-yml-ext
name: "[custom] use .yml not .yaml"
description: use .yml, not .yaml
# except for this file: https://github.com/pre-commit/pre-commit/issues/1451
exclude: .pre-commit-config.yaml
language: system
entry: |
python -c '''
import sys
files = sys.argv[1:]
for file in files:
if file.endswith(".yaml"):
raise ValueError(file)
'''