importpw / import

`import` is a simple and fast module system for Bash and other Unix shells
https://import.sh
MIT License
338 stars 10 forks source link

Implement ShellCheck testing #34

Open oxr463 opened 3 years ago

oxr463 commented 3 years ago
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

emiliovesprini commented 3 years ago

"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.

TooTallNate commented 3 years ago

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!

emiliovesprini commented 3 years ago

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.

oxr463 commented 3 years ago

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

TooTallNate commented 3 years ago

👍 for disabling SC2039.