Skip to content

[FEATURE] Add ShellCheck source-path directive for relative script sourcing #126

@WilliamBerryiii

Description

@WilliamBerryiii

Problem Statement

Some shell scripts source other scripts using relative paths from the script directory. ShellCheck cannot resolve these paths for static analysis, limiting lint coverage. Currently, these scripts require inline suppressions or are not fully validated.

Proposed Solution

Add source-path=SCRIPTDIR directive to .shellcheckrc:

  1. Add directive to enable relative path resolution
  2. Validate with existing sourcing patterns
  3. Document the directive's purpose

Validated patterns in codebase:

  • source "${SCRIPT_DIR}/env/.env"
  • source "${SCRIPT_DIR}/modules/logging.sh"

Alternative Solutions

  • Inline directives per file: Add # shellcheck source-path=SCRIPTDIR to individual files (inconsistent, clutters code)
  • Absolute path refactoring: Rewrite sourcing to use absolute paths (breaks portability)

Target Components

  • Terraform modules
  • Bicep modules
  • Blueprints
  • GitHub Actions
  • Documentation
  • Other: .shellcheckrc configuration file

Implementation Ideas

Add to .shellcheckrc:

# ShellCheck configuration
shell=bash
disable=SC1091
source-path=SCRIPTDIR

Verification steps:

  1. Run shellcheck --format=gcc on scripts with relative sourcing
  2. Confirm no new errors introduced
  3. Confirm existing source patterns resolve correctly

Additional Context

Benefits

  • Better static analysis coverage for sourced scripts
  • Enables ShellCheck to follow source statements
  • Improved lint quality without code changes
  • Consistent configuration approach

Potential Challenges

  • Limited impact initially - only affects scripts using ${SCRIPT_DIR} pattern
  • May need additional source-path entries if other patterns exist

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