Add --print-defaults flag to print default fourmolu.yaml with comments#308
Conversation
|
👋 @jhrcek Reviewer: Please verify the following things have been done, if applicable.
|
brandonchinn178
left a comment
There was a problem hiding this comment.
Looks great, thanks! Some nits you are free to include, or I can merge without
| -- Only check prefix of the output, so we don't have to update the test with every new option added | ||
| stdOutput `shouldSatisfy` isPrefixOf "# Number of spaces per indentation step\nindentation: 4\n" |
There was a problem hiding this comment.
Mentioning this for posterity: we could do stdOutput shouldBe fourmoluYamlFourmoluStyle, but I actually like it this way, with a literal string showing a little bit what it should look like. It makes the test more robust, e.g. if fourmoluYamlFourmoluStyle was accidentally generated as an empty string. It also makes the test more meaningful, as opposed to just ensuring we hooked up everything correctly
There was a problem hiding this comment.
Yes, I considered it, but went with hardcoded string literal exactly for this reason, to have check independent of the String being generated.
| Starting with fourmolu 0.12.0.0 you can generate the default configuration file like this: | ||
|
|
||
| ```console | ||
| $ fourmolu --default-config > fourmolu.yaml |
There was a problem hiding this comment.
I think you meant --print-defaults here
There was a problem hiding this comment.
Yes, thank you! Feel free to put up a PR, or I can update it when I'm free
First attempt at implementing #307
At first I thought I could add ToJSON and just print the
defaultPrinterOptsserialized to Yaml.This has the downside of not telling you what are other valid values for each option. And I didn't find a way to render comments within Yaml using yaml library.
To get access at the info on valid values + also help text for each option I tried another approach:
I extended
Generate.hsto assemble output String corresponding to valid yaml from pieces already present inConfigData.hs. I added the resulting String to Gen.hs.But it feels a bit hacky. Let me know what you think or if you have any ideas how to do it in a less hacky way.
This is the result it produces: