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: Replace = symbols by : symbols where syntactically correct #2979

Open
jfmengels opened this issue Apr 12, 2024 · 2 comments
Open
Labels
help wanted Contributions encouraged priority:medium

Comments

@jfmengels
Copy link

I'm learning Gleam, and sometimes it's hard to remember to use = or : in some cases, especially for record expressions.

pub fn new(name: String) {
  Thing(
    name = name, // should have `:`
  )
}

A nice thing that elm-format does for Elm files, is to transform = to : (and the reverse) where appropriate. This is a time-saver and very nice for beginners. For instance, I have several times taught Elm to beginners, and when they would use the incorrect symbol, then save, the symbol would be fixed without them even noticing (or seeing an error message).

I don't know in how many places this kind of change could be applied, I think it could at least be done reliably in record expressions, maybe as well in type annotations.

@lpil
Copy link
Member

lpil commented Apr 17, 2024

Sounds good! Though I would want compilation to still error for these.

It can be done for labelled arguments but I don't think it could be done for annotations as it would be ambiguous or prevent us from adding defaults in future.

@lpil lpil added help wanted Contributions encouraged priority:medium labels Apr 17, 2024
@jfmengels
Copy link
Author

jfmengels commented Apr 17, 2024

Though I would want compilation to still error for these.

Absolutely.

I don't think it could be done for annotations as it would be ambiguous or prevent us from adding defaults in future.

It it's ambiguous, indeed it should not be done. I don't think this will prevent from adding defaults or other syntaxes in the future. At that point, the formatter should stop doing this transformation, as it will become ambiguous or unhelpful.

I don't think this should be considered as a breaking change in any way, since it doesn't impact the formatting of correct Gleam modules, so in my understanding it should be entirely fine to remove this when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

2 participants