Crystal: It would be nice if the crystal formatter fixed space required after colon in type restriction

Created on 2 Nov 2019  路  2Comments  路  Source: crystal-lang/crystal

I often forget to put a space after a colon... for example

  def area(r:Room)
  end

It would be nice if the crystal formatter just fixed that for me instead of complaining about it.
If it can complain about it, it should be able to fix it.

feature someday topicformatter

Most helpful comment

Yes we could. And it might be useful. But IMO it should have low priority. It's a quality of life feature but not very important.

All 2 comments

We _could_ do this.

The thing is, the formatter works like this:

  1. it parses the source code
  2. it traverses the AST produced in 1 while also lexing the code, to format it

but step 1 already fails for area(r:Room) as a syntax error, so there's no way we can fix it in step 2

That is, unless in step 1 we say "allow that to be a valid syntax" and then we fix it. But it's a bit strange, the formatter doesn't do that at all in any case.

Thoughts?

Yes we could. And it might be useful. But IMO it should have low priority. It's a quality of life feature but not very important.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lgphp picture lgphp  路  3Comments

asterite picture asterite  路  3Comments

asterite picture asterite  路  3Comments

grosser picture grosser  路  3Comments

relonger picture relonger  路  3Comments