There should be a way to disable some checks by their codes in-line:
if ( some sh scripting ); then # shellcheck-ignore: <CODE TO IGNORE>
This is already supported, see https://github.com/koalaman/shellcheck/wiki/Directive
Dam! Honestly I searched and googled.... Thanks!
Only the line right after disabling is ignored?
Since the only directive is "disable", we can't we re-enable the check at a later time in the checking process?
The error will be disabled for the immediate command or structure only, so you can decide on the scope that way.
does anyone know if it's possible to disable error checking for a file?
@gdbtek There's currently no way to make shellcheck ignore a file it's been explicitly asked to check. How are you running into this issue?
@koalaman , I have a case that I think it would be very handy to ignore a file. For example for the case of configuration files:
$ cat config.sh
#!/bin/bash -e
var1='123'
var2='456'
$ cat app.sh
#!/bin/bash -e
source config.sh
echo "${var1}"
echo "${var2}"
$ shellcheck config.sh app.sh
In config.sh line 3:
var1='123'
^-- SC2034: var1 appears unused. Verify it or export it.
In config.sh line 4:
var2='456'
^-- SC2034: var2 appears unused. Verify it or export it.
this is just a quick sample. In my large app, I have many config files that will be shared by multiple apps. So when I ran shellcheck, I have a lot of warning of SC2034 from all config files. That's why I think it would be nice to have a way to ignore files. Would you suggest to export all variables in config files?
I think it would be nice if:
1) shellcheck support some sort of .shellcheckignore file which is very similiar to .jshintignore or .eslintignore file in NodeJS code quality tool.
2) A directive that can be inserted on to of shell script to ignore the entire file.
For now, I have workaround by writing a short shell script to ignore them.
Thanks
@gdbtek - try this, it is how I disable a specific warning for an entire file.
I use a directive, and the braces create a scope for it, which includes the rest of the source. This has worked fine for me in simple one off scripts, but I'm not sure of the implications with included files. Worth a shot!
$ cat config.sh
#!/bin/bash -e
# shellcheck disable=SC2034
{
var1='123'
var2='456'
}
Most helpful comment
@gdbtek - try this, it is how I disable a specific warning for an entire file.
I use a directive, and the braces create a scope for it, which includes the rest of the source. This has worked fine for me in simple one off scripts, but I'm not sure of the implications with included files. Worth a shot!