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

shellcheck via nova-shellcheck does not seem to find sourced (included) shell script files. #10

Open
johnww2-nwxg opened this issue Sep 17, 2024 · 0 comments

Comments

@johnww2-nwxg
Copy link

johnww2-nwxg commented Sep 17, 2024

Nova 11.10, MacOS Sonoma 14.6.1 (23G93)

shellcheck can check sourced files in a shell script if it knows where to find them (which the script writer can assist with shellcheck directives to clarify where the file can be found.)

However, shellcheck needs permission to access such files (can be set with .shellcheckrc directive) and also it needs a relative starting point from which to look for such files.

The relative starting point can be based on the cwd of shellcheck when run, and or via a -P SOURCEPATH parameter passed to shellcheck.

It appears the nova-shellcheck extension reads in the data of a shell script to be analyzed and passes as std input to shellcheck process rather than providing a file path, so shellcheck may not be able to derive the cwd correctly - depending on what Nova thought was the cwd when it loaded the process?

According to the NOVA docs, a process should have a cwd value set by default to the Nova workspace, so I would expect shellcheck to work in the nova-shellcheck context as is, but for me it does not work (for finding sourced/included files.) Shellcheck cannot correctly find the files even with shellcheck directives trying to point the way.

I find that modifying the extension code to add to the process args a -P option with the workspace.path or explicitly providing cwd=workspace.path as a parameter to the process constructor helps shellcheck to find sourced shell script files?

The original process constructor does not pass in a cwd, and notwithstanding Nova documentation (which says it will default to workspace path), if you check the value of process.cwd property after construction, it is "undefined". If you pass in the cwd explicitly to the constructor then the process.cwd property will be set to the value provided to the constructor, and shellcheck will start finding sourced/included shell script files.

here is some quick hack to set the cwd explicitly in the extension code

		var wspath = nova.workspace.path;
		console.info("validating: ", editor.document.uri);
		var documentLength = editor.document.length;
		var content = editor.document.getTextInRange(
			new Range(0, documentLength)
		);
		var process = new Promise(function (resolve) {
			var process = new Process("shellcheck", {
				shell: true,
				args: ["--format", "json", "-"],
				cwd: wspath,
			});

Here is an example of a sourced/included shell script into the main script:

#!/bin/bash
# this is some main bash script

# include some files..
PARENTDIR=$(dirname "$0");
# shellcheck source=build/django_app/incl_term_setup.sh
source "${PARENTDIR}/include/incl_term_setup.sh"

"build" directory is at the top of the Nova workspace

@johnww2-nwxg johnww2-nwxg changed the title spellcheck via nova-spellcheck does not seem to find sourced (included) shell script files. shellcheck via nova-shellcheck does not seem to find sourced (included) shell script files. Sep 18, 2024
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

1 participant