foxundermoon / vs-shell-format

the shellscript、Dockerfile、properties ...... format extension
MIT License
444 stars 47 forks source link

Bug: trailing backslash removed in Dockerfile #304

Open jsngalloway opened 1 year ago

jsngalloway commented 1 year ago

Type: Bug

  1. Have a dockerfile with a RUN line that ends in a backslash
  2. format file

Before formatting:

FROM ubuntu AS build

USER root

RUN apt-get --quiet update && \
  DEBIAN_FRONTEND=noninteractive apt-get --quiet install -y \
  git \
  make

After formatting:

FROM ubuntu AS build

USER root

RUN apt-get --quiet update &&
  DEBIAN_FRONTEND=noninteractive apt-get --quiet install -y \
    git \
    make

Notice first backslash is removed, this breaks the functionality of the file.

yu-sato-astina commented 1 year ago

Hi I am still encounted this format error. Have it already amended on latest release?

My environment: vscode: v1.74.0-insider shell-format plugin: v7.2.2

manuel-lopez-lyb commented 1 year ago

This issue is a duplicate of https://github.com/foxundermoon/vs-shell-format/issues/176 which links to https://github.com/mvdan/sh/issues/640.

The issue is that the plugin is using shfmt to interpret the docker file as a shell script. In shell writing

apt-get --quiet update &&
  DEBIAN_FRONTEND=noninteractive apt-get --quiet install -y

is valid but in docker it breaks since the line is broken. In my case I use

binary_next_line = true

so that the shell scripts have all the operators on the next line and this happens to be aligned with the dockerfiles as well. See https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd

admodev commented 1 year ago

Is this fixed already?

Octogonapus commented 12 months ago

Is this fixed already?

Still experiencing this bug. It also seems disabling formatting for Dockerfiles doesn't work:

    "[docker]": {
        "editor.formatOnSave": false,
        "editor.defaultFormatter": null
    },
    "[dockerfile]": {
        "editor.formatOnSave": false,
        "editor.defaultFormatter": null
    },
nothingface0 commented 8 months ago
     "[dockerfile]": {
         "editor.formatOnSave": false,
     },

This actually worked for me, if you also add:

 "shellformat.effectLanguages": [
    "shellscript",
    // "dockerfile", // Remove me!!
    "dotenv",
    "hosts",
    "jvmoptions",
    "ignore",
    "gitignore",
    "properties",
    "spring-boot-properties",
    "azcli",
    "bats"
  ],

Thank you @Octogonapus !

cdaringe commented 6 months ago

The shfmt crew says explicitly that dockerfile is not supported. It seems like we should perhaps prune Dockerfile support out of this extension?