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

Exclude is still a little bit wonky #139

Open
esn89 opened this issue Sep 25, 2023 · 8 comments
Open

Exclude is still a little bit wonky #139

esn89 opened this issue Sep 25, 2023 · 8 comments

Comments

@esn89
Copy link

esn89 commented Sep 25, 2023

I have yamlfmt installed via nvim mason and it resides in ~/.local/share/nvim/mason/bin.

I have a file named env-config.yaml located in

/Users/esn89/Documents/Projects/helm-charts/application.git/develop/services/superapp/templates

which looks like this:

apiVersion: v1
data:
  PROJECT: {{ .Values.project }}
  JOB_NAME: {{ .Values.jobName }}

kind: ConfigMap
metadata:
  namespace: {{ .Values.namespace }}

I ran ~/.local/share/nvim/mason/bin/yamlfmt -conf ~/.config/nvim/.yamlfmt env-config.yaml and it formats my file to look like this:

---
apiVersion: v1
data:
  PROJECT: {? {.Values.project: ''} : ''}
  JOB_NAME: {? {.Values.jobName: ''} : ''}
kind: ConfigMap
metadata:
  namespace: {? {.Values.namespace: ''} : ''}

These is really strange, as I have set the **template/*.yaml path to be excluded.

My ~/.config/nvim/.yamlfmt looks as follows:

doublestar: true
exclude:
  - "/Users/esn89/Documents/Projects/**/templates/*.yaml"
  - "/Users/esn89/Documents/Projects/**/.gitlab-ci.yml"
formatter:
  type: basic
  indent: 2
  include_document_start: true

Any ideas?

@braydonk
Copy link
Collaborator

I think this is coming down to excludes being absolute paths again. When passing the path into the argument, then the included path is env-config.yaml which according to doublestar does not match /Users/esn89/Documents/Projects/**/templates/*.yaml.

I still don't handle mixed absolute path/relative path excludes well. I note it in the docs. Likely what I should do is check whether either one is an absolute path, and if one is then convert the other. But I would need to test that thoroughly to make sure it works in all scenarios.

Either way I can see how this sucks for the editor plugin use-case; usually the content is just passed to yamlfmt through stdin, with no path-awareness other than the current working directory. I'll try to find a way to address this too.

As a short-term workaround, you can use ignore metadata on this file, which I know is not ideal but still should work for this usecase.

@esn89
Copy link
Author

esn89 commented Sep 26, 2023

I see. So from what I've read the paths need to be specified as relative to where the yamlfmt binary is, right?

https://github.com/google/yamlfmt/blob/main/docs/paths.md#include-and-exclude

@braydonk
Copy link
Collaborator

Not relative to where the yamlfmt binary is, rather relative to the current working directory that yamlfmt is run from, which in most cases would be the project directory, or in neovim the directory that you have open (I think).

Starting with ** can help here, since that just means "any directory/directories appearing until the next thing in the match".

@esn89
Copy link
Author

esn89 commented Sep 26, 2023

So something like this, @braydonk ?

doublestar: true
exclude:
  - "**/templates/*.yaml"
  - "/Users/esn89/Documents/Projects/**/.gitlab-ci.yml"
formatter:
  type: basic
  indent: 2
  include_document_start: true

@braydonk
Copy link
Collaborator

Yeah, I think if your neovim is open in a folder that has a templates subfolder somewhere in it, then any yaml file in it should be excluded. But I'm not 100% sure, I've never tried this exact use case.

@esn89
Copy link
Author

esn89 commented Sep 26, 2023

Great, thanks.

@esn89
Copy link
Author

esn89 commented Sep 29, 2023

@braydonk

Hey, just an idea. Even if exclude is a bit wonky, that's alright, as long as there is a way to have yamlfmt not mess with anything similar to: {{ .Values.helmstuff }}. Is there such a config/setting?

@braydonk
Copy link
Collaborator

Unfortunately not, and any way I can think of to add one would be challenging. That syntax from the helm charts is Go templating. The yaml library that yamlfmt uses for formatting is not built to recognize this syntax since it's compliant only to the YAML spec. So yamlfmt can't actually recognize the syntax difference in any way today (and even if it could wouldn't know how to operate differently on it).

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

No branches or pull requests

2 participants