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

Apply Yaml pre-commit formatter #1689

Merged
merged 4 commits into from
Jun 14, 2022
Merged

Apply Yaml pre-commit formatter #1689

merged 4 commits into from
Jun 14, 2022

Conversation

bendnorman
Copy link
Member

Folks have different YAML formatters in our code editors so we need a pre-commit hook to do the formatting for us!

@bendnorman
Copy link
Member Author

Doesn't seem like there are any yaml formatting pre-commit hooks that are amenable to our current yaml formatting. I found three options:

  • yamlfix: Opinionated formatted that can't be configured.
  • yamlfmt: Formatterr than can be configured but I couldn't figure out options to recreate our current formatting.

@zaneselvans what yaml formatter are you using?

@bendnorman bendnorman mentioned this pull request Jun 14, 2022
@zaneselvans
Copy link
Member

I've been doing the formatting by hand, but then occasionally VS Code or gvim seems to have strong opinions about indentation. It looks like with yamlfix we have the option of lists being condensed (if we use [x, y, z] or having a single element per line if we use the - to indicate each one. I don't totally love it but at least it would be guaranteed to be uniform for everyone which is the most important thing.

@zaneselvans
Copy link
Member

Poking around to try and find a way to integrate yamlfix into VS Code I found this extension from RedHat which lints and autoformats, and also checks the YAML against published schemas if they can be detected, which seems like it would be nice. I wonder if we can make it format along the lines of yamlfix.

@zaneselvans
Copy link
Member

Not totally sure what the conflict is in the pre-config settings because the whole file was re-written.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@bendnorman
Copy link
Member Author

https://prettier.io/ is also an option. It offers a pre-commit and a vscode extension but it can't be configured like the red hat extension. The Red Hat extension doesn't offer a pre-commit or command-line tool.

@bendnorman
Copy link
Member Author

bendnorman commented Jun 14, 2022

Ooo I like prettier:

  • It retains our - formatting for the settings files.
  • It's by far the most established YAML formatter I've found (42k stars).
  • Has a popular VSCode extension.

One con is that it puts each year on its own line in the settings files.

@zaneselvans
Copy link
Member

Widespread support seems like a strong reason to use it.

It seems like it's putting years on individual lines sometimes but not others and I'm not sure why.

I'm fine with whatever you choose! The most important thing is we can have something standardized and well supported.

@bendnorman
Copy link
Member Author

Changes:

  • Add prettier pre-commit hook for consistent YAML formatting.

@bendnorman bendnorman merged commit 4a447d7 into dev Jun 14, 2022
@bendnorman bendnorman deleted the yaml-formatter branch June 14, 2022 22:34
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

Successfully merging this pull request may close these issues.

2 participants