Skip to content

False positive for SC2248 #3405

@LLyaudet

Description

@LLyaudet

For bugs with existing features

  • Rule Id (if any, e.g. SC1000): SC2248
  • My shellcheck version (shellcheck --version or "online"): shellcheck (edge) v0.11.0+git57.29f0d8d
  • The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
  • I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit

It seems https://www.shellcheck.net/ doesn't use --enable=all
But I checked that latest snap (latest/edge) mentions the same commit hash
as the latest commit on GitHub.

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

#!/usr/bin/env bash
foo(){
  declare -i cd_result
  cd "$1" || {
    cd_result=$?;
    echo "foo no such directory";
    return ${cd_result};
  }
}

Here's what shellcheck currently says:

shellcheck --enable=all truc.sh

In truc.sh line 7:
return ${cd_result};
^----------^ SC2248 (style): Prefer double quoting even when variables don't contain special characters.

Did you mean:
return "${cd_result}";

For more information:
https://www.shellcheck.net/wiki/SC2248 -- Prefer double quoting even when v...

Here's what I wanted or expected to see:

I think the only valid exception to rule SC2248 is when the variable is declared as integer.
Script above is such a case,
and in my opinion there should be no warning in that case.

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