Skip to content

False positives: SC2154/SC2140 for sourced variables and heredoc expansion #95

@noahgift

Description

@noahgift

Summary

bashrs reports false positive warnings for two common patterns that are intentional and correct.

Reproduction

Script 1: ground_truth_config.sh (sourced config)

#!/bin/bash
set -euo pipefail
MODEL_SIZE="${1:-tiny}"

case "$MODEL_SIZE" in
  tiny)
    WAPR_MODEL='models/whisper-tiny.apr'
    ;;
esac

export WAPR_MODEL

Script 2: ground_truth_test.sh (sources config, uses heredoc)

#!/bin/bash
set -euo pipefail
source "$(dirname "$0")/ground_truth_config.sh" "$MODEL_SIZE"

# Uses sourced variable - triggers SC2154
echo "Model: $WAPR_MODEL"

# Heredoc with intentional variable expansion - triggers SC2140
uv run --with torch - <<PYTHON
model = whisper.load_model("${MODEL_SIZE}")
PYTHON

Expected Behavior

  1. SC2154: No warning for variables set by source command
  2. SC2140: No warning for heredoc variable expansion when quotes are intentional

Actual Behavior

SC2154: WAPR_MODEL is referenced but not assigned
SC2140: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?

Suggested Solutions

  1. SC2154: Track variables through source/. commands (complex) OR provide directive to suppress
  2. SC2140: Recognize heredoc context where shell expansion is intentional

Workaround

Added comments documenting expected warnings:

# bashrs lint: SC2154 warnings expected (vars from sourced config)
# bashrs lint: SC2140 warnings expected (heredoc var expansion is intentional)

Environment

  • bashrs version: latest
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions