Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Add preset options #300

Open
brandonchinn178 opened this issue Mar 8, 2023 · 6 comments · May be fixed by #364
Open

RFC: Add preset options #300

brandonchinn178 opened this issue Mar 8, 2023 · 6 comments · May be fixed by #364

Comments

@brandonchinn178
Copy link
Collaborator

brandonchinn178 commented Mar 8, 2023

Add a new flag/config option --preset that specifies the default values of unspecified options. This enables certain, blessed option sets for various use cases. Possible presets:

  • fourmolu: The current default Fourmolu options (also the default preset if none is specified)
  • ormolu: Options that emulate Ormolu settings
  • diff-friendly: Options that aim to be as diff-friendly as possible
  • aligned: Options that aim for everything to be as aligned as possible

If an option isn't directly related to the preset (e.g. indentation for diff-friendly), it'll be set the same as fourmolu.


"Fourmolu already uses diff-friendly formatting by default, what's the point of the diff-friendly preset?"

As we've been adding more options, we (the maintainers) have been pushing for option defaults to not change current formatting, to prevent breaking current formatting and maintain some notion of stability. If we add a new foo option tomorrow with a diff-friendly setting, we'd want the default to not change existing formatting (or at least have it be opt-in, a la let-style: auto). But a user might explicitly want to opt in to the maximally diff-friendly setting, even if formatting changes over an upgrade. So with presets, we'd be able to say that fourmolu has no (or very rarely) formatting changes on upgrade (aside from changes we get from ormolu), and other presets would get the cutting edge updates.


Other notes:

  • Optionally, we could also allow preset to be a list, with latter preset values overriding earlier presets
  • Adding a new configuration would now need to specify the default for fourmolu (as non-breaking as possible), the setting to emulate ormolu, and also the setting for all other presets.
  • We could also add a edge preset that contains new fourmolu values for the next major Fourmolu version bump (if we ever wanted to do so)

Related: #128

@feature-not-a-bug
Copy link

Having the presets be a list seems like it might be difficult to work with. If multiple presets change in a release it could cause some surprising changes in the output. My opinion is a preset should have a particular purpose in mind and diff-friendly first and aligned as a second concern (or vice versa) just seems like it would be trying to accomplish contradictory goals. Ormolu also seems like one that wouldn't play well with others.

I'd vote to keep it simple and only allow a single selection. If a user wants to create a mixed set of flags it's easy enough to set up a config.

@brandonchinn178 brandonchinn178 changed the title Add preset options RFC: Add preset options Mar 8, 2023
@dpwiz
Copy link

dpwiz commented Mar 9, 2023

It would be better to name the fourmolu preset explicitly. Using --preset default sets no expectations for the result (and looks silly). No shame in naming the style you use after yourself 😄

@brandonchinn178
Copy link
Collaborator Author

@feature-not-a-bug are you opposed to diff-friendly/aligned as presets altogether, or just in the context of not trying to mix them with the ormolu/fourmolu presets?

@georgefst:

  • I see a 👎 from you about --preset default vs --preset fourmolu. What are your thoughts? Do you prefer --preset default?
  • Thoughts on the edge preset?
  • Thoughts on diff-friendly/aligned preset? (as a single preset, not in the allow-multiple-presets context)
  • Any other concerns about this change?

@feature-not-a-bug
Copy link

I like the idea of the presets themselves, and my apprehension is only in mixing presets

@brandonchinn178
Copy link
Collaborator Author

hm or alternatively an extends option that could also be a URL that downloads a YAML config? Then the fourmolu repo could just have a bunch of YAML configs for various configurations, and people could even host their own configs (and if any get popular enough, we could always merge them in)

@brandonchinn178
Copy link
Collaborator Author

Took a stab at this in #364. Any feedback would be appreciated!

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 a pull request may close this issue.

3 participants