jfmengels/elm-review-unused/1.2.5

NOTE: the latest version is 1.2.6

NoUnused.Parameters

Report parameters that are not used.

rule : Rule

Report parameters that are not used.

🔧 Running with --fix will automatically remove some of the reported errors.

config =
    [ NoUnused.Parameters.rule
    ]

This rule looks within function arguments, let functions and lambdas to find any values that are unused. It will report any parameters that are not used.

Fixes for lambdas

We're only offering fixes for lambdas here because we believe unused parameters in functions are a code smell that should be refactored.

Fail

Value number is not used:

add1 number =
    1

The rule will also report parameters that are only used to be passed again to the containing recursive function:

last list unused =
    case list of
        [] ->
            Nothing


        [ a ] ->
            Just a


        _ :: rest ->
            last rest unused

Success

add1 number =
    number + 1

Automatic fixes

When possible, the rule will automatically remove function arguments from the declaration and call sites

-- Before
someFunction : Int -> Int -> Int
someFunction used unused =
    used + 1


two =
    someFunction 1 10


-- After
someFunction : Int -> Int
someFunction used =
    used + 1


two =
    someFunction 1

Also for fields and tuple values inside parameters, such as:

-- Before
someFunction : { unused : Int, used : Int } -> Int
someFunction { unused, used } =
    otherFunction used


a =
    someFunction { unused = 1, used = 2 }


-- After
someFunction : { used : b } -> b
someFunction { used } =
    otherFunction used


a =
    someFunction { used = 2 }

When fixing the calls is not possible, a fix will be made to ignore the argument (by replacing it by _ for instance. _ arguments will only be reported if they're automatically fixable, otherwise they will be ignored.

Try it out

You can try this rule out by running the following command:

elm-review --template jfmengels/elm-review-unused/example --rules NoUnused.Parameters