truqu / elm-review-noleftpizza / NoLeftPizza

rule : Strictness -> Review.Rule.Rule

Forbids using the left pizza operator (<|) in infix position.

Expressions like foo <| "hello" ++ world will be flagged, and a fix will be proposed to write the expression to foo ("hello" ++ world).

To use this rule, add it to your elm-review config like so:

import NoLeftPizza
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoLeftPizza.rule NoLeftPizza.Any
    ]

The above configuration results in absolutely any use of <| being flagged. If you'd prefer only flagging redundant usage (such as foo <| bar), pass NoLeftPizza.Redundant as the configuration option.

If you would prefer to keep writing tests in the more "traditional" style which uses <|, you can disable the rule for tests/ like so:

import NoLeftPizza
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoLeftPizza.rule NoLeftPizza.Any
        |> Rule.ignoreErrorsForDirectories
            [ -- Test functions are traditionally built up using a left pizza.
              -- While we don't want them in our regular code, let's allow them
              -- just for tests.
              "tests/"
            ]
    ]

Or pass NoLeftPizza.Redundant which will only apply to redundant usage:

import NoLeftPizza
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoLeftPizza.rule NoLeftPizza.Redundant
    ]


type Strictness
    = Any
    | Redundant

Specify how strict the rule should be.

Specifying Any means that any use of <| will be flagged, whereas Redundant limits it to cases where <| can be removed - without adding any parenthesis - without changing the semantics.