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

Formatter: make long functions in type annotations easier to read #2988

Open
jfmengels opened this issue Apr 14, 2024 · 2 comments
Open

Formatter: make long functions in type annotations easier to read #2988

jfmengels opened this issue Apr 14, 2024 · 2 comments
Labels
discussion The approach has not yet been decided

Comments

@jfmengels
Copy link

In the following function, I find it hard to read the type for get_visitor, especially that get_visitor is a function.

fn apply_visitor(
  a: a,
  rules: List(rule.ModuleVisitorOperations),
  get_visitor: fn(rule.ModuleVisitorOperations) ->
    option.Option(fn(a) -> rule.ModuleVisitorOperations),
) -> rule.ModuleVisitorOperations {
  todo
}

My suggestion:

fn apply_visitor(
  a: a,
  rules: List(rule.ModuleVisitorOperations),
  get_visitor:
    fn(rule.ModuleVisitorOperations) -> // arrow either here, or on the next line (à la elm-format)
       option.Option(fn(a) -> rule.ModuleVisitorOperations),
) -> rule.ModuleVisitorOperations {
  todo
}
@lpil
Copy link
Member

lpil commented Apr 15, 2024

I'm not so sure about this one- I don't find it any easier to read. Could it be this is what you are familiar with rather than it being better?

Would this also apply to let and use and other annotations rather than just functions? Currently we are consistent everywhere with this formatting.

Interested in hearing what others have to say.

@lpil lpil added the discussion The approach has not yet been decided label Apr 15, 2024
@han-tyumi
Copy link

I find with the proposed change that the function type is more "together" as you would expect to see it if it were on its own.

I don't think it's a huge difference, but I do find the extra whitespace makes it a bit easier to read the whole function type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion The approach has not yet been decided
Projects
None yet
Development

No branches or pull requests

3 participants