mbucc / shmig

Database migration tool written in BASH.
BSD 3-Clause "New" or "Revised" License
458 stars 49 forks source link

shellcheck #34

Closed mbucc closed 5 years ago

mbucc commented 6 years ago

https://github.com/koalaman/shellcheck

mbucc commented 6 years ago

Output of pasting 7fa1172bd36937b55641be72c721f5586090a6a5 into https://www.shellcheck.net is below.

For details on issue reported (for example, SC2006), see https://github.com/koalaman/shellcheck/wiki/SC2006.

Line 16:
MYSQL=`which mysql`
      ^-- SC2006: Use $(..) instead of legacy `..`.

Line 17:
PSQL=`which psql`
     ^-- SC2006: Use $(..) instead of legacy `..`.

Line 18:
SQLITE3=`which sqlite3`
        ^-- SC2006: Use $(..) instead of legacy `..`.

Line 50:
  echo -e "$ME: $@" >&2
                ^-- SC2145: Argument mixes string and array. Use * or separate argument.

Line 68:
  printf "%s\n" "$VERSION"
            ^-- SC1117: Backslash is literal in "\n". Prefer explicit escaping: "\\n".

Line 170:
  if [ $? -ne 0 ]
       ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Line 224:
    "$MYSQL" $args <<< $*
             ^-- SC2086: Double quote to prevent globbing and word splitting.
                       ^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems.
                       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 226:
    "$MYSQL" $args
             ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 253:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 262:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 284:
    "$PSQL" $args -c "$*"
            ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 286:
    "$PSQL" $args
            ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 314:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 323:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 339:
    "$SQLITE3" $args <<< $*
               ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems.
                         ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 341:
    "$SQLITE3" $args
               ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 369:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 378:
cat >> $1 << EOF
       ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 424:
  local since="^-- $(sed_quote "$2")\$"
        ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 425:
  local till="^-- $(sed_quote "$3")\$"
        ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 453:
    | grep -q "\-$name\.sql" \
               ^-- SC1117: Backslash is literal in "\-". Prefer explicit escaping: "\\-".
                      ^-- SC1117: Backslash is literal in "\.". Prefer explicit escaping: "\\.".

Line 456:
  local fname="$MIGRATIONS/$(date +%s)-$(echo "$name" | tr \  _).sql"
        ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 465:
${TYPE}_up_text $fname
^-- SC2086: Double quote to prevent globbing and word splitting.
                ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 473:
${TYPE}_down_text $fname
^-- SC2086: Double quote to prevent globbing and word splitting.
                  ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 484:
pending_migrations(){
^-- SC2120: pending_migrations references arguments, but none are ever passed.

Line 485:
  local last=$("${TYPE}_previous_versions" 1)
        ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 504:
  while read version
        ^-- SC2162: read without -r will mangle backslashes.

Line 506:
    local migration=$(find_migrations -name "$version-*.sql")
          ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 511:
  [[ $? -ne 0 ]] && exit 1
     ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Line 519:
  pending_migrations | while read fname
  ^-- SC2119: Use pending_migrations "$@" if function's $1 should mean script's $1.
                             ^-- SC2162: read without -r will mangle backslashes.

Line 577:
  while read fname
        ^-- SC2162: read without -r will mangle backslashes.

Line 579:
    local version=$(migration_version "$fname")
          ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 580:
    local name=$(migration_name "$fname")
          ^-- SC2155: Declare and assign separately to avoid masking return values.

Line 593:
      echo -en "$ME: $message '${LMAGENTA}${name}${CLEAR}'\t(${LBLUE}$version${LBLUE}${CLEAR})... " >&2
                                                          ^-- SC1117: Backslash is literal in "\t". Prefer explicit escaping: "\\t".

Line 595:
      migration_section "$fname" "$since" "$till" || die "\n  ${LRED}migration in '${LYELLOW}$fname${LRED}' contains no section ${CYAN}$sname${CLEAR}"
                                                          ^-- SC1117: Backslash is literal in "\n". Prefer explicit escaping: "\\n".

Line 602:
  done < <("$src" $steps)
                  ^-- SC2086: Double quote to prevent globbing and word splitting.

Line 641:
shift $(($OPTIND - 1))
         ^-- SC2004: $/${} is unnecessary on arithmetic variables.

Line 649:
  source "$CONFIG"
  ^-- SC1090: Can't follow non-constant source. Use a directive to specify location.

Line 659:
[[ $ASK_PASSWORD -eq 1 ]] && read -s -p "Password: " _PASSWORD
                             ^-- SC2162: read without -r will mangle backslashes.

Line 694:
  RED="\e[31m"
       ^-- SC1117: Backslash is literal in "\e". Prefer explicit escaping: "\\e".

[ ... delete rest of SC1117 entries ...]