-
Notifications
You must be signed in to change notification settings - Fork 167
Shellcheck optionals #25
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 optionals #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution and apologies for the delay in reviewing this! This feature makes sense and this looks like a good start, but have some suggestions for improvements.
…k shells * `sh` * `ash` * `dash` * `bash` * `bats` * `ksh` [src](https://github.com/koalaman/shellcheck/blob/c2a15ce8e906ae6a12bcbe32eac7ac586fbcb59b/src/ShellCheck/Parser.hs#L3186-L3193) --- Shebang regex: Was: `'^#!.*sh'` Now: `'^#!\(/\|/.*/\|/.* \)\(\(ba\|da\|k\|a\)*sh\|bats\)$'` Test cases: https://pastebin.com/BKB92wx2 Previous regex matched a lot of invalid shebangs & missed the 6 valid `bats` shebangs. Current regex matches just the 6 correct shebangs from each valid shell. There are probably some cases that I can't think of but it's a lot safer than the existing one. A compromise would be something like: `'^#!/.*\(\(ba\|da\|k\|a\)*sh\|bats\)$'` It matches the `zsh` `fish` and extra characters + valid shell ones but they're all at least valid. --- File ending regex: Was: `\.sh$|bash$` Now: `.+\.(sh|bash|dash|ksh|ash|bats)$` Test cases: https://pastebin.com/JRJg8N13 Testing script: ``` test() { if [[ "$1" =~ .+\.(sh|bash|dash|ksh|ash|bats)$ ]]; then echo "match - $1" else echo "not match - $1" fi } while IFS= read -r FILE; do if [[ "$FILE" != "" ]]; then test "$FILE" fi done <<EOF TEST CASES HERE EOF ``` Previous regex would match `.sh` `bash` and miss `file.ksh` `file.dash` `file.ash` `file.bats` Current regex only matches the 3 normal file names + also matches just `.sh` `.bash` etc, which are very unusual but valid file names. There's no extra checking for slashes etc because file names & escapes could confuse things, just the extension should be enough.
I've updated the regex used for the shebang & file ending as shellcheck should match the following shells:
Shebang regex: Test cases: Previous regex matched a lot of invalid shebangs & missed the 6 valid Current regex matches just the 6 correct shebangs from each valid shell. File ending regex: Test cases: Testing script:
Previous regex would match Current regex only matches the 3 normal file names + also matches just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay in getting back to you on this! I have a few style nits (tabbing should be 2 spaces, and the while loop should use $# -gt 0
), but since they're minor will apply them in a separate PR after merging.
No problem
|
|
Ahhh I think you are right. Apologies for that! I was so used to switching to |
no problem 😃 |
Added the ability to use optional shellcheck checks.
Testing Script:
Testing pre-commit config:
logging the command that would be ran, forcing exit 1 to show the logs:
With:
Without:
--enable
will only be ran if it's provided in the pre-commit config. This is to avoid issues with shellcheck before 0.7.0 when--enable
was added