Skip to content

[FEATURE] Enable ShellCheck require-variable-braces optional check #127

@WilliamBerryiii

Description

@WilliamBerryiii

Problem Statement

The codebase has inconsistent variable reference formatting - some use $var while others use ${var}. ShellCheck's SC2250 optional check can enforce the braced format (${var}) for consistency. Initial analysis shows 3,145 potential changes across 81 scripts.

Proposed Solution

Enable SC2250 in .shellcheckrc and remediate existing scripts:

  1. Add enable=require-variable-braces to .shellcheckrc
  2. Create automated script to convert $var to ${var}
  3. Run conversion across all shell scripts
  4. Validate no functional changes

Alternative Solutions

  • Gradual adoption: Enable SC2250 but suppress existing violations, fix incrementally (slow, defeats purpose)
  • Manual conversion: Fix each script by hand (time-consuming, error-prone)
  • Do nothing: Accept inconsistent formatting (status quo)

Target Components

  • Terraform modules
  • Bicep modules
  • Blueprints
  • GitHub Actions
  • Documentation
  • Other: Shell scripts (81 files with 3,145 potential changes)

Implementation Ideas

Discovery command used:

shellcheck --enable=require-variable-braces --format=gcc *.sh 2>&1 | grep -c SC2250

Breakdown by directory:

Directory SC2250 Warnings
scripts/ 2,847
src/100-edge/100-cncf-cluster/scripts/ 113
src/starter-kit/*/scripts/ 142
Other directories 43

Automated fix approach:

  • Use sed or custom script to convert $var${var}
  • Exclude special variables: $@, $*, $?, $!, $$, $#, positional $1-$9
  • Preserve quoted contexts

Additional Context

Benefits

  • Consistent variable formatting across all scripts
  • Improved readability and maintainability
  • Eliminates ambiguity in variable boundaries (e.g., ${var}suffix vs $varsuffix)
  • Aligns with shell scripting best practices

Potential Challenges

  • High volume of changes requires thorough testing
  • Automated conversion must be carefully validated
  • Some edge cases may need manual review
  • Large PR may be difficult to review

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions