Skip to content

Commit

Permalink
Update shellcheck version
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed May 3, 2022
1 parent c3e6e0d commit b8935ec
Show file tree
Hide file tree
Showing 103 changed files with 159 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .shellcheck-version
@@ -1 +1 @@
v0.7.1
v0.8.0
1 change: 1 addition & 0 deletions examples/spec/17.putsn_puts_directive_spec.sh
Expand Up @@ -10,6 +10,7 @@ End

Describe '%= directive'
Example 'is alias for %putsn'
# shellcheck disable=SC2276
foo() { %= value; }
When call foo
The entire output should eq "value${SHELLSPEC_LF}"
Expand Down
1 change: 1 addition & 0 deletions examples/spec/18.const_directive_spec.sh
@@ -1,6 +1,7 @@
#shellcheck shell=sh

%const NAME: value
# shellcheck disable=SC2288
% MAJOR_VERSION: "${SHELLSPEC_VERSION%%.*}"
# % OK: "$(echo_ok)" # echo_ok not found

Expand Down
10 changes: 5 additions & 5 deletions examples/spec/22.sourcced_spec.sh
Expand Up @@ -22,11 +22,11 @@ Describe 'sourced return example'
Example 'test cpunum.sh with stubbed cat /cpu/info'
Data data
data() {
%= "line1"
%= "line2"
%= "line3"
%= "line4"
%- "line5 (without newline)"
%putsn "line1"
%putsn "line2"
%putsn "line3"
%putsn "line4"
%puts "line5 (without newline)"
}

When call count_lines
Expand Down
7 changes: 6 additions & 1 deletion helper/spec_helper.sh
Expand Up @@ -7,6 +7,8 @@ spec_helper_precheck() {
minimum_version "$SHELLSPEC_VERSION"

if [ "${PIPEFAIL:-}" ]; then
# TODO: set -o pipefail will be allowed in POSIX issue 8
# shellcheck disable=SC3040
if ( set -o pipefail ) 2>/dev/null; then
info "pipefail enabled"
else
Expand All @@ -16,6 +18,7 @@ spec_helper_precheck() {
fi

if [ "${EXTGLOB:-}" ]; then
# shellcheck disable=SC3044
if shopt -s extglob 2>/dev/null; then
info "extglob enabled"
setenv EXTGLOB="extglob"
Expand All @@ -34,14 +37,16 @@ spec_helper_precheck() {
fi
}

# shellcheck disable=SC2039
spec_helper_loaded() {
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# shellcheck disable=SC2153
IFS="${SHELLSPEC_LF}${SHELLSPEC_TAB}"

# shellcheck disable=SC3040
[ "${PIPEFAIL:-}" ] && set -o pipefail
unset PIPEFAIL ||:

# shellcheck disable=SC3044
case ${EXTGLOB:-} in
extglob) shopt -s extglob ;;
extendedglob) setopt extendedglob ;;
Expand Down
3 changes: 2 additions & 1 deletion install.sh
Expand Up @@ -113,6 +113,7 @@ components_path() {

git_remote_tags() {
git ls-remote --tags "$repo" | while read -r line; do
# shellcheck disable=SC2295
tag=${line##*/} && pre=${tag#${tag%%[-+]*}}
[ "${1:-}" = "--pre" ] || case $pre in (-*) continue; esac
echo "${tag%\^\{\}}"
Expand All @@ -130,7 +131,7 @@ sort_by_first_key() {

version_sort() {
while read -r version; do
ver=${version%%+*} && num=${ver%%-*} && pre=${ver#$num}
ver=${version%%+*} && num=${ver%%-*} && pre=${ver#"$num"}
#shellcheck disable=SC2086
case $num in
*[!0-9.]*) set -- 0 0 0 0 ;;
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap.sh
Expand Up @@ -3,7 +3,7 @@
shellspec() { echo '#'; }

# Disable verbose_errexit by default for osh
# shellcheck disable=SC2039
# shellcheck disable=SC3044
shopt -u verbose_errexit 2>/dev/null ||:

# shellcheck source=lib/general.sh
Expand Down
1 change: 1 addition & 0 deletions lib/core/evaluation.sh
Expand Up @@ -255,6 +255,7 @@ shellspec_interceptor() {
done
shift 2
case $SHELLSPEC_INTERCEPTOR in (*\|$1:*)
# shellcheck disable=SC2295
eval "shift; set -- \"${SHELLSPEC_INTERCEPTOR##*\|$1:}\" ${2:+\"\$@\"}"
eval "shift; set -- \"${1%%\|*}\" ${2:+\"\$@\"}"
"$@"
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils.sh
Expand Up @@ -55,7 +55,7 @@ shellspec_set_option() {
}

shellspec_shopt() {
#shellcheck disable=SC2039
#shellcheck disable=SC3044
case $1 in
-o) shopt -s "$2" 2>/dev/null || set -o "$2" ;;
+o) shopt -u "$2" 2>/dev/null || set +o "$2" ;;
Expand Down
22 changes: 15 additions & 7 deletions lib/general.sh
Expand Up @@ -96,6 +96,7 @@ shellspec_resolve_module_path() {
shellspec_find_module "$SHELLSPEC_LOAD_PATH" "$2" "$1"
}

# shellcheck disable=SC2295
shellspec_module_exists() {
set -- "$1" "${2:-$SHELLSPEC_LOAD_PATH}"
[ -e "${2%%$SHELLSPEC_PATHSEP*}/$1.sh" ] && return 0
Expand All @@ -107,6 +108,7 @@ shellspec_module_exists() {
return 1
}

# shellcheck disable=SC2295
shellspec_find_module() {
if [ -e "${1%%$SHELLSPEC_PATHSEP*}/$2.sh" ]; then
eval "$3=\${1%%\$SHELLSPEC_PATHSEP*}/\$2.sh"
Expand Down Expand Up @@ -275,6 +277,7 @@ shellspec_loop() {
shellspec_loop "$1" $(($2 - 1))
}

# shellcheck disable=SC2295
shellspec_get_line() {
[ "$2" -le 0 ] && set -- "$1" "$2" ""
while [ "$2" -gt 1 ]; do
Expand All @@ -287,6 +290,7 @@ shellspec_get_line() {
unset "$1" ||:
}

# shellcheck disable=SC2295
shellspec_count_lines() {
set -- "$1" "$2" 0
while [ "$2" ]; do
Expand All @@ -309,6 +313,7 @@ shellspec_padding_() {
shellspec_padding_ "$1" "$2" $(($3 - 1))
}

# shellcheck disable=SC2295
shellspec_wrap() {
[ ! "$2" ] && eval "$1=" && return 0
case $2 in
Expand Down Expand Up @@ -348,7 +353,7 @@ else
shellspec_readfile() { shellspec_readfile_posix "$@"; }
fi

# shellcheck disable=SC2039
# shellcheck disable=SC3043,SC3044
shellspec_readfile_bash_readarray() {
[ -e "$2" ] || { unset "$1" ||:; return 0; }
[ -s "$2" ] || { eval "$1=''"; return 0; }
Expand All @@ -369,14 +374,14 @@ shellspec_readfile_ksh_readall() {
return 0
}

# shellcheck disable=SC2039
# shellcheck disable=SC3045
shellspec_readfile_read_delim() {
[ -e "$2" ] || { unset "$1" ||:; return 0; }
[ -s "$2" ] || { eval "$1=''"; return 0; }
IFS= read -r -d "" "$1" < "$2" ||:
}

# shellcheck disable=SC2039
# shellcheck disable=SC3044
shellspec_readfile_yash_array() {
[ -e "$2" ] || { unset "$1" ||:; return 0; }
[ -s "$2" ] || { eval "$1=''"; return 0; }
Expand All @@ -395,19 +400,21 @@ shellspec_readfile_zsh_mapfile() {
eval "$1=\"\${mapfile[\$2]}\""
}

# shellcheck disable=SC2039
shellspec_readfile_zsh_concat() {
[ -e "$2" ] || { unset "$1" ||:; return 0; }
[ -s "$2" ] || { eval "$1=''"; return 0; }
# shellcheck disable=SC3043
local shellspec_readfile_line='' shellspec_readfile_data=''
while IFS= read -r shellspec_readfile_line; do
# shellcheck disable=SC3024
shellspec_readfile_data+="${shellspec_readfile_line}${SHELLSPEC_LF}"
done < "$2"
# shellcheck disable=SC3024
shellspec_readfile_data+="$shellspec_readfile_line"
eval "$1=\"\$shellspec_readfile_data\""
}

# shellcheck disable=SC2039
# shellcheck disable=SC3043
shellspec_readfile_zsh_array() {
[ -e "$2" ] || { unset "$1" ||:; return 0; }
[ -s "$2" ] || { eval "$1=''"; return 0; }
Expand Down Expand Up @@ -758,6 +765,7 @@ else
}
fi

# shellcheck disable=SC2295
shellspec_which() {
set -- "$1" "${PATH%$SHELLSPEC_PATHSEP}${SHELLSPEC_PATHSEP}"
while [ "${2%$SHELLSPEC_PATHSEP}" ]; do
Expand All @@ -784,7 +792,7 @@ shellspec_is_empty_directory() {

# workaround for posh 0.10.2: glob does not expand when set -u
set +o noglob +u
# shellcheck disable=SC2039
# shellcheck disable=SC3044
[ "${SHELLSPEC_FAILGLOB_AVAILABLE:-}" ] && shopt -u failglob
[ "${SHELLSPEC_NOMATCH_AVAILABLE:-}" ] && setopt NO_NOMATCH

Expand Down Expand Up @@ -819,7 +827,7 @@ shellspec_unsetf() {
return 0
fi
if [ "$SHELLSPEC_BUILTIN_TYPESETF" ]; then
# shellcheck disable=SC2039
# shellcheck disable=SC3044
typeset -f "$1" >/dev/null 2>&1 || return 0
elif [ "${POSH_VERSION:-}" ]; then
( unset -f "$1" 2>/dev/null ) || return 0
Expand Down
2 changes: 1 addition & 1 deletion lib/libexec/optparser/parser_definition_generated.sh
Expand Up @@ -19,7 +19,7 @@ export SHELLSPEC_ERROR_EXIT_CODE='102'
export SHELLSPEC_PROFILER=''
export SHELLSPEC_PROFILER_LIMIT='10'
export SHELLSPEC_LOGFILE='/dev/tty'
export SHELLSPEC_TMPDIR=${TMPDIR:-${TMP:-/tmp}}
export SHELLSPEC_TMPDIR="${TMPDIR:-${TMP:-/tmp}}"
export SHELLSPEC_KEEP_TMPDIR=''
export SHELLSPEC_QUICK=''
export SHELLSPEC_WORKERS='0'
Expand Down
2 changes: 2 additions & 0 deletions lib/libexec/reporter.sh
Expand Up @@ -15,6 +15,7 @@ count_examples() {
}

# $1: prefix, $2: filename
# shellcheck disable=SC2295
read_time_log() {
eval "$1_real='' $1_user='' $1_sys=''"
[ -r "$2" ] || return 1
Expand Down Expand Up @@ -89,6 +90,7 @@ xmlcdata() {
fi
}

# shellcheck disable=SC2295
remove_escape_sequence() {
while IFS= read -r line || [ "$line" ]; do
text=''
Expand Down
1 change: 1 addition & 0 deletions lib/libexec/reporter/documentation_formatter.sh
Expand Up @@ -7,6 +7,7 @@ create_buffers documentation
require_formatters methods conclusion finished summary references profiler
[ "$SHELLSPEC_KCOV" ] && require_formatters kcov

# shellcheck disable=SC2295
documentation_each() {
_id='' _current_id='' _description='' _indent=''
_last_id=$documentation_last_id
Expand Down
2 changes: 1 addition & 1 deletion lib/libexec/reporter/formatter.sh
Expand Up @@ -15,7 +15,7 @@ load_formatter() {
import_formatter "$1"

# move main formatter to first
#shellcheck disable=SC2086
#shellcheck disable=SC2086,SC2295
set -- "$1" ${formatters%$1*} ${formatters#*$1}
formatters="$*"
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libexec/reporter/junit_formatter.sh
Expand Up @@ -82,7 +82,7 @@ junit_each() {
inc _errors _errors_total
_message="${field_note}${field_note:+: }${field_message}"
_failure=$field_failure_message _address="$field_specfile:$field_lineno"
wrap _failure "${_failure%${LF}}${LF}" " "
wrap _failure "${_failure%"$LF"}${LF}" " "
_system_error="${_system_error}${_message}${LF}${_failure}"
_system_error="${_system_error}# ${_address}${LF}${LF}"
;;
Expand Down
4 changes: 3 additions & 1 deletion lib/libexec/shellspec.sh
Expand Up @@ -115,9 +115,11 @@ current_shell() {
cmdline=$(read_cmdline "/proc/$2/cmdline")
[ "$cmdline" ] || cmdline=$(read_ps "$2")

# shellcheck disable=SC2295
echo "${cmdline%% $self*}"
}

# shellcheck disable=SC2295
command_path() {
if [ $# -lt 2 ]; then
set -- "" "$1" "${PATH}${SHELLSPEC_PATHSEP}"
Expand Down Expand Up @@ -148,7 +150,7 @@ setup_load_path() {
SHELLSPEC_LOAD_PATH="${1}${SHELLSPEC_PATHSEP}${SHELLSPEC_LOAD_PATH}"
shift
done
SHELLSPEC_LOAD_PATH=${SHELLSPEC_LOAD_PATH%$SHELLSPEC_PATHSEP}
SHELLSPEC_LOAD_PATH=${SHELLSPEC_LOAD_PATH%"$SHELLSPEC_PATHSEP"}
}

finddirs() {
Expand Down
2 changes: 1 addition & 1 deletion lib/support-bin.sh
Expand Up @@ -10,7 +10,7 @@ if [ "${SHELLSPEC_PATH_IS_READONLY:-}" ]; then
# shellcheck disable=SC2086
exec $SHELLSPEC_SHELL "$0" "$@"
fi
# shellcheck disable=SC2039
# shellcheck disable=SC3044
typeset +x PATH
exec "$SHELLSPEC_ENV" PATH="$PATH" SHELLSPEC_PATH_IS_READONLY="" "$0" "$@"
fi
Expand Down
2 changes: 1 addition & 1 deletion libexec/shellspec-executor.sh
Expand Up @@ -39,7 +39,7 @@ error_handler() {
detect_unexpected_error "$specfile" "$lineno" "$errors"
errors=''
fi
line=${line#${SYN}shellspec_marker:}
line=${line#"$SYN"shellspec_marker:}
specfile=${line% *} lineno=${line##* }
;;
Syntax\ error:*) putsn "${LF}${line}"; error_handler_status=1 ;;
Expand Down
20 changes: 11 additions & 9 deletions libexec/shellspec-inspection.sh
Expand Up @@ -80,9 +80,8 @@ fi
set -e

SHELLSPEC_CLONE_TYPE="posix"
# shellcheck disable=SC2039
# shellcheck disable=SC3044
if typeset >/dev/null 2>&1; then
# shellcheck disable=SC2034
set -- "$(var=data; typeset -p var 2>/dev/null ||:)" ||:
if [ ! "${1#*data}" = "$1" ]; then
if [ "${BASH_VERSION:-}" ]; then
Expand Down Expand Up @@ -116,16 +115,19 @@ if "${0%/*}/shellspec-shebang" 2>/dev/null; then
fi

set +e
# shellcheck disable=SC2034,SC2039
(
# shellcheck disable=SC3045
ulimit -t unlimited || exit 1

# shellcheck disable=SC3047
trap '' DEBUG || exit 1
echo "SHELLSPEC_DEBUG_TRAP=1"
echo "SHELLSPEC_KCOV_COMPATIBLE_SHELL=1"

# Workaround for ksh93u+ and ksh2020 (fixed in ksh93u+m)
# shellcheck disable=SC3047
trap ':' DEBUG
# shellcheck disable=SC2034
r=$(exit 123)
if [ $? -ne 123 ]; then
echo "SHELLSPEC_DEFECT_DEBUGXS=1"
Expand Down Expand Up @@ -161,14 +163,14 @@ if print -nr -- '' 2>/dev/null; then
fi

typesetf_check() { :; }
# shellcheck disable=SC2034,SC2039
# shellcheck disable=SC3044
if typeset -f typesetf_check >/dev/null 2>&1; then
echo "SHELLSPEC_BUILTIN_TYPESETF=1"
fi

if type shopt >/dev/null 2>&1; then
echo "SHELLSPEC_SHOPT_AVAILABLE=1"
# shellcheck disable=SC2039
# shellcheck disable=SC3044
if shopt -s failglob 2>/dev/null; then
echo "SHELLSPEC_FAILGLOB_AVAILABLE=1"
fi
Expand All @@ -178,18 +180,18 @@ if setopt NO_NOMATCH >/dev/null 2>&1; then
echo "SHELLSPEC_NOMATCH_AVAILABLE=1"
fi

#shellcheck disable=SC2034,SC2039
# shellcheck disable=SC2034,SC3022
if ( exec {fd}>/dev/null ) 2>/dev/null; then
echo "SHELLSPEC_FDVAR_AVAILABLE=1"
fi

# shellcheck disable=SC2039
# shellcheck disable=SC3044
if readarray </dev/null 2>/dev/null; then
echo "SHELLSPEC_BUILTIN_READARRAY=1"
fi

string=''
# shellcheck disable=SC2039
# shellcheck disable=SC3024
if string+="concat" 2>/dev/null; then
echo "SHELLSPEC_STRING_CONCAT=1"
fi
Expand All @@ -199,7 +201,7 @@ if ( eval '{ : <#((0)); } <<<:' ) 2>/dev/null; then
fi

line=''
# shellcheck disable=SC2039
# shellcheck disable=SC3045
read -r -d "" line <<'HERE' 2>/dev/null ||:
a\b
HERE
Expand Down

0 comments on commit b8935ec

Please sign in to comment.