Skip to content

v0.11.0

Compare
Choose a tag to compare
@github-actions github-actions released this 10 Feb 14:39
· 9 commits to main since this release
449dacb

Oops, all features!

https://www.youtube.com/watch?v=cXBX2PumuBk

It's been a while since the last release! Life has kept me very busy, but since there were a number of feature requests in the issue queue that weren't too challenging to implement I knocked a bunch of them off the list! I also came up with one feature for this release myself.

Config Discovery Enhancements

Two major enhancements to config discovery! I am pretty sure they are purely additive and shouldn't break any existing workflows, but don't hesitate to open an issue if there's something I missed.

Config file can be .yamlfmt, yamlfmt.yaml, or yamlfmt.yml

Instead of forcing the .yamlfmt hidden file name, the command will also recognize yamlfmt.yaml or yamlfmt.yml as a valid file name. (Note that this only applies to automatic config searching; it has never mattered what the name of a file specified directly in the -conf flag is.)

Config file search goes all the way up the directory tree

Instead of only looking for a yamlfmt config in the working directory, it will look at every directory up from the current directory and use the nearest config file it can find. If it doesn't find one all the way up the tree, then it will default to the config file in the global location at $XDG_CONFIG_HOME/yamlfmt (LOCALAPPDATA on Windows). This should be useful for monorepo scenarios, where you might want to apply a single yamlfmt config file to a number of projects within the monorepo, instead of needing a config file in every sub-project or having to manually specify with -conf.

This does change some potential scenarios where previously the global config would have been discovered. To combat this, I added a new command line flag -global_conf that will force using the config from the global location.
Similarly, I added -no_global_conf to force not using the global config.

Use a .gitignore for excludes

The -gitignore_excludes or gitignore_excludes top-level config option will allow yamlfmt to use patterns from a .gitignore file for excluding files from formatting! This should be helpful for scenarios where you previously would have needed to repeat all of these patterns in your own yamlfmt excludes config. You can also specify a specific path to a .gitignore file with -gitignore_path or gitignore_path (command/config respectively).

Retain only single line breaks

Sometimes you have yaml files where there are lots of line breaks in a row. Sometimes you want to keep those, but sometimes you only want to keep a single one out of a group. The new formatter-level config option retain_line_breaks_single will make it so this:

a: 1


b: 2

Formats to this:

a: 1

b: 2

Debug Logging

(This is the one I came up with)

By default yamlfmt is deliberately very quiet on output. This did have a negative though, as even in verbose mode it was hard to figure out which config file was used, or why files may have been excluded/included in formatting. Introducing the -debug command line flag! Currently there are two debug logging profiles:

  • The config profile will log the config file discovery process so you can figure out which config file was used and why
  • The paths profile will log the include/exclude process to understand exactly which paths are included/excluded and why

Read more about usage in the docs: https://github.com/google/yamlfmt/blob/v0.11.0/docs/command-usage.md#debug-logging

Conclusion

I knocked out a good number of the issues that aren't rooted in the yaml parsing/formatting portion of the tool (only one outlier that I'll address soon). This means my future focus is on how to solve some of the weird yaml problems. Right now it is looking like the main way for me to address these issues is by finally biting the bullet and writing my own. I decided to address a number of features this release to make sure I don't leave open issues out to dry while I dive into this new challenge.

As always, don't hesitate to open an issue if you have any problems!