forked from ceph/ceph-csi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-extras.sh
executable file
·106 lines (95 loc) · 2.61 KB
/
lint-extras.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
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
#!/bin/bash
# vim: set ts=4 sw=4 et :
# This script will be used to lint non-go files
# Usage: ./scripts/lint-extras.sh <command>
# Available commands are [lint-shell lint-yaml lint-markdown lint-helmlint-all ]
set -e
# Run checks from root of the repo
scriptdir="$(dirname "$(realpath "$0")")"
cd "$scriptdir/.."
# run_check <file_regex> <checker_exe> [optional args to checker...]
# Pass empty regex when no regex is needed
function run_check() {
local regex="$1"
shift
local exe="$1"
shift
if [ -x "$(command -v "${exe}")" ]; then
if [ -z "${regex}" ]; then
"$exe" "$@"
else
find . -path ./vendor -prune -o -regextype egrep -iregex "$regex" -print0 |
xargs -0rt -n1 "$exe" "$@"
fi
elif [ "$all_required" -eq 0 ]; then
echo "Warning: $exe not found... skipping some tests."
else
echo "FAILED: All checks required, but $exe not found!"
exit 1
fi
}
all_required=0
function lint_markdown() {
# markdownlint: https://github.com/markdownlint/markdownlint
# https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
# Install via: gem install mdl
run_check '.*\.md' mdl --style scripts/mdl-style.rb
}
function lint_shell() {
# Install via: dnf install shellcheck
run_check '.*\.(ba)?sh' shellcheck --external-sources
run_check '.*\.(ba)?sh' bash -n
}
function lint_yaml() {
# Install via: pip install yamllint
# disable yamlint check for helm charts
run_check '.*\.ya?ml' yamllint -s -d "{extends: default, rules: {line-length: {allow-non-breakable-inline-mappings: true}},ignore: charts/*/templates/*.yaml}"
}
function lint_helm() {
# Install via: https://github.com/helm/helm/blob/master/docs/install.md
run_check '' helm lint --namespace=test charts/*
}
function lint_py() {
# Install via: sudo apt-get install python3-pylint
run_check '.*\.py' pylint --score n --output-format=colorized
}
function lint_all() {
# runs all checks
all_required=1
lint_shell
lint_yaml
lint_markdown
lint_helm
lint_py
}
case "${1:-}" in
lint-shell)
lint_shell
;;
lint-yaml)
lint_yaml
;;
lint-markdown)
lint_markdown
;;
lint-helm)
lint_helm
;;
lint-py)
lint_py
;;
lint-all)
lint_all
;;
*)
echo " $0 [command]
Available Commands:
lint-shell Lint shell files
lint-yaml Lint yaml files
lint-markdown Lint markdown files
lint-helm Lint helm charts
lint-py Lint python files
lint-all Run lint on all non-go files
" >&2
;;
esac