Skip to content

Add single source of truth for JSON/CLI configuration#150

Merged
brandonchinn178 merged 12 commits intomainfrom
options
May 31, 2022
Merged

Add single source of truth for JSON/CLI configuration#150
brandonchinn178 merged 12 commits intomainfrom
options

Conversation

@brandonchinn178
Copy link
Copy Markdown
Collaborator

@brandonchinn178 brandonchinn178 commented Jan 24, 2022

Resolves #50

Help text:

-  --indentation WIDTH      Number of spaces per indentation step (default '4')
-  --comma-style STYLE      How to place commas in multi-line lists, records etc:
-                           'leading' or 'trailing' (default 'leading')
+  --indentation WIDTH      Number of spaces per indentation step (default: 4)
+  --comma-style STYLE      How to place commas in multi-line lists, records,
+                           etc. (choices: "leading" or "trailing")
+                           (default: "leading")
   --indent-wheres BOOL     Whether to indent 'where' bindings past the preceding
                            body (rather than half-indenting the 'where' keyword)
-                           (default 'false')
+                           (default: False)
   --record-brace-space BOOL
                            Whether to leave a space before an opening record
-                           brace (default 'false')
+                           brace (default: False)
   --diff-friendly-import-export BOOL
                            Whether to make use of extra commas in import/export
-                           lists (as opposed to Ormolu's style) (default 'true')
+                           lists (as opposed to Ormolu's style) (default: True)
   --respectful BOOL        Give the programmer more choice on where to insert
-                           blank lines (default 'true')
-  --haddock-style STYLE    How to print Haddock comments: 'single-line' or
-                           'multi-line' (default 'multi-line')
+                           blank lines (default: True)
+  --haddock-style STYLE    How to print Haddock comments (choices: "single-line"
+                           or "multi-line") (default: "multi-line")
   --newlines-between-decls HEIGHT
                            Number of spaces between top-level declarations
-                           (default '1')
+                           (default: 1)

Config parse failure:

# old
Failed to load fourmolu.yaml:
Aeson exception:
Error in $['comma-style']: parsing Ormolu.Config.CommaStyle failed, expected one of the tags ["leading","trailing"], but found tag "asdf"

# new
Failed to load fourmolu.yaml:
Aeson exception:
Error in $['comma-style']: unknown value: "asdf"
Valid values are: "leading" or "trailing"

CLI parse failure:

# old
$ stack exec -- fourmolu --comma-style=asdf
option --comma-style: unknown value: 'asdf'
Valid values are: 'leading' or 'trailing'.

# new
$ stack exec -- fourmolu --comma-style=asdf
option --comma-style: unknown value: "asdf"
Valid values are: "leading" or "trailing"

If you're curious about the splices:

Ormolu/Config.hs:177:14-36: Splicing expression
    allNothing 'PrinterOpts
  ======>
    (((((((PrinterOpts Nothing) Nothing) Nothing) Nothing) Nothing)
        Nothing)
       Nothing)
      Nothing
Ormolu/Config.hs:198:17-55: Splicing pattern
    unpackFieldsWithSuffix 'PrinterOpts "0"
  ======>
    PrinterOpts poIndentation0 poCommaStyle0 poIndentWheres0
                poRecordBraceSpace0 poDiffFriendlyImportExport0 poRespectful0
                poHaddockStyle0 poNewlinesBetweenDecls0
Ormolu/Config.hs:(349,6)-(352,7): Splicing expression
    mkBijectiveMap
      [('HaddockSingleLine, "single-line"),
       ('HaddockMultiLine, "multi-line")]
  ======>
    Ormolu.Config.TH.BijectiveMap
      {parseTextWith = \case
                         "single-line" -> Right HaddockSingleLine
                         "multi-line" -> Right HaddockMultiLine
                         unknown_aiad
                           -> ((Left . unlines)
                                 $ [("unknown value: " <> show unknown_aiad),
                                    ("Valid values are: " <> ""single-line" or "multi-line"")]),
       showTextWith = \case
                        HaddockSingleLine -> "single-line"
                        HaddockMultiLine -> "multi-line",
       Ormolu.Config.TH.getAllOptions = ["single-line", "multi-line"]}

You can try the following things to make mkBijectiveMap fail:

  • Add a Foo constructor to CommaStyle
  • Change 'Trailing to 'HaddockSingleLine
  • Add a String argument to Trailing

@brandonchinn178 brandonchinn178 force-pushed the options branch 8 times, most recently from 6844866 to d816b6c Compare January 25, 2022 05:45
@brandonchinn178 brandonchinn178 marked this pull request as ready for review January 25, 2022 05:48
@brandonchinn178 brandonchinn178 force-pushed the options branch 3 times, most recently from 185cc17 to f40a445 Compare January 27, 2022 05:28
@brandonchinn178
Copy link
Copy Markdown
Collaborator Author

@georgefst would be great to get your thoughts on this

@brandonchinn178 brandonchinn178 force-pushed the options branch 2 times, most recently from e2047a6 to 7dabddc Compare April 17, 2022 22:11
@brandonchinn178 brandonchinn178 force-pushed the options branch 3 times, most recently from c35bcc2 to 06194cb Compare May 15, 2022 22:50
@brandonchinn178 brandonchinn178 force-pushed the master branch 10 times, most recently from d85cd0c to 3a667cc Compare May 18, 2022 19:20
@brandonchinn178 brandonchinn178 force-pushed the options branch 2 times, most recently from d2c71da to 5a6f620 Compare May 30, 2022 21:40
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.

Consistency between CLI and YAML config

1 participant