vs-shell-format icon indicating copy to clipboard operation
vs-shell-format copied to clipboard

Bug: trailing backslash removed in Dockerfile

Open jsngalloway opened this issue 3 years ago • 12 comments

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.

jsngalloway avatar Nov 17 '22 15:11 jsngalloway

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

yu-sato-astina avatar Dec 05 '22 04:12 yu-sato-astina

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

manuel-lopez-lyb avatar Dec 07 '22 04:12 manuel-lopez-lyb

Is this fixed already?

admodev avatar Jun 23 '23 17:06 admodev

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
    },

Octogonapus avatar Sep 02 '23 03:09 Octogonapus

    "[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 !

nothingface0 avatar Dec 19 '23 14:12 nothingface0

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

cdaringe avatar Feb 06 '24 23:02 cdaringe