vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

double braces (for helm stuff) get a space put in between them

Open naseemkullah opened this issue 4 years ago • 16 comments

{{ become { { ... not desired

naseemkullah avatar Nov 11 '19 15:11 naseemkullah

We're using Go templates in YAML files - and the space insertion breaks them. Furthermore, type checking doesn't work where templates are used (e.g. if the template expands to an integer.

Is it possible to stop checking when encountering a {{ }} sequence ?

cfiderer avatar Jan 31 '20 08:01 cfiderer

Is it possible to stop checking when encountering a {{ }} sequence ?

I'm assuming you mean stop validating when {{}} are hit so that no error is reported? Technically it's possible but the problem is then we're implementing helm specific things into this extension when this extension is supposed to be only for pure yaml.

This extension has some support for helm that I think would be better suited: https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools you just need to change your file type association to helm and then the error dissapears

JPinkney avatar Jan 31 '20 14:01 JPinkney

Our stuff is not Helm-related - it just uses the YAML as input to the Go template engine. So for the time being, the file in question is not pure YAML yet.

So the question remains: how can I configure the vscode-yaml extension that I can use it also for "not pure YAML yet" files?

cfiderer avatar Jan 31 '20 14:01 cfiderer

how can I configure the vscode-yaml extension that I can use it also for "not pure YAML yet" files?

There's currently no way to do that, but it would be an interesting enhancement

JPinkney avatar Jan 31 '20 14:01 JPinkney

Hey all! I got around this by strong quoting (') my go templating and my helmfile still seems to render my helm chart properly when examed with helmfile -f path/to/helmfile.yaml diff.

Here's an example of what I mean:

-    namespace: {{ requiredEnv "NAMESPACE" }}
+    namespace: '{{ requiredEnv "NAMESPACE" }}'

I haven't tested this in a helm chart yet so I don't know if this change will work there (meaning I am not sure if this will be interpreted properly by the go templating parser).

Additionally, I am not sure if this will work for stuff like Jinja2 (I don't think so) so it might be worth just writing an exception for this plugin to just ignore {{ ...blah... }}.

unacceptable avatar Jun 12 '20 09:06 unacceptable

A simple solution now is close the bracketSpacing in Yaml Plugin.

{
    "yaml.format.bracketSpacing": false,
}

But this will get a 'side-effect', the space inside double braces also removed.

- {{.Values.node2}}

But at least it works now.

liyzcj avatar Nov 03 '20 08:11 liyzcj

"yaml.format.bracketSpacing": false,

Not working for me.

c0bra avatar Mar 17 '21 18:03 c0bra

@c0bra Try "prettier.bracketSpacing" instead.

a-ski avatar Mar 21 '21 00:03 a-ski

@AdamPodolski's suggestion worked for me ("prettier.bracketSpacing": false).

An alternative solution is to use a .prettierignore file with *.yaml inside, which will still allow Prettier to add bracket spacing on other file types.

Really wish they didn't remove the disableLanguages config from prettier-vscode!

coopbri avatar Mar 29 '21 01:03 coopbri

"yaml.format.bracketSpacing": false,

Not working for me.

It's not work because you may using prettier as your yaml formatter, you can change your yaml formatter with

    "[yaml]": {
        "editor.defaultFormatter": "redhat.vscode-yaml",
    }

or use @AdamPodolski 's suggestion "prettier.bracketSpacing": false, but the side effect is all languages formatted with prettier will ignore bracket spacing.

liyzcj avatar Mar 30 '21 06:03 liyzcj

I created ~/.prettierignore file, added *.yaml, *.yml to it, then updated vscode User setting "prettier.ignorePath": "~/.prettierignore".

skyward-luke avatar Apr 21 '21 08:04 skyward-luke

Pain in the neck.

gcsfred2 avatar Feb 16 '22 19:02 gcsfred2

Previously, i saw the above behaviour, but with "prettier.bracketSpacing": false I now see this...

{{ include (print $.Template.BasePath "/configMap.yaml") . | sha256sum }}

Format to this...

    {
      {
        include (print $.Template.BasePath "/configMap.yaml") . | sha256sum,
      },
    },

ben-walters avatar Aug 08 '22 09:08 ben-walters

It seems that go-style templating of yaml files is just too common in kubernetes world... What this issue is about, I think, is devex, meaning, if I pick some existing codebase and make some small changes to it, I don't want my tools to break existing conventions. And FWIW k8s is kinda popular. Some kind of copout is needed.

P.S. '{{ val }}' is not an answer, because some values must be of specific type, not strings.

dimaqq avatar Sep 17 '23 08:09 dimaqq

So, still no solution without side effects found? The recommended "prettier.bracketSpacing": false produces this side effect:

But this will get a 'side-effect', the space inside double braces also removed.

That is very annoying!

Please add an option like prettier.bracketSpacing.ignore that will skip all formatting of the bracket spacing!

MurzNN avatar Apr 15 '24 05:04 MurzNN