Skip to content

feat: add shellcheckExternalSources config to make --external-sources optional#1376

Merged
skovhus merged 2 commits intobash-lsp:mainfrom
marcusquinn:fix/configurable-external-sources
Mar 6, 2026
Merged

feat: add shellcheckExternalSources config to make --external-sources optional#1376
skovhus merged 2 commits intobash-lsp:mainfrom
marcusquinn:fix/configurable-external-sources

Conversation

@marcusquinn
Copy link
Contributor

Summary

Adds a shellcheckExternalSources boolean config option (default: true for backward compatibility) that controls whether --external-sources is passed to ShellCheck. When set to false, the flag is omitted, preventing unbounded memory growth on projects with many cross-sourcing shell scripts.

Problem

The --external-sources flag is currently hardcoded in every ShellCheck invocation (server/src/shellcheck/index.ts:142). On projects with many shell scripts that cross-source each other (e.g. 100+ scripts with source-path=SCRIPTDIR in .shellcheckrc), this causes exponential AST expansion — individual shellcheck processes grow to 3-5 GB RSS and never terminate.

With multiple editor sessions or headless AI coding tools (opencode, Claude Code) each spawning their own bash-language-server, this compounds rapidly. We observed 73 concurrent shellcheck processes consuming 17.8 GB RAM on a 64 GB machine.

The existing shellcheckArguments config only appends arguments — there's no way to remove the hardcoded --external-sources.

Changes

File Change
server/src/config.ts Add shellcheckExternalSources boolean config (default true) and SHELLCHECK_EXTERNAL_SOURCES env var
server/src/shellcheck/index.ts Add externalSources to LinterOptions, conditionally include --external-sources
server/src/server.ts Pass config.shellcheckExternalSources when constructing Linter
vscode-client/package.json Add bashIde.shellcheckExternalSources VS Code setting

Usage

VS Code setting:

{
  "bashIde.shellcheckExternalSources": false
}

Environment variable:

SHELLCHECK_EXTERNAL_SOURCES=false

LSP initialization (for non-VS Code editors):

{
  "shellcheckExternalSources": false
}

Backward Compatibility

Default is true — existing behavior is unchanged. Only users who explicitly set it to false will see the difference.

Fixes #874
Fixes #1375

… optional

The --external-sources flag is currently hardcoded in every ShellCheck
invocation. On projects with many shell scripts that cross-source each
other (e.g. 100+ scripts with source-path=SCRIPTDIR in .shellcheckrc),
this causes exponential AST expansion — individual shellcheck processes
grow to 3-5 GB RSS and never terminate.

Adds a shellcheckExternalSources boolean config option (default: true
for backward compatibility) and SHELLCHECK_EXTERNAL_SOURCES env var.
When set to false, --external-sources is omitted from the ShellCheck
invocation, preventing the unbounded memory growth.

Fixes bash-lsp#874
Fixes bash-lsp#1375
@skovhus skovhus enabled auto-merge March 6, 2026 06:18
@skovhus skovhus disabled auto-merge March 6, 2026 06:18
@skovhus skovhus enabled auto-merge March 6, 2026 18:42
@skovhus skovhus merged commit 3218a31 into bash-lsp:main Mar 6, 2026
4 checks passed
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.56%. Comparing base (84ec668) to head (e46e4a6).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
server/src/shellcheck/index.ts 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1376      +/-   ##
==========================================
- Coverage   80.59%   80.56%   -0.03%     
==========================================
  Files          29       29              
  Lines        1510     1513       +3     
  Branches      373      374       +1     
==========================================
+ Hits         1217     1219       +2     
  Misses        235      235              
- Partials       58       59       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ShellCheck subprocess with --external-sources leaks unbounded memory (19.8 GB observed) Add ability to not use --external-sources flag in shellcheck

2 participants