import icon indicating copy to clipboard operation
import copied to clipboard

Implement ShellCheck testing

Open oxr463 opened this issue 4 years ago • 5 comments

shellcheck import.sh
 
Line 27:
        local location="$1"
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 28:
        local headers="$2"
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 29:
        local location_header=""
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 45:
        local url="$*"
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 46:
        local url_path=""
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 65:
        local cache="${IMPORT_CACHE-${HOME}/.import-cache}"
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 74:
        local cache_path="$cache/links/$url_path"
        ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 78:
                local dir
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 81:
                local link_dir="$cache/links/$dir"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 91:
                local location=""
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 92:
                local tmpfile="$cache_path.tmp"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 93:
                local tmpheader="$cache_path.header"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 94:
                local locfile="$cache/locations/$url_path"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 95:
                local qs="?"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 99:
                local url_with_qs="${url}${qs}format=raw"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 104:
                        ${IMPORT_CURL_OPTS-} \
                        ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
                        "${IMPORT_CURL_OPTS-}" \
 
Line 106:
                                local r=$?
                                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 119:
                local hash
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 123:
                local hash_file="$cache/data/$hash"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 134:
                local relative
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 135:
                local cache_start
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 136:
                cache_start="$(expr "${#cache}" + 1)" || return
                               ^-- SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].
 
Line 137:
                relative="$(echo "$link_dir" | awk '{print substr($0,'$cache_start')}' | sed 's/\/[^/]*/..\//g')data/$hash" || return
>>                                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
                relative="$(echo "$link_dir" | awk '{print substr($0,'"$cache_start"')}' | sed 's/\/[^/]*/..\//g')data/$hash" || return
 
Line 155:
                local __import_parent_location="${__import_location-}"
                ^-- SC2039: In POSIX sh, 'local' is undefined.
 
Line 157:
                . "$cache_path" || return
                  ^-- SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location.
 
Line 195:
                . "$__import_entrypoint"
                  ^-- SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location.

See also: https://github.com/marketplace/actions/shellcheck-action

oxr463 avatar Jul 17 '20 13:07 oxr463

"POSIX-Compliant Way to Scope Variables to a Function in a Shell Script" on Stack Overflow features some options to get rid of all those ^-- SC2039: In POSIX sh, 'local' is undefined. errors.

emiliovesprini avatar Jul 17 '20 19:07 emiliovesprini

Ya, this would be good to set up. Most of them should be ignored I think (local works on all the shells I'm interested in supporting, for example). Thanks for the suggestion!

TooTallNate avatar Jul 17 '20 20:07 TooTallNate

Oh wait. So a narrowly compliant POSIX sh implementation just ignores the locals? Then it might be actually desirable to just leave them there. The thing is variable scoping would differ between shells, but turning every function body into a subshell sounds like it would have side effects.

emiliovesprini avatar Jul 17 '20 20:07 emiliovesprini

If we want to leave the local's in there, we can just create a shellcheck directive to disable SC2039...

oxr463 avatar Oct 02 '20 15:10 oxr463

👍 for disabling SC2039.

TooTallNate avatar Oct 02 '20 19:10 TooTallNate