Skip to content

fix(completion): remove spurious single-quote in zsh loadautofunc detection - #2548

Merged
shadowspawn merged 3 commits into
yargs:mainfrom
JSap0914:fix/zsh-completion-loadautofunc-quote
Sep 15, 2026
Merged

shadowspawn merged 3 commits into
yargs:mainfrom
JSap0914:fix/zsh-completion-loadautofunc-quote

Conversation

@JSap0914

Copy link
Copy Markdown
Contributor

Bug

The zsh completion template added in #2424 contains a stray single-quote ' before ${zsh_eval_context[-1]}, making the autoloaded-function detection always fail:

# Generated script (broken) — the left side is "'loadautofunc" not "loadautofunc"
if [[ "'${zsh_eval_context[-1]}" == "loadautofunc" ]]; then

The double-quoted string "'${zsh_eval_context[-1]}" evaluates to a string with a literal ' prepended to the variable value, so the comparison is 'loadautofunc vs loadautofunc — never equal. The entire if branch that makes zsh autoloaded completions work on first Tab press is unreachable.

Fix

Remove the spurious ' so the generated script reads:

if [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]; then

Verification

npx mocha --enable-source-maps ./test/completion.mjs --require ./test/before.mjs --timeout=24000 --grep "spurious"

  Completion
    zsh
      ✓ zsh completion script uses correct zsh_eval_context comparison without spurious single-quote

  1 passing (93ms)

The test fails (RED) on the original template and passes (GREEN) after the one-character fix. The full suite (828 tests) continues to pass with no regressions.

Note: This PR was prepared with AI assistance.

…ection

The zsh completion template introduced in yargs#2424 included a stray
single-quote before ${zsh_eval_context[-1]}, causing the comparison:

  [[ "'${zsh_eval_context[-1]}" == "loadautofunc" ]]

to always evaluate as false (comparing "'loadautofunc" vs "loadautofunc").
This broke the autoloaded-function detection entirely, so completions
would never fire on the first Tab when the script is zsh-autoloaded.

Remove the spurious quote so the comparison is correct:

  [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]
Copilot AI review requested due to automatic review settings June 17, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@shadowspawn

Copy link
Copy Markdown
Member

Over 120 Pull Requests opened in 3 days.

To be clear: is this Pull Request entirely AI/LLM generated?

@JSap0914

Copy link
Copy Markdown
Contributor Author

Fair question, and thanks for asking directly rather than just closing it. Yes — I use an AI coding assistant to find and fix small, self-contained bugs, and I review and test each change locally before opening it (for this one: a RED test reproducing the issue, then the fix, then the full suite). I realize a burst of PRs across many repos reads as noise and adds review load you didn't ask for. If commander/yargs would prefer not to receive AI-assisted contributions, just say the word and I'll close these and stay out of your tracker — no hard feelings either way.

@shadowspawn

Copy link
Copy Markdown
Member

That change got introduced right before release: cbf7788

A lot of discussion in #2424 for something that didn't achieve the goal! 😢

The RED test is not appropriate. It is testing for s specific typo and not testing the functionality. Given the difficulty in testing and a minor change, I think just leave the test out.

I'll check this by hand before releasing in any case.

@JSap0914

Copy link
Copy Markdown
Contributor Author

Dropped the test — the PR now contains only the one-line fix removing the spurious single-quote in lib/completion-templates.ts.

@lbesecker195 lbesecker195 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified in lib/completion-templates.ts: the string is a JS template literal, so the leading ' is emitted verbatim into the zsh script and the comparison becomes "'loadautofunc" == "loadautofunc", which never matches. Removing it restores the intended check. LGTM.

@shadowspawn
shadowspawn merged commit 224e285 into yargs:main Sep 15, 2026
7 checks passed
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.

4 participants