-
Notifications
You must be signed in to change notification settings - Fork 7
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
Format source code with current gren format #11
base: gren-0.2.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
module Main exposing (main) | ||
module Main exposing ( main ) | ||
|
||
import Browser | ||
import Html exposing (Html) | ||
import Html exposing ( Html ) | ||
import Html.Attributes as Attribute | ||
import Html.Events as Event | ||
|
||
|
||
main = | ||
Browser.sandbox | ||
{ init = init | ||
, update = update | ||
, view = view | ||
} | ||
{ init = init | ||
, update = update | ||
, view = view | ||
} | ||
|
||
|
||
type alias Model = Int | ||
type alias Model = | ||
Int | ||
|
||
|
||
init : Model | ||
init = | ||
init = | ||
0 | ||
|
||
|
||
type Msg = Clicked | ||
type Msg | ||
= Clicked | ||
|
||
|
||
update : Msg -> Model -> Model | ||
update msg model = | ||
|
@@ -31,14 +35,19 @@ update msg model = | |
|
||
|
||
view : Model -> Html Msg | ||
view model = | ||
Html.div [] | ||
[ Html.span | ||
[ Attribute.id "count" ] | ||
[ Html.text <| String.fromInt model ] | ||
view model = | ||
Html.div | ||
[] | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the first argument is a simple expression, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, elm-format allows function calls to be one of (with the added rule that if any argument spans multiple lines, then it is not allowed to be on the same line as anything else):
It's a rule that I feel like isn't very elegant, and I guess it's been fine in Elm, but I'm not 100% sure it always makes sense. We could use that same rule for gren, or consider some different kind of rule for this. |
||
[ Html.span | ||
[ Attribute.id "count" | ||
] | ||
[ Html.text | ||
<| String.fromInt model | ||
] | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, I think it makes sense to format as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 this is part of retaining linebreak information, noted in #11 (comment) re "(1)" |
||
, Html.button | ||
[ Attribute.id "increase-count" | ||
, Event.onClick Clicked | ||
] | ||
[ Html.text "Count" ] | ||
[ Html.text "Count" | ||
] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we can format this block of code in a nicer way.
<|
seems to always be split out to a seperate line, I'd usually prefer it to be on the same line. I believe that's what happens inelm-format
too, or am I wrong?<|
, I prefer lambdas to stay on the previous line, instead of being broken out to a separate line. Not sure whatelm-format
does in this case.<|
.While I'm giving this feedback to this particular block of code, my comments apply universally.
Personally, I'd love to see the
await
statements formatted to be on the same line, but I appriciate there being different views on this and it's not important to get in before the 0.2 release.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Sounds good. I already was expecting this from following some of the discussions on Zulip :D I think this will be doable, but as it's quite different from elm-format, it'll take a bit of thinking through the details of the rules, so I've postponed worrying about it yet.
(1): Yes, elm-format will keep it on a single line if it's not otherwise forced to expand. For gren format, retaining information about where linebreaks originally were isn't implemented at all yet, so allowing single-line
<|
would fit as part of that future goal. I guess the main question here is, is<|
going to be considered special, or do we want a rule that applies to all binary operators? (For elm-format,<|
is in fact a special case, see below.)(2): elm-format doesn't allow that, though it does have one special case for
<| \_ -> ...
where the<|
will stick at the end of the previous line (but the lambda will still start on the next line). This sounds fine to try to implement.(3): I think I made it add parens in the first pass because I wasn't confident that I understood the edge cases well enough to be confident that it wouldn't remove parens in some cases that are actually necessary. (Since the parser originally dropped all parens when parsing, the formatter actually is only adding parens that are required -- which in total has the result of removing unnecessary parens.) This should be fine to implement. Though if anyone happens to have some time to help enumerate all the possible edge cases where parens may or may not be required around lambdas to avoid changing the meaning of code, that'd be helpful!