Skip to content

README caveats on index whitespace outdated #1314

Closed

Description

@scop

Check the caveats section in the README.

Originally posted by @mvdan in #1273

In relation to #1273 and the above comment, the said section is not up to date with the 3.13.0 behavior. I'm not sure if this is an inadvertent change after 3.12.0, or a documentation issue. so seeking to clarify. Specifically the last example:

$ echo '${array[dash-string]}' | shfmt
${array[dash - string]}

3.13.0 does not emit ${array[dash - string]}, but ${array[dash-string]}. (It does that also for ${array[dash - string]} input.)

I don't quite follow how this formatting change follows from the caveats section -- to me it could end up either with or without spaces and still satisfy what was said in the caveats?

The other example outputs are also slightly outdated, as they lack some backticks. #1315 updates them all.

Activity

  1. scop commented on Apr 2, 2026

    @scop
    ContributorAuthor

    One example: bash-completion sources are currently formatted with 3.12.0. Reformatting them with 3.13.0 causes a bunch of these mentioned changes: https://github.com/scop/bash-completion/actions/runs/23769811310/job/69258324432

    I'm mainly seeking to clarify if this change is intentional before upgrading to 3.13.0 as it's not mentioned in the release notes. (I don't have a particular preference towards spaces vs no spaces in this case, but I do prefer consistency unless there's an intentional and preferably documented change.)

  2. LangLangBart commented on Apr 2, 2026

    @LangLangBart

    3.13.0 does not emit ${array[dash - string]}, but ${array[dash-string]}

    might have been unintentionally caused by 8c73583

    sh/syntax/printer.go

    Lines 720 to 722 in e97b2b0

    // Note that e.g. foo[1,3]=$bar in Zsh does not allow any spaces around the comma,
    // as that breaks the assignment word.
    p.arithmExpr(index, true, false)

  3. mvdan commented on Apr 2, 2026

    @mvdan
    Owner

    @LangLangBart is on the money, this was an unintentional change in 8c73583. I'll take a look.

  4. mvdan commented on Apr 2, 2026

    @mvdan
    Owner

    Incredible that this was not covered by any tests even though we had an example in the README. Well, we have tests now. Thanks @scop for catching this. Regardless of what format is best, I didn't intend this change, and it was unnecessary diff noise for downstreams, so it's now fixed.

  5. added a commit that references this issue on Apr 2, 2026
    d2b044b
  6. added a commit that references this issue on Jun 7, 2026
    4a980c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址