Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Relative paths in source directives #117

Closed
beauchar opened this issue Mar 23, 2018 · 4 comments
Closed

Relative paths in source directives #117

beauchar opened this issue Mar 23, 2018 · 4 comments

Comments

@beauchar
Copy link

beauchar commented Mar 23, 2018

I use a shellcheck source directive to give the filename where I have a variable source or . in the shell code.
This along with the -x option to shellcheck should include those files in it's processing.

Ideally I want use a relative path to the file from the project location, but I'm not sure what the current working directory context for shellcheck will be when it is run. I can't make it work with any combination of absolute or relative paths at the moment.

For added complication I am also running on Windows!

Any ideas to get things working much appreciated.

The code I'm having issues with looks like this:

this="$(readlink -f "${BASH_SOURCE[0]}")"
# shellcheck source=src/common_functions.sh
. "${this%/*}/common_functions.sh"

I see something like the following regardless of the path to the file I give in the directive:
Info ShellCheck Not following: src/common_functions.sh: openBinaryFile: does not exist (No such file or directory) [SC1091]

@Arcanemagus
Copy link
Member

It looks like it was originally set in #40 to the directory of the current file. A better choice (which sounds like it should fit your use case) would be to use the project root path, and fall back to the current directory of the file in question, like this.

@tbehling
Copy link
Contributor

Hi there, I wanted to comment here because I am also seeing these inconsistencies in using shellcheck from Atom and on the command line. Because the Atom plugin runs shellcheck relative to the file, I get errors when I run my own shellcheck from the command line or under a CI script when the current directory is the project root.

@Arcanemagus
Copy link
Member

Fixed in #124.

@virgilwashere
Copy link

FYI: Resolved upstream
koalaman/shellcheck#1553 (comment)

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

No branches or pull requests

4 participants