koalaman/shellcheck

can not disable SC1009 by directive (or SC1072, SC1073)

Opened this issue · 1 comments

For bugs

  • SC1009, SC1072, SC1073
  • version: 0.4.6 / online

Here's a snippet or screenshot that shows the problem:

#!/bin/bash

VAR1=123
VAR2=456
VAR3=123
OP="-eq"

# shellcheck disable=1009 disable=1072 disable=1073
if [ 0${VAR1} ${OP} 0${VAR2} ]; then
   echo "${VAR1} equal ${VAR2}"
elif [ 0${VAR1} ${OP} 0${VAR3} ]; then
   echo "${VAR1} equal ${VAR3}"
else
   echo "${VAR1} not equal to ${VAR2} or ${VAR3}"
fi

Here's what shellcheck currently says:

In test/sh/shellcheck_1 line 10:
if [ 0${VAR1} ${OP} 0${VAR2} ]; then
^-- SC1009: The mentioned parser error was in this if expression.
   ^-- SC1073: Couldn't parse this test expression.
              ^-- SC1072: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

Here's what I wanted or expected to see:

same result like:

shellcheck -e SC1009,SC1072,SC1073 test/sh/shellcheck_1

There's little value in running shellcheck on a script that doesn't parse. Hiding syntax errors is purely cosmetic, and won't make shellcheck continue.

Until ShellCheck is able to parse or skip such statements, you could rewrite it with test which it doesn't get involved with.