mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.99k stars 333 forks source link

Formatter break #922

Closed Bilge closed 1 year ago

Bilge commented 1 year ago

Is this the syntax highlighter used by Jetbrains' PhpStorm? If so, I have a parser syntax highlighting bug to report. This code will break syntax highlighting for the entire remainder of the file.

    x=(
        "$(:a "b" c)"
        "$(d e f)"
        "$(g h i)"
    )

It requires quoted subshells assigned to arguments of an array, the first of which has a command whose name starts with a colon (:) and has at least one quoted argument. I realise that's quite a long and obscure list of requirements but it occurs in the real world, believe it or not!

It does not matter how many arguments are quoted, so "$(:a "b" c)" causes the issue, as well as "$(:a "b" "c")", but not "$(:a b c)" (because there are no quotes embedded in the subshell) and not "$(a "b" c)" (because the command name doesn't begin with the colon (:) character.

📝 If this is the correct project to post this issue in, I have a few other parser breaks to submit also.

mvdan commented 1 year ago

This is the first time I hear about PhpStorm, so my guess is they are not using this parser. I would say raise this issue with them first. I did some brief googling and found nothing about their relation to this project.

Bilge commented 1 year ago

Right or wrong, you are nevertheless credited for the Shell Script plugin, unless it just means it can (optionally) integrate with these tools.

image

mvdan commented 1 year ago

I see. It appears they only use shfmt for formatting (https://github.com/JetBrains/intellij-community/blob/a98897a49e33d58c06dee6d6b07f98316cc9c145/plugins/sh/core/src/com/intellij/sh/formatter/ShExternalFormatter.java#L71) and not for syntax highlighting. Which makes sense, because shfmt does not fail on the example you posted above.

Bilge commented 1 year ago

Thanks and sorry for bothering you.