Skip to content

v0.9.0

Compare
Choose a tag to compare
@github-actions github-actions released this 02 Apr 15:05
· 25 commits to main since this release
3a03733

The Content Analyzer Release

Biggest release in a long time! Had lots of spare time to fix some stuff that has been requested for a while, as well as some stuff that came up during the work on this release.

Features

Downgrade to Go 1.18

This is the most disruptive change, although I hope it won't affect anyone too much. Previously, yamlfmt was using Go 1.19 and then Go 1.20. I wasn't actually using any features from Go 1.19, and only errors.Join from Go 1.20. Since I now support installing as a pre-commit hook, and some folks still go through go install to install yamlfmt, I figured it would be in everyone's best interest to support a lower minimum version. I still make use of generics and would like to continue to, so I went with Go 1.18 as the minimum required version.

Better Docs

The docs have been cleaned up quite a bit and should be easier to navigate. I'm still considering moving over to using the GitHub Wiki feature, but right now it's really convenient to have the docs living with the code and there's a chance I might opt for a documentation site instead. I'll keep thinking about this!

Content Analyzer

A new construct has been added in this release, the ContentAnalyzer. This is an interface designed for performing actions based on the contents of the discovered yaml files. In this release, the only action currently possible is excluding yaml files based on their content instead of just exclude patterns. I added two ways to do this.

Metadata

In the yamlfmt library a new construct has been added called Metadata. See the Metadata docs for more information. This was created in this release to support the first type of Metadata, ignore:

# !yamlfmt!:ignore

If this metadata is detected in the document, yamlfmt will exclude it from formatting.

Exclude files by content regex (#101)

The other way is through a new command configuration called regex_exclude. Using Golang regexes, you can now provide a regex for yamlfmt to match with each files contents. For example, if you generate yaml files with a header comment:

# generated by: my awesome tool

You can provide the following regex_exclude:

regex_exclude:
- ".*generated by.*"

This will cause any file with that header comment to be excluded from formatting.

Configure yamlfmt through the CLI (#88)

This one has been requested for a while and I've wanted to do it for a while but never could think of a nice way to do it based on how I'd chosen to implement configuration. I've settled on an implementation that I think will work pretty well, and doesn't rock the boat too much. This should be easier for folks using yamlfmt directly in CI, removing the need for a .yamlfmt file if you'd like not to.

Drop Merge Tags (#102)

yamlfmt used to always add a !!merge tag explicitly:

a: &a
b:
 !!merge <<: *a

This release adds a formatter configuration option called drop_merge_tag, that when true will ensure this tag is excluded:

a: &a
b:
 <<: *a

Pad Line Comments (#104)

By default, yamlfmt will put one space between line contents and the comment on that line. The new formatter configuration option called pad_line_comments will allow you to configure the number of spaces that the yaml library uses to pad line comments.
i.e. with pad_line_comments: 1

a: 1 # comment

And with pad_line_comments: 2

a: 1  # comment

Bug Fixes

Absolute paths in doublestar exclude patterns (#97)

Providing an absolute system path in your exclude patterns would previously not match in most scenarios. This has been fixed, and absolute paths like /home/user/**/ignore_this_file.yaml should work now.

Contributors

Thank you @badouralix for all the new suggestions this release, as well as contributing a bugfix in CLI configuration (#100 which I'm glad was found before release), and the pad_line_comments feature!


This ended up being a large release because I had some free time to really catch up on the features I've wanted to include for a while. Now that I've settled up some of these feature gaps, I'm going to spend my time mainly on improving the testing in this repo. I plan on setting up some end-to-end tests to improve my verification of release (which right now is just me running the command a bunch of different ways). I also want to finally properly godoc all the types at least in the main yamlfmt library section. I will still be addressing bugfixes, but feature work may get put on hold unless there's really low-hanging fruit or someone else is willing to contribute them. Thanks as always for using the tool and providing your feedback!