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

Suggestion: warn if sourcing a file without checking if it exists. #1068

Open
2 tasks done
nihilus opened this issue Dec 5, 2017 · 3 comments
Open
2 tasks done

Suggestion: warn if sourcing a file without checking if it exists. #1068

nihilus opened this issue Dec 5, 2017 · 3 comments

Comments

@nihilus
Copy link

nihilus commented Dec 5, 2017

For new checks and feature suggestions

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

#!/bin/sh
source foo/bar.script

Here's what shellcheck currently says:

Nothing

Here's what I wanted or expected to see:

Warning: sourcing without check if file exists, please use: [ -e foo/bar.script ] && source foo/bar.script

@harleypig
Copy link

Wouldn't [ -r foo/bar.script ] && source foo/bar.script be a better way to do this?

@pawamoy
Copy link

pawamoy commented Dec 22, 2017

It might be complicated to implement since the check could be many lines above, and the script path could be in a variable, etc.

@kurahaupo
Copy link

The recommended "fix" in the suggested warning message is bad from a correctness perspective.

If the other file is installed as part of the same package (or a prerequisite package) as the main file, such a suggestion would be misleading and worse than useless. In those cases, if the file is missing, it's a fatal error, not something that should be ignored.

If this were to be implemented, the default recommendation should be to abort with a fatal error if the other file is missing. The script writer can then decide whether it's appropriate for their case.

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

4 participants