File: lint.sh

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,000 kB
  • sloc: javascript: 160; sh: 70; makefile: 3
file content (88 lines) | stat: -rwxr-xr-x 1,561 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

##
# Colorize output
##
function color() {
  case $1 in
    yellow) echo -e -n "\033[33m"   ;;
    green)  echo -e -n "\033[32m"   ;;
    red)    echo -e -n "\033[0;31m" ;;
  esac
  echo "$2"
  echo -e -n "\033[0m"
}

##
# Print Usage
##
function usage() {
  color yellow "Usage:"
  echo "  $SCRIPT_DIR [OPTIONS]"
  echo ""

  color yellow "Options:"

  color green "  -w, --write"
  echo -e "\tFix found issues (if it's supported by the linter)."

  color green "  --list"
  echo -e "\tList current linters configuration."

  color green "  -h, --help"
  echo -e "\tDisplay this help."

  echo ""
  exit "$1";
}

OPT_CMD="run"
OPT_FLAGS=""
OPT_DIRS="$ROOT_DIR/..."

##
# Parse arguments
##
while [[ $# -gt 0 ]]
do
  case "$1" in
	  -h|--help)
	    usage 0 ;;

    -w|--write)
      OPT_CMD="run"
      OPT_FLAGS+=" --fix" ;;

    --list)
      OPT_DIRS=""
      OPT_CMD="linters" ;;

    -v|--verbose)
      OPT_FLAGS+=" -v" ;;

    *)
      color red "Unkown argument '$1'"
      echo
      usage 1 ;;
  esac
  shift
done

##
# Check golangci-lint command existence
##
if [ ! -x "$(command -v golangci-lint)" ];
then
  echo "golangci-lint is not installed"
  echo "On macOS, you can run: brew install golangci/tap/golangci-lint"
  echo "On other systems, refer to installation instructions: https://github.com/golangci/golangci-lint#install"
  exit 1
fi

##
# Execute golangci-lint command
##
golangci-lint $OPT_CMD $OPT_FLAGS $OPT_DIRS