nebulab / erb-formatter

Format ERB files with speed and precision
MIT License
135 stars 22 forks source link

Improve formatting of multiline ERB #56

Open pelletencate opened 2 months ago

pelletencate commented 2 months ago

I totally didn't notice the existence of #7 and did my own implementation of better multiline ERB.

This PR does 2 things:

  1. Subtract the indentation level from Syntax Tree line width
    • This could be even further improved: line length should take ERB tag start and end tag overhead in consideration
  2. Change the way multiline ERB is formatted. It will do the following:
    • If formatted ruby yields more than 1 line, then:
      • The ERB tag start and end will be on separate lines
      • The entire Ruby code will be indented with an additional 2 spaces
      • If a mulit-line comment has its own (arbitrary) indentation, properly indent the entire comment underneath the ERB tags, preserving relative indentation

(Due to the fact that I was adding to repetitive logic, I chose to optimize the case statement. If this is undesirable and we prefer even more repetition, I'm OK with having that refactored back)

pelletencate commented 2 months ago

Oh @elia I completely missed #7 and went my own way with this one.