shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

[Feature Request] Disable then enable

Open lonix1 opened this issue 3 years ago • 3 comments

For new checks and feature suggestions

  • [x] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
  • [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

I couldn't find anything similar other than #2196 which is a "global" toggle, and not what I'm referring to here.

Problem

In many static analysers you can do this

// disable 1234
var something = that.Causes(theError);        // error is not reported
and.this.AlsoCausesTheError();                // error is not reported
// enable 1234
foo.causeErrorAgain();                        // error is reported

So we can disable a rule for one or more lines, then enable it again for the rest of the file.

Feature Request

Please consider something like this for shellcheck:

# shellcheck disable=SC1083
...
# shellcheck enable=SC1083

lonix1 avatar Jun 07 '22 01:06 lonix1

Alternatively put the SC disable commands into a commands block that shares the same shellcheck disabled entries:

# shellcheck disable=SCxxx
{
  var something = that.Causes(theError);  // error is not reported
  and.this.AlsoCausesTheError();                // error is not reported
}
foo.causeErrorAgain();                               // error is reported
``

leagris avatar Jun 07 '22 06:06 leagris

That is a nice trick @leagris, thanks.

Sadly it doesn't work when using templating, as discussed here, but it's a nice workaround in other cases.

lonix1 avatar Jun 07 '22 07:06 lonix1

This would be useful for my use case too, which is that I have a shell script with a man page embedded in it.

lpar avatar Sep 21 '22 16:09 lpar

Came across an instance of this yesterday..

I was thinking something like: # shellcheck disable=SC1234:5 meaning disable the check for the next 5 lines.

woodward2 avatar May 10 '23 15:05 woodward2