github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/hack/lib/lint.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  ###
     4  #Copyright 2020 The KubeEdge Authors.
     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  
    19  set -o errexit
    20  set -o nounset
    21  set -o pipefail
    22  
    23  kubeedge::lint::cloud_lint() {
    24    (
    25      echo "lint cloud"
    26      cd ${KUBEEDGE_ROOT}/cloud
    27      golangci-lint run --skip-dirs 'pkg/client' --disable-all -E gofmt -E golint --deadline '10m' ./...
    28      go vet ./... 
    29    )
    30  }
    31  
    32  kubeedge::lint::edge_lint() {
    33    (
    34      echo "lint edge"
    35      cd ${KUBEEDGE_ROOT}/edge
    36      golangci-lint run --disable-all -E gofmt -E golint -E misspell --deadline '10m' ./...
    37      go vet ./...
    38    )
    39  }
    40  
    41  kubeedge::lint::keadm_lint() {
    42    (
    43      echo "lint keadm"
    44      cd ${KUBEEDGE_ROOT}/keadm
    45      golangci-lint run --deadline '10m' --disable-all -E golint ./...
    46      go vet ./...
    47    )
    48  }
    49  
    50  kubeedge::lint::bluetoothdevice_lint() {
    51    (
    52      echo "lint bluetoothdevice"
    53      cd ${KUBEEDGE_ROOT}/mappers/bluetooth_mapper
    54      golangci-lint run --disable-all -E golint --deadline '10m' ./...
    55      go vet ./...
    56    )
    57  }
    58  
    59  ALL_COMPONENTS_AND_LINT_FUNCTIONS=(
    60    cloud::::kubeedge::lint::cloud_lint
    61    edge::::kubeedge::lint::edge_lint
    62    keadm::::kubeedge::lint::keadm_lint
    63    bluetoothdevice::::kubeedge::lint::bluetoothdevice_lint
    64  )
    65  
    66  kubeedge::lint::get_lintfuntion_by_component() {
    67    local key=$1
    68    for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
    69      local component="${cl%%::::*}"
    70      if [ "${component}" == "${key}" ]; then
    71        local func="${cl##*::::}"
    72        echo "${func}"
    73        return
    74      fi
    75    done
    76    echo "can not find component: $key"
    77    exit 1
    78  }
    79  
    80  kubeedge::lint::get_all_lintfuntion() {
    81    local -a funcs 
    82    for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
    83      funcs+=("${cl##*::::}")
    84    done
    85    echo ${funcs[@]}
    86  }
    87  
    88  IFS=" " read -ra ALL_LINT_FUNCTIONS <<< "$(kubeedge::lint::get_all_lintfuntion)"
    89  
    90  kubeedge::lint::check() {
    91    echo "checking golang lint $@"
    92  
    93    cd ${KUBEEDGE_ROOT}
    94  
    95    local -a funcs=()
    96    local arg
    97    for arg in "$@"; do
    98      funcs+=("$(kubeedge::lint::get_lintfuntion_by_component $arg)")
    99    done
   100  
   101    if [[ ${#funcs[@]} -eq 0 ]]; then
   102      funcs+=("${ALL_LINT_FUNCTIONS[@]}")
   103    fi
   104  
   105    for f in ${funcs[@]}; do
   106      $f
   107    done
   108  }