Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: trailing backslash removed in Dockerfile #304

Open
jsngalloway opened this issue Nov 17, 2022 · 6 comments
Open

Bug: trailing backslash removed in Dockerfile #304

jsngalloway opened this issue Nov 17, 2022 · 6 comments

Comments

@jsngalloway
Copy link

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
Copy link

yu-sato-astina commented Dec 5, 2022

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
Copy link

This issue is a duplicate of #176 which links to
mvdan/sh#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
Copy link

admodev commented Jun 23, 2023

Is this fixed already?

@Octogonapus
Copy link

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
Copy link

nothingface0 commented Dec 19, 2023

    "[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
Copy link

cdaringe commented Feb 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants