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

[SC2120] False positive when a function is called by trap with arguments #3052

Open
2 of 4 tasks
Frederick888 opened this issue Sep 3, 2024 · 2 comments
Open
2 of 4 tasks

Comments

@Frederick888
Copy link

Frederick888 commented Sep 3, 2024

For bugs

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/usr/bin/env bash

clean_up() {
        local code=$?
        printf 'Cleaning up!\n'
        if [[ -n "$1" ]]; then
                printf 'Invoked due to error %d on line %d\n' "$code" "$1"
                exit "$code"
        fi
        exit 0
}

trap 'clean_up $LINENO' ERR SIGINT SIGTERM SIGQUIT

if [[ -z "$INPUT" ]]; then
        printf 'Missing input!\n'
        clean_up
fi

# do something

Here's what shellcheck currently says:

Line 3:
clean_up() {
^-- SC2120 (warning): clean_up references arguments, but none are ever passed.
 
Line 17:
        clean_up
        ^-- SC2119 (info): Use clean_up "$@" if function's $1 should mean script's $1.

Here's what I wanted or expected to see:

No SC2120 error as trap 'clean_up $LINENO' ERR SIGINT SIGTERM SIGQUIT can call clean_up with an argument.

@Frederick888 Frederick888 changed the title [SC2119, SC2120] False positive when a function is called by trap with arguments [SC2120] False positive when a function is called by trap with arguments Sep 3, 2024
@wileyhy
Copy link

wileyhy commented Sep 13, 2024 via email

@Frederick888
Copy link
Author

@wileyhy No, in my example clean_up is something that can be called directly when an expected/handled issue arises to clean up and exit, or called when an unexpected error / interruption happens (during # do something). I did not want to trigger the trap from within if-fi.

Anyway, I fail to see how that's related to this issue report. clean_up can be called with an argument nevertheless.

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

2 participants