avh4 / avh4/elm-format

Separate the field access function from an operator automatically

Open
#677 0 comments 3 reactions 0 assignees View on GitHub
0.9 feature for developers full operators list
Dominant language
Haskell
Stars
1.3k
Forks
147
PR merge metrics
No merged PRs in 30d

Description

Quite often, I write code similar to the following:
```elm
result = someRecord|>.field
```
which then gets reformatted to
```elm
result =
someRecord |>. field
```
which does not compile, because `|>.` is not a known operator.
This is "syntactically" the correct change, as even in the first case, the code does not compile for the same reason.

Since `elm-format` likes to fix syntax errors [to help the user out without them noticing](https://elmtown.simplecast.fm/my-favorite-thing-is-when-they-dont-even-notice), I thought maybe it could also help them by reformatting to the following instead:
```elm
result =
someRecord |> .field
```

I think the same thing would be worthwhile for `<|`, `<<`, `>>`, and potentially all operators.

This is my proposal:
When seeing code of the form `.`, reformat it to ` .`.

AFAIK, there is only `|.` from `Parser` and `Parser.Advanced` which ends with a `.`, but since `|` is not a known operator, this wouldn't be ambiguous.

Since the number of operators is limited and has been stable for quite a while now, I think it would be reasonably safe to fix it the proposed way but you may righteously disagree, and that would be a good reason to decide against this proposal :+1:

Thanks for all your work on `elm-format`! :heart:

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue points to Parser and Parser.Advanced and proposes changing known-operator field access from `operator.field` to `operator .field`. Start by locating the formatter logic for operator and field-access spacing in those areas, then add coverage for `|>`, `<|`, `<<`, `>>`, and other relevant operators; done means valid separated output without changing unrelated operators.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.