I searched issues for "auto fix" and didn't find anything related.
Is there any interest in an auto fix feature?
When first discovering shellcheck, and when inheriting code, and when upgrading to a new version of shellcheck there can be an overwhelming number of simple fixes that can be solved by find . -iname '*.sh' | xargs -I {} perl -pi -e "$RE" {} followed by git diff-highlight review of course. So instead of everyone independently creating $RE we could have an "auto fix" feature that would make a best effort to correct common issues.
Am I the outlier here or is anyone else accumulating a list of Regular Expressions to help fix issues identified by shellcheck?
At this point, I'd say the next step is a proof-of-concept called shellfix. If it seems viable (meaning there are enough REs to make it worth the effort), then maybe a --fix option, plus functionality, could be grafted into shellcheck.
So, the original question still begs - is anyone out there doing autocorrect?
I would like that feature very much but I would also be fine with having a patch-file for the fix as alternate output. Then I could apply the patches easily enough.
This was the intention behind #695 from a few years ago, but it's hard to retrofit this kind of functionality.
But the corrected line is suggested. So in theory, having an applyable diff as output would be fine as well and doable.
There's now diff output in b1aeee56!
Why is this issue closed? I'd still like to have a --fix-option. :)
Why is this issue closed? I'd still like to have a --fix-option. :)
@dploeger You can pipe diff output to git apply or patch -p1: https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md
This will fix "fixable" errors for you in a git repo :slightly_smiling_face:
shellcheck -f diff <files> | git apply
Ohhhhh! 馃う鈥嶁檪
Brilliant idea. Thanks.
Why is this issue closed? I'd still like to have a --fix-option. :)
@dploeger You can pipe diff output to
git applyorpatch -p1: https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.mdThis will fix "fixable" errors for you in a git repo 馃檪
shellcheck -f diff <files> | git apply
Which version of shellcheck is that?
I'm getting the following on version 0.4.6:
Unknown format diff
Supported formats:
checkstyle
gcc
json
tty
@oxr463 I think you should update shellcheck. Version 0.4.6 is really old (> 3 years).
Look at https://github.com/koalaman/shellcheck/releases for newer releases.
@oxr463 I think you should update shellcheck. Version 0.4.6 is really old (> 3 years).
Look at https://github.com/koalaman/shellcheck/releases for newer releases.
Thanks!
To apply to a bunch of scripts:
find <directory> -type f -print0 | xargs -0 shellcheck -f diff | git apply
find . -type f -iname '*.sh' -print0 | xargs -0 -I {} -P "$(nproc)" bash -c "shellcheck -f diff \"{}\" | git apply"
Most helpful comment
There's now
diffoutput in b1aeee56!