google / yamlfmt

An extensible command line tool or library to format yaml files.
Apache License 2.0
1.2k stars 48 forks source link

Ability to have end stream token #194

Open alexandrebrg opened 4 months ago

alexandrebrg commented 4 months ago

Hello :wave:

yamlfmt allows to have the start token ---, but doesn't yet allow for end token .... That would be very useful for projects where this is needed, as for now yamlfmt will just remove the end token, making projects linters fail.

Implementation would be similiar to include_document_start.

alexandrebrg commented 4 months ago

I'd be happy to help if needed :)

braydonk commented 4 months ago

Hi @alexandrebrg thanks for the feature request! I think it makes sense.

I think the only way to do this where yamlfmt actually handles multi-document files properly is to modify the yaml library. It shouldn't be too difficult, I forget if in the Node data structure there is an end to the document, but I am reasonably certain that it should work by adding something to the function that triggers on a yaml_DOCUMENT_END_EVENT here: https://github.com/braydonk/yaml/blob/10bcc859418b821726f51e2beb7406449cf0b4a2/emitterc.go#L499-L527 If you are willing to give it a shot I would certainly encourage it! My time is even more limited to work on this project recently. I'll be happy to review any PRs to braydonk/yaml and can tag a new release whenever it gets merged so it can be used in yamlfmt.