Skip to content

False positive: Comments/ShellCheck directives in associative arrays wrongly triggers SC2190 #3377

@brlin-tw

Description

@brlin-tw

For bugs with existing features

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

#!/usr/bin/env bash

# shellcheck disable=SC2034
declare -A assoc_array=(
    # shellcheck disable=SC1003
    ['Legit array index with trailing backslash \']=value
)

Here's what shellcheck currently says:

[Line 5:](javascript:setPosition(5, 5))
    # shellcheck disable=SC1003
    ^-- [SC2190](https://www.shellcheck.net/wiki/SC2190) (warning): Elements in associative arrays need index, e.g. array=( [index]=value ) .
      ^-- [SC2190](https://www.shellcheck.net/wiki/SC2190) (warning): Elements in associative arrays need index, e.g. array=( [index]=value ) .
                 ^-- [SC2190](https://www.shellcheck.net/wiki/SC2190) (warning): Elements in associative arrays need index, e.g. array=( [index]=value ) .
 
[Line 6:](javascript:setPosition(6, 49))
    ['Legit array index with trailing backslash \']=value
                                                ^-- [SC1003](https://www.shellcheck.net/wiki/SC1003) (info): Want to escape a single quote? echo 'This is how it'\''s done'.

Here's what I wanted or expected to see:

No issues detected!

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