Skip to content

Support automatic line breaking at column limit#305

Merged
brandonchinn178 merged 3 commits intofourmolu:mainfrom
CrystalSplitter:stacked-main
Mar 28, 2023
Merged

Support automatic line breaking at column limit#305
brandonchinn178 merged 3 commits intofourmolu:mainfrom
CrystalSplitter:stacked-main

Conversation

@CrystalSplitter
Copy link
Contributor

This is a revival of the work done in #102 by @gustavoavena

This feature is implemented as a hack, as described by @georgefst in Issue #71.

This breaks idempotency, which is an unfortunate limitation of this implementation. Open to making fixes for idempotency, but from the comments in #71, this seems to be okay given the utility and the warning.

@github-actions
Copy link

👋 @CrystalSplitter
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
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.

Small nits, let me know if you agree, or I can merge as-is

@CrystalSplitter CrystalSplitter force-pushed the stacked-main branch 2 times, most recently from 6b8d84b to 68cf957 Compare March 27, 2023 03:51
Copy link
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.

One last nit. Feel free to ignore.

@CrystalSplitter
Copy link
Contributor Author

CrystalSplitter commented Mar 27, 2023

Hold on, parsing issue.

Error in $['column-limit']: parsing ColumnLimit failed, expected String, but encountered Number.

May have broken it somewhere in my fixups...

@brandonchinn178
Copy link
Collaborator

@CrystalSplitter the adtParseJson implementation, I think.

Also, the tests apparently dont test that function... I'll have to think about how best to test it

@CrystalSplitter
Copy link
Contributor Author

The underlying issue here is that column limit can both be a String (none) and an Int during parsing.

Some solutions:

  • A real quick solution to this would be that 0 or lower is none. This is originally what it did at the very beginning, but it was requested that Gustavo change that. I think this option is fine, though weird from a user perspective.
  • Another solution is make a somewhat hacky parser that returns both the string "none" and an integer as a raw string. This is fine from a user perspective but weird for implementation.
  • And another solution is to write in the documentation that the integer has to be wrapped in quotes. I dislike this option.

@brandonchinn178
Copy link
Collaborator

Or just parse it directly?

parseJson = \case
  String "none" -> pure NoLimit
  Number x | Right i <- floatingOrIntegral x -> pure $ ColumnLimit i
  _ -> fail "Invalid ColumnLimit"

It'll slightly duplicate the adtParseText implementation, which I think is fine.

@CrystalSplitter
Copy link
Contributor Author

Done, but I had to include scientific in the depends. I noticed that there was a test that broke with that, so I patched that as well. I'm unsure if that was the right move, though.

gustavoavena and others added 3 commits March 26, 2023 22:36
This feature is implemented as a hack,
as described by George Thomas in Issue fourmolu#71.

Unfortunately, adding a column limit/max line
length right now is not idempotent. We mark
the feature with a warning accordingly in the README.

The actual logic changes of this commit are in:

* Ormolu/Printer/Combinators.hs
* Ormolu/Printer/Meat/Declaration/Value.hs

The rest is config changes, to surface this option.

Co-authored-by: CrystalSplitter <gamewhizzit@gmail.com>
We have to configure tests to ignore idempotency in
the PrinterOptsSpec, so we have to interpret examples
based on TestGroup context

This makes use of the existing input/output fourmolu
testing configuration.

Co-authored-by: Gustavo Avena <ggavena@gmail.com>
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