summaryrefslogtreecommitdiff
path: root/hack/lib/lint.sh
diff options
context:
space:
mode:
authorzhangjie <iamkadisi@163.com>2020-02-05 15:34:01 +0800
committerzhangjie <iamkadisi@163.com>2020-02-18 16:12:24 +0800
commit2d341dee7b21b9e75c7c45fe258052b6b068c152 (patch)
tree68bf6de8ad663e5719a9470c279fcf0e8c798aee /hack/lib/lint.sh
parentsupport make test (diff)
downloadkubeedge-2d341dee7b21b9e75c7c45fe258052b6b068c152.tar.gz
support make lint
Signed-off-by: zhangjie <iamkadisi@163.com>
Diffstat (limited to 'hack/lib/lint.sh')
-rw-r--r--hack/lib/lint.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/hack/lib/lint.sh b/hack/lib/lint.sh
new file mode 100644
index 000000000..5ef5374af
--- /dev/null
+++ b/hack/lib/lint.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+###
+#Copyright 2020 The KubeEdge Authors.
+#
+#Licensed under the Apache License, Version 2.0 (the "License");
+#you may not use this file except in compliance with the License.
+#You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing, software
+#distributed under the License is distributed on an "AS IS" BASIS,
+#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#See the License for the specific language governing permissions and
+#limitations under the License.
+###
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+kubeedge::lint::cloud_lint() {
+ (
+ echo "lint cloud"
+ cd ${KUBEEDGE_ROOT}/cloud
+ golangci-lint run --skip-dirs 'pkg/client' --disable-all -E gofmt -E golint --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::edge_lint() {
+ (
+ echo "lint edge"
+ cd ${KUBEEDGE_ROOT}/edge
+ golangci-lint run --disable-all -E gofmt -E golint -E misspell --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::keadm_lint() {
+ (
+ echo "lint keadm"
+ cd ${KUBEEDGE_ROOT}/keadm
+ golangci-lint run --deadline '10m' --disable-all -E golint ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::bluetoothdevice_lint() {
+ (
+ echo "lint bluetoothdevice"
+ cd ${KUBEEDGE_ROOT}/mappers/bluetooth_mapper
+ golangci-lint run --disable-all -E golint --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+ALL_COMPONENTS_AND_LINT_FUNCTIONS=(
+ cloud::::kubeedge::lint::cloud_lint
+ edge::::kubeedge::lint::edge_lint
+ keadm::::kubeedge::lint::keadm_lint
+ bluetoothdevice::::kubeedge::lint::bluetoothdevice_lint
+)
+
+kubeedge::lint::get_lintfuntion_by_component() {
+ local key=$1
+ for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
+ local component="${cl%%::::*}"
+ if [ "${component}" == "${key}" ]; then
+ local func="${cl##*::::}"
+ echo "${func}"
+ return
+ fi
+ done
+ echo "can not find component: $key"
+ exit 1
+}
+
+kubeedge::lint::get_all_lintfuntion() {
+ local -a funcs
+ for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
+ funcs+=("${cl##*::::}")
+ done
+ echo ${funcs[@]}
+}
+
+IFS=" " read -ra ALL_LINT_FUNCTIONS <<< "$(kubeedge::lint::get_all_lintfuntion)"
+
+kubeedge::lint::check() {
+ echo "checking golang lint $@"
+
+ cd ${KUBEEDGE_ROOT}
+
+ local -a funcs=()
+ local arg
+ for arg in "$@"; do
+ funcs+=("$(kubeedge::lint::get_lintfuntion_by_component $arg)")
+ done
+
+ if [[ ${#funcs[@]} -eq 0 ]]; then
+ funcs+=("${ALL_LINT_FUNCTIONS[@]}")
+ fi
+
+ for f in ${funcs[@]}; do
+ $f
+ done
+}