-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
SC1090/SC1091: sourcing should find files relative to script #769
Comments
I think generally speaking this is a bad idea which is perhaps why
shellcheck requires you to be explicit about it.
http://mywiki.wooledge.org/BashFAQ/028
|
I know that |
|
@koalaman I can see the argument that the behaviour as it stands could be useful in some edge cases, but generally I would expect that "resolve relative As it currently works (where shellcheck resolves relative I'd claim (at least in my work environment) that this scenario is actually far more common than the environment wherein using the current working directory makes more sense. For us, it is rather unequivocal that the script's parent directory would be a far, far better default. At the least, I'd like to see a command-line argument to switch behaviours, but I really think that serious thought should be given to making relative links resolve from the script's parent directory, rather than from the current working directory that |
If directive I agree with @rbroemeling and @petersohn currently |
I'm also interested in getting the relative sources to resolve.
If you're worried about existing scripts, you could always make both options explicit. For example:
|
Actually 'proot' solved my problems enabling me to chroot to the target directory without modifying it and invoke shellcheck as if it was part of the target directory. |
In a CI/CD pipeline this isn't an issue, since I control which directory shellcheck is executed from. The issue I have is when using a shellcheck in an IDE. It would be useful to have an argument I can pass to shellcheck to indicate the root path it should use to resolve the directives. |
This seems to be a duplicate of #539 — Maybe we should move everything into one place (and possible edit the subject to be easier to find). |
@koalaman Wiki for https://github.com/koalaman/shellcheck/wiki/SC1090 is confusing: The path there looks relative. However, if I have 2 files in the same directory (and I get SC1090 on one of them) I cannot write "Who is right", "is there any fix coming", "any status update"? ( |
The path is relative, and it's relative to shellcheck's current working directory. It is not relative to the file in which you put this directive. |
This presents a problem if i.e. I want to run shellcheck as part of the unit tests, from the top of the project. If I then want to run shellcheck individually while editing a file, the path may be incorrect. Maybe two (or more) parts could be provided, to account for that? |
This really needs to be fixed, makes it a pain to run shellcheck as part of builds, etc, as paths wrt where shellcheck is run can change. |
Specifying the path relative to where shellcheck is running from is only realistic for a single user/system. Using |
Just because it's hard doesn't mean it can't be improved. The path isn't relative to shellcheck, but rather the current working directory. Allowing relative paths and/or multiple paths would help for automated builds among other cases. |
We also have big problems with source-directive being relative cwd and not script location.
That would remove the need for source-directive completely because the only time when we actually need source-directive in the first place is in such scenarios. It might be runtime code but the pattern is easily identifiable so a small set of special cases could be defined to resolve script directory. Shellcheck could recommend one of them and make sure that source-following works with it. Or shellcheck could bundle a companion-library with built in functions for this. |
With 301705e you can specify It would also be simple to make this the default, if that would make things even easier |
I recently added shellcheck to my workflow within VS Code (via this extension). As such, shellcheck is called per file. Very helpful in IDE, I tend to jump between several languages/syntax in any given day - Thank you. In my limited view, I'm thinking
My particular instance of SC1090 is (where
It would be nice if could handle case of |
Agreed, |
this is not useful for using shellcheck inside editors. for example vim and syntastic .. Please make the current-script-relative source the default one |
@drAlberT You can add this line to your .vimrc to pass options to shellcheck w/ syntastic:
|
My use case is to have relative scripts, not a global wide SCRIPTDIR .. I made a number of different combination of dirs in .vimrc but no luck Have you any suggestion to add the current SCRIPT dir as SCRIPTDIR on a per file basis ? |
I totally did not understand that I thought |
@docwhat yeah I thought the same thing until I read your comment.
|
-P SCRIPTDIR is due to: koalaman/shellcheck#769
This way matches behavior for shellcheck extension in Visual Studio Code so linting works in the editor correctly. koalaman/shellcheck#769
For folks using VSCode and Timon Wong's shellcheck extension, add the following to your user settings:
This is just a quick adaptation of @JoshCooley's Sublime config. |
@jeffomatic - This doesn't seem to work for me. Config:Code (some-script.sh)
IDE: |
Hi @armenr! I think that the |
When using the directive
source=foobar.sh
, then it seems to look up the source relative to the path shellcheck is being run from. For example, I have the following scripts:foo.sh
andfoobar.sh
in the same directory (for examplebar/baz
from the project root).Suppose there is the following line in
foo.sh
:I will get a SC1090 error because shellcheck is unable to resolve the path. I have to do this:
This works, but only if I run the checker from the project root (either by specifying
foo/bar/foobar.sh
as an input file, or with-x
), but not if I run it from anywhere else. There should be a way to tell shellcheck to look for a file relative to the checked file's location, not where shellcheck is run. For example, this way:The text was updated successfully, but these errors were encountered: