gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.16k stars 714 forks source link

Formatter: Replace = symbols by : symbols where syntactically correct #2979

Open jfmengels opened 4 months ago

jfmengels commented 4 months ago

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 commented 4 months ago

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.

jfmengels commented 4 months ago

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.