Skip to content

Suppress SC2319/SC2320 when $? is assigned to a variable#3488

Open
ayushi-work wants to merge 1 commit into
koalaman:masterfrom
ayushi-work:fix/sc2319-assignment-false-positive
Open

Suppress SC2319/SC2320 when $? is assigned to a variable#3488
ayushi-work wants to merge 1 commit into
koalaman:masterfrom
ayushi-work:fix/sc2319-assignment-false-positive

Conversation

@ayushi-work

@ayushi-work ayushi-work commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Fixes #3486

SC2319 warns "This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten." However, it fired even when $? was already being assigned to a variable via || or &&, like:

[[ -e "./lockfile" ]] || retval=$?

The user is already following the advice (assigning to a variable), so the warning is a false positive.

This change skips both SC2319 and SC2320 when $? appears inside a T_Assignment node.

Test plan

  • cabal test passes (all existing + 3 new prop_ tests)
  • The issue snippet no longer triggers SC2319
  • Non-assignment cases like exit $? after a condition still trigger SC2319

@ayushi-work

Copy link
Copy Markdown
Author

Hi @koalaman, just bumping this up!

Comment thread src/ShellCheck/Analytics.hs Outdated
@ayushi-work ayushi-work force-pushed the fix/sc2319-assignment-false-positive branch from f2af3dc to bc5cded Compare June 23, 2026 19:54
@ayushi-work ayushi-work requested a review from e-kwsm June 23, 2026 20:09
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.

SC2319: rule triggered even though using variable assignment

2 participants