Skip to content

Bug: --show-snippet option definition uses single colon instead of double colon, silently consuming the next CLI argument #11683

@alies-dev

Description

@alies-dev

Description

In src/Psalm/Internal/Cli/Psalm.php, the show-snippet long option is defined with a single colon ('show-snippet:') instead of a double colon ('show-snippet::').

Line 154:

private const LONG_OPTIONS = [
    // ...
    'show-snippet:',  // BUG: single colon = required value
    // ...
];

Per PHP's getopt() semantics:

  • Single colon (:) = required value
  • Double colon (::) = optional value

The help text correctly documents it as optional: --show-snippet[=true]

Impact

When --show-snippet is placed before another option like --config, PHP's getopt() treats the next argument as --show-snippet's value, silently consuming it:

# BUG: --config=psalm-taint.xml is consumed as value of --show-snippet
psalm --show-snippet --config=psalm-taint.xml --taint-analysis

# WORKAROUND: put --config before --show-snippet
psalm --config=psalm-taint.xml --show-snippet --taint-analysis

This causes Psalm to silently fall back to the default psalm.xml config, with no warning that --config was ignored.

Expected fix

- 'show-snippet:',
+ 'show-snippet::',

Environment

  • Psalm version: 6.15.1
  • PHP version: 8.4.18
  • OS: macOS (Darwin 24.6.0)

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