Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ShellCheck testing #34

Open
oxr463 opened this issue Jul 17, 2020 · 5 comments
Open

Implement ShellCheck testing #34

oxr463 opened this issue Jul 17, 2020 · 5 comments

Comments

@oxr463
Copy link

oxr463 commented Jul 17, 2020

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
Copy link

"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
Copy link
Member

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
Copy link

emiliovesprini commented Jul 17, 2020

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
Copy link
Author

oxr463 commented Oct 2, 2020

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

@TooTallNate
Copy link
Member

👍 for disabling SC2039.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants