[yast-devel] ShellCheck available in Travis and YaST:Head
Hi, some time ago I fixed a typo in an yast2-packager shell script. After fixing it [1] I remembered that I had looked at the ShellCheck tool in the past. It is a similar tool to Rubocop but designed for shell scripts. There is even an online version if you want to do a quick test without installing it [2]. When I tried to run it on the original script it obviously found the error there. My idea was to run this check also in Travis to avoid similar problems in the future so I created a package in YaST:Head [3] and included it in the Travis image. The package is already available in the Leap 15.0 but the Tumbleweed contains a newer version which reports some more issues so I copied the TW version to YaST:Head and built it also for Leap 15.0. If you want to run ShellCheck for your scripts in Travis see [4] how it was done in the yast2-packager. Last but not least, there is a good documentation (wiki) describing the rationales and how to fix each reported issue, like [5]. So even when you are not a shell expert you should be able to fix the reported issues quite easily. Enjoy! :-) P.S.: An interesting detail I found: Shellcheck looks quite smart, e.g. in foo $bar it complains that you should double quote the unknown $bar value, but with bar=baz foo $bar it does not complain as it is actually not needed. With bar="baz z" foo $bar it correctly complains again. So it does not foolishly complain about double quotes everywhere, it evaluates the context and the real values to avoid false positives. That's really nice! [1] https://github.com/yast/yast-packager/pull/386/files [2] https://www.shellcheck.net/ [3] https://build.opensuse.org/package/show/YaST:Head/ShellCheck [4] https://github.com/yast/yast-packager/blob/465cdbce77c24f008b9e36653abf4dea8... [5] https://github.com/koalaman/shellcheck/wiki/SC2086 -- Ladislav Slezák YaST Developer SUSE LINUX, s.r.o. Corso IIa Křižíkova 148/34 18600 Praha 8 -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, Jan 08, 2019 at 01:30:45PM +0100, Ladislav Slezak wrote:
Hi,
TL;DR: .travis.yml: - docker run -it -e TRAVIS=1 -e TRAVIS_JOB_ID="$TRAVIS_JOB_ID" yast-packager-image shellcheck src/scripts/*.sh Thanks for this, Lada!
Last but not least, there is a good documentation (wiki) describing the rationales and how to fix each reported issue, like [5]. So even when you are not a shell expert you should be able to fix the reported issues quite easily.
Yes, I love it when a tool gives me URLs with explanations and rationales.
Enjoy! :-)
P.S.: An interesting detail I found: Shellcheck looks quite smart, e.g. in
It is written in Haskell. You know, strong type checking and mathematicians disguised as programmers. That gives me some comfort because it balances the mess that Bash itself is. -- Martin Vidner, YaST Team http://en.opensuse.org/User:Mvidner
On 1/8/19 1:30 PM, Ladislav Slezak wrote:
Hi,
some time ago I fixed a typo in an yast2-packager shell script. After fixing it [1] I remembered that I had looked at the ShellCheck tool in the past. It is a similar tool to Rubocop but designed for shell scripts. There is even an online version if you want to do a quick test without installing it [2].
Just for completeness, the same guy that recently recommended SellCheck in the Canary Linux User's group also pointed to Bashate as a possible alternative. https://github.com/openstack-dev/bashate -- Ancor González Sosa YaST Team at SUSE Linux GmbH -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (3)
-
Ancor Gonzalez Sosa
-
Ladislav Slezak
-
Martin Vidner