Skip to content

SC2317 false positives on scripts run with source and having return as its last command #3046

Open
@emacalinao

Description

@emacalinao

For bugs

For new checks and feature suggestions

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

main.sh

#!/bin/bash
# shellcheck source=./sourced.sh
source sourced.sh
echo "this comes after 'source sourced.sh'"
echo "the next line"

sourced.sh

return

Here's what shellcheck currently says:

> shellcheck -x main.sh

In main.sh line 4:
echo "this comes after 'source sourced.sh'"
^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

In main.sh line 5:
echo "the next line"
^------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

For more information:
  https://www.shellcheck.net/wiki/SC2317 -- Command appears to be unreachable...

All lines following source ... are reported as unreachable.

Here's what I wanted or expected to see:

The highlighted commands are reachable and should not be flagged.

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