Skip to content

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

@Frederick888

Description

@Frederick888

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions