github.com/osrg/gobgp/v3@v3.30.0/tools/spell-check/scspell.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  SCRIPT_DIR=`dirname $0`
     4  GOBGP=${SCRIPT_DIR}/../../
     5  
     6  FUNCS=(
     7  Debug
     8  Debugf
     9  Debugln
    10  Error
    11  Errorf
    12  Errorln
    13  Fatal
    14  Fatalf
    15  Fatalln
    16  Fprint
    17  Fprintf
    18  Fprintln
    19  Info
    20  Infof
    21  Infoln
    22  Panic
    23  Panicf
    24  Panicln
    25  Print
    26  Printf
    27  Println
    28  Sprint
    29  Sprintf
    30  Sprintln
    31  Warn
    32  Warnf
    33  Warning
    34  Warningf
    35  Warningln
    36  Warnln
    37  )
    38  
    39  CHECK_LOG=/tmp/gobgp/scspell.log
    40  mkdir -p `dirname ${CHECK_LOG}`
    41  rm -f ${CHECK_LOG}  # Clean up previous output
    42  
    43  # Do find *.go files except under vendor directory
    44  for FILE in `find ${GOBGP} -type d -name vendor -prune -o -type f -name *.go | sort`
    45  do
    46      TMP_FILE=${FILE/${GOBGP}//tmp/gobgp/}
    47      mkdir -p `dirname ${TMP_FILE}`
    48      rm -f ${TMP_FILE}  # Clean up previous output
    49  
    50      for FUNC in ${FUNCS[@]}
    51      do
    52          # Do grep cases like:
    53          #   fmt.Print("...")
    54          # or
    55          #   fmt.Print(
    56          #       "...")
    57          grep ${FUNC}'("'      ${FILE} | grep -o '".*"' >> ${TMP_FILE}
    58          grep ${FUNC}'($' -A 1 ${FILE} | grep -o '".*"' >> ${TMP_FILE}
    59      done
    60  
    61      # If any case found
    62      if [ -s ${TMP_FILE} ]
    63      then
    64          # Apply exclude rules defined in ignore.txt
    65          for WORD in `grep -v -e '^\s*#' -e '^$' ${SCRIPT_DIR}/ignore.txt`
    66          do
    67              sed -i "s/${WORD}//g" ${TMP_FILE}
    68          done
    69  
    70          # Do scspell with dictionary.txt and reformat messages
    71          scspell \
    72              --use-builtin-base-dict \
    73              --override-dictionary ${SCRIPT_DIR}/dictionary.txt \
    74              --report-only \
    75              ${TMP_FILE} 2>&1 \
    76           | tee -a ${CHECK_LOG} \
    77           | sed "s/\/tmp\/gobgp\///" | cut -d ':' -f -1,3-
    78      fi
    79  
    80      #rm ${TMP_FILE}
    81  done
    82  
    83  RESULT=0
    84  
    85  # If any output of scspell exists
    86  if [ -s ${CHECK_LOG} ]
    87  then
    88      echo "---"
    89      echo "See ${CHECK_LOG} for more details."
    90      # Set return code as error
    91      RESULT=1
    92  fi
    93  
    94  #rm -f ${CHECK_LOG}
    95  exit ${RESULT}
    96