Skip to content

Commit 6964c15

Browse files
authored
chore: use git hooks for linter/formatter and signed-off/conventional-commits (podman-desktop#2847)
* chore: use pre-commit hook for linter/formatter fixes podman-desktop#2845 Signed-off-by: Florent Benoit <[email protected]>
1 parent 79a9644 commit 6964c15

File tree

5 files changed

+734
-16
lines changed

5 files changed

+734
-16
lines changed

.husky/commit-msg

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
#!/usr/bin/env sh
3+
#
4+
# Copyright (C) 2023 Red Hat, Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
20+
. "$(dirname -- "$0")/_/husky.sh"
21+
22+
set -u
23+
24+
# avoid [[ which is not POSIX sh.
25+
if test "$#" != 1; then
26+
echo "$0 requires an argument."
27+
exit 1
28+
fi
29+
30+
if test ! -f "$1"; then
31+
echo "file does not exist: $1"
32+
exit 1
33+
fi
34+
35+
yarn commitlint --edit "$1"
36+
37+
SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
38+
grep -qs "^$SOB" "$1" || echo "$SOB" >>"$1"
39+
40+
# Catches duplicate Signed-off-by lines.
41+
42+
test "" = "$(grep '^Signed-off-by: ' "$1" |
43+
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
44+
echo >&2 Duplicate Signed-off-by lines.
45+
exit 1
46+
}

.husky/pre-commit

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Copyright (C) 2023 Red Hat, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
. "$(dirname -- "$0")/_/husky.sh"
20+
21+
yarn lint-staged

commitlint.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,19 @@
7070
"typecheck:renderer": "npm run build:preload:types && tsc --noEmit -p packages/renderer/tsconfig.json",
7171
"typecheck": "npm run typecheck:main && npm run typecheck:preload && npm run typecheck:renderer && npm run typecheck:preload-dd-extension",
7272
"website:build": "cd website && yarn run docusaurus build",
73-
"website:dev": "cd website && yarn run docusaurus start"
73+
"website:dev": "cd website && yarn run docusaurus start",
74+
"prepare": "husky install"
75+
},
76+
"lint-staged": {
77+
"*.{js,ts,tsx,svelte}": [
78+
"eslint --cache --fix",
79+
"prettier --write"
80+
],
81+
"*.{md,css,json}": "prettier --write"
7482
},
7583
"devDependencies": {
84+
"@commitlint/cli": "^17.6.5",
85+
"@commitlint/config-conventional": "^17.6.5",
7686
"@playwright/test": "^1.35.0",
7787
"@rollup/plugin-commonjs": "^25.0.1",
7888
"@rollup/plugin-json": "^6.0.0",
@@ -100,6 +110,8 @@
100110
"eslint-plugin-import": "^2.27.5",
101111
"eslint-plugin-redundant-undefined": "^0.4.0",
102112
"eslint-plugin-sonarjs": "^0.19.0",
113+
"husky": "^8.0.0",
114+
"lint-staged": "^13.2.2",
103115
"nock": "^13.3.1",
104116
"playwright": "1.35.0",
105117
"postcss-import": "^15.1.0",

0 commit comments

Comments
 (0)