Skip to content

False positive for 1072 when there's inline disable directives #1036

Description

@mechalynx

For bugs

  • Rule Id: 1072
  • Version: local 0.4.6 / also occurs online
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

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

#! /usr/bin/env bash

if [[ "$1" =~ [0-9]+ ]]
then
  echo "$1"
# shellcheck disable=1001
elif [[ "$1" =~ [^0-9] ]]
then
  echo "$2"
fi

Here's what shellcheck currently says:

Line 3:
if [[ "$1" =~ [0-9]+ ]]
^-- SC1009: The mentioned parser error was in this if expression.
 
Line 4:
then
^-- SC1073: Couldn't parse this then clause.
 
Line 7:
elif [[ "$1" =~ [^0-9] ]]
     ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.

Here's what I wanted or expected to see:

No error exists in that code. The false positive does not occur if the disable directive is missing or at the block level (outside the if or a function block).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions