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

How to disable formatting for Dockerfile? #62

Closed
zulhfreelancer opened this issue Jan 10, 2020 · 13 comments
Closed

How to disable formatting for Dockerfile? #62

zulhfreelancer opened this issue Jan 10, 2020 · 13 comments
Labels
configuration configutation question help wanted

Comments

@zulhfreelancer
Copy link

Hi,

I've been using this extension for a while and I like it. But for Dockerfile, I prefer not to enable the auto formatting.

How to disable it?

Thanks.

@foxundermoon foxundermoon added configuration configutation question help wanted labels Jan 10, 2020
@foxundermoon
Copy link
Owner

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

@Eisbrenner
Copy link

Hi,

I, too, liked to disable the formatting for Dockerfiles since it removes \ at the end of lines, which breaks the files.

However, since I had format-on-save enabled, I needed to add

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

having either of those excluded from the settings would result in auto formatting of Dockerfiles.

@foxundermoon
Copy link
Owner

foxundermoon commented Mar 23, 2020

@Eisbrenner Maybe it was formatted by another plugin. You can check out docker related plugins.

@joemaller
Copy link

@foxundermoon Dropped backslashes in Dockerfiles seems to be happening upstream in shfmt. My Dockerfiles weren't formatting (because of Prettier?) until I explicitly enabled shell-format in settings.json with this:

    "[dockerfile]": {
        "editor.defaultFormatter": "foxundermoon.shell-format"
    }

After that, my Dockerfiles formatted, but all multi-line commands broke. Output from this extension (obviously?) is identical to output from shfmt.

Input

RUN yum -y -q update \
        && yum install -q -y zip

output

RUN yum -y -q update &&
	yum install -q -y zip

@joemaller
Copy link

Followup: This should be a known issue and was already mentioned here in #29 which referenced mvdan/sh#424

@texastoland
Copy link

texastoland commented Jun 5, 2020

@foxundermoon Your extension shouldn't manually format files. formatOnSave happens automatically when you register as a formatter. Could you please remove the following lines:

const formatOnSave = vscode.workspace.getConfiguration().get(formatOnSaveConfig);
if (formatOnSave) {
vscode.workspace.onWillSaveTextDocument((event: vscode.TextDocumentWillSaveEvent) => {
// Only on explicit save
if (event.reason === 1 && isAllowedTextDocument(event.document)) {
vscode.commands.executeCommand(formatDocumentCommand);
}
});
}

can you submit a pr?

br3ndonland added a commit to br3ndonland/dotfiles that referenced this issue Sep 18, 2020
foxundermoon/vs-shell-format#29
foxundermoon/vs-shell-format#62
mvdan/sh#424

The foxundermoon/vs-shell-format extension formats Dockerfiles, but it
shouldn't, because the underlying formatter mvdan/sh isn't engineered
for Dockerfiles. As explained in mvdan/sh#424,

> Removing the `\` is correct in shell, because a line ending in `&&`
> just continues the command in the following line.

This commit will disable Dockerfile formatting.
@bernardolm
Copy link

bernardolm commented Oct 8, 2020

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

Doesn't work for me. I also want to disable this weird Dockerfile formatter.

br3ndonland added a commit to br3ndonland/dotfiles that referenced this issue Nov 6, 2020
foxundermoon/vs-shell-format#29
foxundermoon/vs-shell-format#62
mvdan/sh#424

The foxundermoon/vs-shell-format extension formats Dockerfiles, but it
shouldn't, because the underlying formatter mvdan/sh isn't engineered
for Dockerfiles. As explained in mvdan/sh#424,

> Removing the `\` is correct in shell, because a line ending in `&&`
> just continues the command in the following line.

This commit will disable Dockerfile formatting.
@JounQin
Copy link

JounQin commented Mar 24, 2021

binaryNextLine is auto enabled in prettier-plugin-sh, you can use it if you are using prettier.

@bduffany
Copy link

bduffany commented Dec 22, 2021

@foxundermoon It looks like the manual formatting behavior mentioned in #62 (comment) is still in the code in master?

const formatOnSave = vscode.workspace.getConfiguration().get(formatOnSaveConfig);
if (formatOnSave) {
vscode.workspace.onWillSaveTextDocument((event: vscode.TextDocumentWillSaveEvent) => {
// Only on explicit save
if (event.reason === 1 && isAllowedTextDocument(event.document)) {
vscode.commands.executeCommand(formatDocumentCommand);
}
});
}

If I understand @texastoland's comment correctly, this code is causing the extension to ignore the user's editor.formatOnSave preference for the dockerfile language mode, which should be enough to disable the formatter. Folks shouldn't also need to remove dockerfile from shellformat.effectLanguages.

@Re-st
Copy link

Re-st commented Nov 21, 2023

I happened to have same issue. After some struggles I evaded the problem by installing Docker extension and setting dockerfile default formatter to the one given there.

@rucoder
Copy link

rucoder commented Nov 22, 2023

I managed to fix it adding following to my settings.json

    "[dockerfile]": {
        "editor.defaultFormatter": "foxundermoon.shell-format"
    },
   "shellformat.flag": "-bn"

@JounQin
Copy link

JounQin commented Nov 22, 2023

I think the solution should be well documented. Or it should be enabled by default for Dockerfile even better.

@Pointotech
Copy link

This extension should not be attempting to format Dockefiles, since it clearly isn't able to do so correctly and it doesn't seem to be the goal of this extension.

There should not be extra configuration required to avoid breaking files which this extension doesn't support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration configutation question help wanted
Projects
None yet
Development

No branches or pull requests