You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are instances where it would be useful to have a user-defined preprocessor flesh out script fragments for Shellcheck to lint, then a postprocessor to read and adjust the results before Shellcheck prepares final judgement. User-defined config scripts that are sourced by application scripts within their own environments are a broad class of files that need this functionality to be properly checked.
The workflow I'm thinking of would look like this (new bits in bold):
Shellcheck opens source file (or stdin)
Shellcheck writes source file to stdin of preprocessor, and reads modified source from its stdout
Shellcheck parses and checks modified source
Shellcheck sends JSON results to stdin of postprocessor, and reads modified JSON results from its stdout
Shellcheck prints results in desired user format
#1843 is a typical example. Arch Linux's PKGBUILD files are really shell script fragments that are executed in an environment that's fairly well-defined, but not accessible outside the build process. A user wanting to use Shellcheck on PKGBUILD files would write the following:
A postprocessor script (pbadj.sh) that takes the JSON results from stdin and uses jq or some similar tool to subtract 7 from all line and endLine properties, to account for the wrapper's prelude, then drop any entries with line numbers that are negative or greater than the original input length. (For this and other reasons, it would be good for the postprocessor to also get the original source and the preprocessed input, probably as command-line arguments.)
Then shellcheck --pre pbwrap.sh --post pbadj.sh ... my.PKGBUILD should Get The Job Done.
Why not simply write a wrapper around Shellcheck instead?
A Shellcheck wrapper would have to parse all Shellcheck options, to "short-circuit" the above workflow when it doesn't make sense (e.g. --help, --list-optional, --version), and to "count option arguments" otherwise, to ensure all specified files are processed. This would require revisiting the wrapper each time the Shellcheck version changes, in case options are added/renamed/removed. It's not impossible, but it's highly inelegant.
Having this functionality be directly supported by Shellcheck also makes it easier to integrate with third-party tools like vscode-shellcheck, that would want to choose an output format best suited to their operations. Embedded pre-/post-processing in Shellcheck itself means not having to figure out how to adjust the final tty or diff output.
What about buggy plugins?
Poorly-written plugins could b0rk the workflow or confuse the user with results that don't map to the original source, but shouldn't be able to harm Shellcheck directly.
The text was updated successfully, but these errors were encountered:
For new checks and feature suggestions
There are instances where it would be useful to have a user-defined preprocessor flesh out script fragments for Shellcheck to lint, then a postprocessor to read and adjust the results before Shellcheck prepares final judgement. User-defined config scripts that are sourced by application scripts within their own environments are a broad class of files that need this functionality to be properly checked.
The workflow I'm thinking of would look like this (new bits in bold):
#1843 is a typical example. Arch Linux's PKGBUILD files are really shell script fragments that are executed in an environment that's fairly well-defined, but not accessible outside the build process. A user wanting to use Shellcheck on PKGBUILD files would write the following:
pbwrap.sh
) that takes the PKGBUILD source from stdin and wrap it like this: https://github.com/vn971/rua/blob/master/res/shellcheck-wrapperpbadj.sh
) that takes the JSON results from stdin and usesjq
or some similar tool to subtract 7 from allline
andendLine
properties, to account for the wrapper's prelude, then drop any entries with line numbers that are negative or greater than the original input length. (For this and other reasons, it would be good for the postprocessor to also get the original source and the preprocessed input, probably as command-line arguments.)Then
shellcheck --pre pbwrap.sh --post pbadj.sh ... my.PKGBUILD
should Get The Job Done.Why not simply write a wrapper around Shellcheck instead?
A Shellcheck wrapper would have to parse all Shellcheck options, to "short-circuit" the above workflow when it doesn't make sense (e.g.
--help
,--list-optional
,--version
), and to "count option arguments" otherwise, to ensure all specified files are processed. This would require revisiting the wrapper each time the Shellcheck version changes, in case options are added/renamed/removed. It's not impossible, but it's highly inelegant.Having this functionality be directly supported by Shellcheck also makes it easier to integrate with third-party tools like vscode-shellcheck, that would want to choose an output format best suited to their operations. Embedded pre-/post-processing in Shellcheck itself means not having to figure out how to adjust the final
tty
ordiff
output.What about buggy plugins?
Poorly-written plugins could b0rk the workflow or confuse the user with results that don't map to the original source, but shouldn't be able to harm Shellcheck directly.
The text was updated successfully, but these errors were encountered: