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

Breaks Dockerfile

Open Makoehle opened this issue 4 years ago • 8 comments

Having a Dockerfile with the following instruction:

FROM node:lts-alpine3.12 
RUN echo "Installing ..." \
  apk update > /dev/null && \
  apk upgrade > /dev/null && \
  apk add zip > /dev/null

this extension formats this code block to removing \

FROM node:lts-alpine3.12 
RUN echo "Installing ..." \
  apk update >/dev/null &&
  apk upgrade >/dev/null &&
  apk add zip >/dev/null

Which will lead to the following error: Error response from daemon: dockerfile parse error line 17: unknown instruction: APK

Update

  • I disabled Prettier and reloaded VS-Code but the Dockerfile kept getting formatted
  • I disabled shell-format and the Dockerfile stopped being formatted.

Makoehle avatar Jun 08 '21 06:06 Makoehle

You can provide the complete dockerfile. or test by shfmt command line tool.

foxundermoon avatar Jun 10 '21 07:06 foxundermoon

have same problem

AchillesG avatar Jun 23 '21 09:06 AchillesG

Looks like this is bug in shfmt that is officially not supporting Dockerfiles https://github.com/mvdan/sh/issues/640

matrixik avatar Jul 17 '21 21:07 matrixik

I've just installed this extension and it's true that the automatic formatting of Dockerfiles that contain multiline RUN statements leads to broken Dockerfiles. If shfmt doesn't explicitly support Dockerfiles, perhaps disabling Dockerfile formatting is the right thing to do? Or at least provide optional configuration?

stormsilver avatar Sep 03 '21 17:09 stormsilver

The solution is probably provided in this comment: https://github.com/foxundermoon/vs-shell-format/issues/29#issuecomment-806236260

sbrunner avatar Nov 07 '21 14:11 sbrunner

To save some time for everyone arriving here, just add the following to your settings.json:

"shellformat.effectLanguages": ["shellscript"],
"[dockerfile]": {
  "editor.formatOnSave": false
}

I am not sure why both "do only shellscript" and "do not do dockerfile" is required, but it won't work with only one of the settings.

mcnesium avatar Dec 09 '21 14:12 mcnesium

@mcnesium, better configure a different formatter for Dockerfiles. This one works great.

"[dockerfile]": {
    "editor.defaultFormatter": "ms-azuretools.vscode-docker"
}

But your effect langauges is good. Because disable formatOnSave is not respected by this extension for some reason.

bluebrown avatar Mar 24 '22 07:03 bluebrown