-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathformat-code.sh
executable file
·43 lines (36 loc) · 1.08 KB
/
format-code.sh
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
#!/bin/bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"/..
LANG=${1:-}
LANG=${LANG,,}
# C
if [[ -z $LANG ]] || [[ $LANG == c ]]; then
git ls-files -- 'csrc/*.[hc]' 'bpf/*.[hc]' -x ':!:csrc/vendor' | xargs clang-format-15 -i -style=file
fi
# Go
if [[ -z $LANG ]] || [[ $LANG == go ]]; then
source mk/goenv.sh
gofmt -l -w -s .
go mod tidy
staticcheck ./...
fi
# bash
if [[ -z $LANG ]] || [[ $LANG == sh ]]; then
git ls-files -- '*.sh' | xargs shfmt -l -w -s -i=2 -ci
fi
# TypeScript
if [[ -z $LANG ]] || [[ $LANG == ts ]]; then
$(corepack pnpm bin)/xo-yoursunny --fix
fi
# YAML
if [[ -z $LANG ]] || [[ $LANG == yaml ]]; then
git ls-files '*.yml' '*.yaml' '.clang-format' | xargs yamllint -c mk/yamllint.yaml
fi
# Markdown
if [[ -z $LANG ]] || [[ $LANG == md ]]; then
git ls-files '*.md' | xargs $(corepack pnpm bin)/markdownlint
fi
# Docker
if ([[ -z $LANG ]] || [[ $LANG == docker ]]) && command -v docker &>/dev/null; then
git ls-files -- Dockerfile '*/Dockerfile' | xargs docker run --rm -u $(id -u):$(id -g) -v $PWD:/mnt -w /mnt hadolint/hadolint hadolint -t error
fi