-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
.pre-commit-config.yaml
272 lines (262 loc) · 9.43 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
---
exclude: (?x)^( htdocs/includes/ckeditor/.*|(\.(?!github/workflows)[^/]*/.*))$
repos:
# Several miscellaneous checks and fix (on yaml files, end of files fix)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
# This hook tests the name of the branch and return an error if the name is
# 'develop' or an official version 'x.y'
# So you can't commit if your branch name is not a custom branch name.
# Using a custom branch name is good practice that makes it easier to manage PRs.
# You can skip this:
# - Permanently:
# export SKIP=no-commit-to-branch # In your .bashrc or session.
# - Only this for one commit:
# SKIP=no-commit-to-branch git commit -a -m "My message"
# - Skipping all checks for a commit:
# git commit -a -m "My message" --no-verify
# (Recommendation: run git commit -a .. once, then with `--no-verify`)
- id: no-commit-to-branch
args: [--branch, develop, --pattern, \d+.0]
# This checks that xml files are correct
- id: check-xml
exclude: |
(?x)^(htdocs/includes/.*)$
# This checks that yaml files are correct
- id: check-yaml
args: [--unsafe]
# This checks that json files are correct
- id: check-json
# Fixes Fix files that have DOS end of line endings
- id: mixed-line-ending
# alternative for dev/tools/fixdosfiles.sh
exclude: |
(?x)^(htdocs/includes/tecnickcom/tcpdf/fonts/.*
|.*/CRLF.*.php # Files in swiftmailer
)$
args: [--fix=lf]
# Remove trailing whitespace
- id: trailing-whitespace
exclude_types: [markdown]
# Fix the end of file
- id: end-of-file-fixer
# Check that there are no completely merged file conflicts
- id: check-merge-conflict
stages: [pre-rebase, pre-commit, pre-merge-commit]
# Check that files with shebangs have the executable bit set (in git)
- id: check-executables-have-shebangs
# Check that shell files are executables
- id: check-shebang-scripts-are-executable
exclude:
(?x)^( dev/tools/dolibarr-postgres2mysql.php |test/other/test_serialize.php
|test/phpunit/textutf8.txt |test/phpunit/textiso.txt |htdocs/includes/.*
|htdocs/modulebuilder/template/.* |build/debian/dolibarr.postrm |build/debian/dolibarr.postinst
|build/debian/dolibarr.config )$
# Fix the first UTF8 byte
- id: fix-byte-order-marker
# Check that there are no files that have are the same when uppercased (conflict on windows)
- id: check-case-conflict
# Gitleaks is a SAST tool for detecting and preventing hardcoded secrets like passwords, api keys, and tokens in git repos
- repo: https://github.com/gitleaks/gitleaks.git
rev: v8.16.1
hooks:
- id: gitleaks
# Check github actions
- repo: https://github.com/rhysd/actionlint
rev: v1.7.3
hooks:
- id: actionlint
# Beautify shell scripts
- repo: https://github.com/lovesegfault/beautysh.git
rev: v6.2.1
hooks:
- id: beautysh
exclude: |
(?x)^(dev/setup/git/hooks/pre-commit
)$
args: [--tab]
# Run local script
#
# For example, to update the license in edited files, you could add to local.sh:
#
# ```shell
# #!/bin/bash
# MYDIR=$(dirname "$0")
# git diff HEAD --name-only | grep -v includes | \
# xargs "$MYDIR/dev/tools/updatelicense.php"
# ```
- repo: local
hooks:
- name: Find missing/unused/duplicate language keys
id: check-translations
files: (?x)^(htdocs/langs/en_US/.*\.lang)
language: script
entry: ./dev/translation/sanity_check_trans_missing_unused.sh
pass_filenames: false
args: [list]
- id: local-precommit-script
name: Run local script before commit if it exists
language: system
entry: bash -c '[ ! -x local.sh ] || ./local.sh'
pass_filenames: false
- id: duplicate-lang-lines
stages: [manual]
name: Find duplicate language lines
files: (?x)^(htdocs/langs/en_US/.*\.lang)
language: script
entry: ./dev/tools/fixduplicatelanglines.sh
pass_filenames: false
args: [list]
- id: duplicate-lang-keys
stages: [manual]
name: Find duplicate language keys
files: (?x)^(htdocs/langs/en_US/.*\.lang)
language: script
entry: ./dev/tools/fixduplicatelangkey.sh
pass_filenames: false
args: [list]
- id: fix-alt-languages
stages: [manual]
name: Fix alt languages
# Selection: see fixaltlanguages.sh script
files: (?x)^(htdocs/langs/(e[lnstu]|k[akmno]|s[lqrv]|b[nrs]|c[asy]|n[bel]|[ip]t|a[mr]|d[ae]|f[ar]|h[ei]|m[sy]|t[ag]|u[kr]|gl|ja|lo|ru|vi|zh)_[^/]*/.*\.lang)
language: script
entry: ./dev/tools/fixaltlanguages_pre-commit.sh
pass_filenames: true
# Check PHP syntax
- repo: https://github.com/mdeweerd/pre-commit-php
rev: v1.6.8
hooks:
- id: php-cbf
files: \.(php)$
args: [--standard=dev/setup/codesniffer/ruleset.xml]
- id: php-cs
files: \.(php)$
args:
[
--standard=dev/setup/codesniffer/ruleset.xml,
--report=emacs,
--severity=5,
--no-colors,
]
- alias: php-cs-with-cache
id: php-cs
# Configuration for ci - run on all files with cache
stages: [manual]
args:
[
--standard=dev/setup/codesniffer/ruleset.xml,
--report=emacs,
--severity=5,
--no-colors,
--cache=.cache/pre-commit/dolibarr-php-cs.cache,
.,
]
pass_filenames: false # Run on all files
- id: php-lint
- id: php-stan
stages: [manual]
files: \.(php)$
# Prettier (format code, only for non common files)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
stages: [manual]
exclude:
(?x)^( .*\.(phar |min\.css |lock) |htdocs/(includes|theme/common)/.*
)$
exclude_types:
- php
- executable
- binary
- shell
- javascript
- markdown
- html
- less
- plain-text
- scss
- css
- yaml
# Check format of yaml files
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args:
- --no-warnings
- -d
- "{extends: relaxed, rules: {line-length: {max: 120}}}"
# Execute codespell to fix typo errors (setup of codespell into dev/tools/codespell/)
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
# Due to a current limitation of configuration files,
# we can specify two dicts only on the CLI.
# You can update the contents of the exclude-file codespell-lines-ignore with the script
# dev/tools/codespell/addCodespellIgnores.sh
args:
- -D
- "-"
- -D
- dev/tools/codespell/codespell-dict.txt
- -I
- dev/tools/codespell/codespell-ignore.txt
- -x
- dev/tools/codespell/codespell-lines-ignore.txt
exclude_types: [image]
exclude: (?x)^(.phan/stubs/.*|phpstan\.neon.*)$
additional_dependencies: [tomli]
- alias: codespell-lang-en_US
# Only for translations with specialised exceptions
# -D contains predefined conversion dictionaries
# -L is to ignore some words
id: codespell
files: ^htdocs/langs/en_US/.*$
args:
- -D
- "-"
- -D
- dev/tools/codespell/codespell-dict.txt
- -L
- informations,medias,uptodate,reenable,crypted,developpers
- -L
- creat,unitl,alltime,datas,referers
- -I
- dev/tools/codespell/codespell-ignore.txt
- -x
- dev/tools/codespell/codespell-lines-ignore.txt
- --uri-ignore-words-list
- ned
# Check some shell scripts
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
args: [-W, "100"]
# Check sql file syntax
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.1.0
hooks:
- id: sqlfluff-lint
stages: [pre-commit, manual] # manual needed for ci
exclude: (?x)^
(dev/initdemo/mysqldump_.*\.sql
|htdocs/core/menus/init_menu_auguria\.sql
|htdocs/includes/.*
|htdocs/install/doctemplates/websites/.*_template
|htdocs/install/doctemplates/websites/website_template.*\.sql
|htdocs/install/mysql/data/llx_20_c_departements\.sql
|htdocs/install/mysql/data/llx_accounting_account_.*\.sql
|htdocs/install/mysql/migration/3\..*\.sql
|htdocs/install/mysql/migration/(1[0-5]|[456789])\.0\.0-.*\.sql
|htdocs/install/mysql/migration/repair\.sql
|htdocs/install/mysql/tables/llx_bookcal_availabilities-bookcal\.sql
|htdocs/install/mysql/tables/llx_categorie.*\.key\.sql
|htdocs/install/mysql/tables/llx_rights_def\.key\.sql
|htdocs/install/pgsql/functions/functions.*\.sql
|htdocs/modulebuilder/template/sql/.*\.sql
)$