jfmengels / elm-review-simplify

Provides elm-review rules to simplify your Elm code
https://package.elm-lang.org/packages/jfmengels/elm-review-simplify/latest/
BSD 3-Clause "New" or "Revised" License
20 stars 9 forks source link

Simplify pipelined accessor call into access #312

Closed Janiczek closed 1 week ago

Janiczek commented 1 week ago

What the rule should do: Replace things like foo |> .x with foo.x, except for when the foo is a function call or operator call (eg. a pipeline).

What problems does it solve: Makes things simpler?

Example of things the rule would report:

foo |> .x
--> foo.x
1 |> .x
--> 1.x, wouldn't typecheck but is valid syntax
{ x = 3 } |> .x
--> { x = 3 }.x, to be picked up by another rule later and simplify to 3

Example of things the rule would not report:

foo 1 |> .x
foo |> fn |> .x

Should this be part of the Simplify rule or should it be a new rule? Simplify

I am looking for:

Janiczek commented 1 week ago

I guess it might be related to a rule where .x foo is rewritten into foo.x, which could be thought of as a simpler variant of the above. If we had some RuleAstPred -> RuleAstPred combinator way of making rules that work on fn calls also work on pipelined fn calls, then that simpler rule + that combinator would give you the rule I'm proposing above.

lue-bird commented 1 week ago

Similar to .x foo I think this is pretty much just a style issue which is better suited to rules with fine control like SiriusStarr/elm-review-pipeline-styles.

For example, in some cases, it might just be more readable to not use the record access shortcut

generalizableListElement
    |> .toGeneral
    |> expressionParenthesize
    |> ...

and I think simplify reporting such cases could be annoying for users.

jfmengels commented 1 week ago

Right. I feel like we often have this discussion and I keep forgetting :sweat_smile: Yeah, use SiriusStarr/elm-review-pipeline-styles instead, and if it doesn't support this, then open an issue there.

Janiczek commented 1 week ago

fair, thanks