Revisit if-else comment indentation
- Dominant language
- Haskell
- Stars
- 1.3k
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
I realize this has been discussed in #251 and #280, but I wanted to reopen the discussion considering more recent changes to conditional formatting.
Specifically, elm-format now puts a newline between if-else branches, the same as is done for case-of branches, reinforcing the similar function of these two code structures. Comments preceding case-of patterns are indented to the same depth, however, as established in the previous two issues, for if-else statements, they are instead re-indented to the depth of whatever statement proceeds the `else`. (In contrast, attempting to use this trailing comment style with a case-of statement re-indents the comment to the depth of the next pattern!) This is a surprising discrepancy, and can require moving comments around if one replaces a case-of with an if-else, etc.
Further, I find it reasonable to want to comment the code in the condition and the code in the first line of the branch body separately, using two separate comment blocks (and, ideally, two distinct indent levels) to establish a visual distinction between the comments' purposes. This, however, is not possible with if-else unless one adheres to trailing comment blocks (which, as noted, can't be used with case-of).
Given that there's now a *required* newline between branches, I respectfully recommend detecting which side of the newline the comment is on for both if-else and case-of statements, indenting it accordingly.
Contributor guide
No contributing guide indexed for this repository
Research direction
No files, tests, or entry points are named. Begin by locating the formatter logic for if-else and case-of comment indentation, then compare their current behavior with the proposed newline-side rule. Done means the indentation behavior is consistent for both constructs and covered by relevant formatter tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100