Skip to content

Add --print-defaults flag to print default fourmolu.yaml with comments#308

Merged
brandonchinn178 merged 9 commits intofourmolu:mainfrom
jhrcek:jhrcek/print-defaults
Apr 3, 2023
Merged

Add --print-defaults flag to print default fourmolu.yaml with comments#308
brandonchinn178 merged 9 commits intofourmolu:mainfrom
jhrcek:jhrcek/print-defaults

Conversation

@jhrcek
Copy link
Copy Markdown
Contributor

@jhrcek jhrcek commented Apr 1, 2023

First attempt at implementing #307

At first I thought I could add ToJSON and just print the defaultPrinterOpts serialized 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.hs to assemble output String corresponding to valid yaml from pieces already present in ConfigData.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:

$ stack --stack-yaml stack-ghc-9.2.yaml exec fourmolu -- --print-defaults
# Number of spaces per indentation step
indentation: 4

# Styling of arrows in type signatures (choices: trailing, leading, or leading-args)
function-arrows: trailing

# How to place commas in multi-line lists, records, etc. (choices: leading or trailing)
comma-style: leading

# Styling of import/export lists (choices: leading, trailing, or diff-friendly)
import-export-style: diff-friendly

# Whether to full-indent or half-indent 'where' bindings past the preceding body
indent-wheres: false

# Whether to leave a space before an opening record brace
record-brace-space: false

# Number of spaces between top-level declarations
newlines-between-decls: 1

# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact)
haddock-style: multi-line

# How to print module docstring
haddock-style-module: null

# Styling of let blocks (choices: auto, inline, newline, or mixed)
let-style: auto

# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space)
in-style: right-align

# Output Unicode syntax (choices: detect, always, or never)
unicode: never

# Give the programmer more choice on where to insert blank lines
respectful: true

# Fixity information for operators
fixities: []

# Whether to put parentheses around a single constraint (choices: auto, always, or never)
single-constraint-parens: always

# Max line length for automatic line breaking
column-limit: none

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2023

👋 @jhrcek
Thank you for raising your pull request.
Please make sure you have followed our contributing guidelines in DEVELOPER.md. We will review it as soon as possible!

Reviewer: Please verify the following things have been done, if applicable.

  • A file has been added to changelog.d/
  • "Configuration > Available options" section in README.md has been updated
  • "Configuration > Specifying configuration" section in README.md has been updated
  • Tests have been added

Copy link
Copy Markdown
Collaborator

@brandonchinn178 brandonchinn178 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! Some nits you are free to include, or I can merge without

Comment on lines +51 to +52
-- 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"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant --print-defaults here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you! Feel free to put up a PR, or I can update it when I'm free

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.

3 participants