Skip to content
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

Don't report custom type constructor args used in comparisons #35

Merged
merged 31 commits into from
Mar 26, 2021

Conversation

jfmengels
Copy link
Owner

@jfmengels jfmengels commented Mar 26, 2021

Fixes #25

When used in comparison, the arguments of a custom type constructor won't be reported.

-- Not reported
value == Foo 1
-- Still reported
value == fn (Foo 1)

@r-k-b This won't handle the case for assoc-list and I don't have a good idea to handle it. I added a warning in the rule's documentation though.

Please try it out:

elm-review --template jfmengels/elm-review-unused/preview#issue-25 --rules NoUnused.CustomTypeConstructorArgs

cc @lydell @jpagex

@lydell
Copy link
Contributor

lydell commented Mar 26, 2021

Cool!

I tried to simplify down my case:

module Simple exposing (update, view)

import Html exposing (Html)


type alias Model =
    { version : Version
    }


type Version
    = LatestVersion String
    | OutOfDateVersion


update : String -> Model -> Model
update justFetchedVersionString model =
    { model
        | version =
            if model.version == LatestVersion justFetchedVersionString then
                model.version

            else
                OutOfDateVersion
    }


view : Model -> Html msg
view model =
    case model.version of
        LatestVersion _ ->
            Html.text ""

        OutOfDateVersion ->
            Html.text "You need to update!"

This is the result:

❯ npx elm-review --template jfmengels/elm-review-unused/preview#issue-25 --rules NoUnused.CustomTypeConstructorArgs
npx: installed 125 in 8.083s
✔ Fetching template information
-- ELM-REVIEW ERROR --------------------------------------- src/Simple.elm:12:21

NoUnused.CustomTypeConstructorArgs: Argument is never extracted and therefore
never used.

11| type Version
12|     = LatestVersion String
                        ^^^^^^
13|     | OutOfDateVersion

This argument is never used. You should either use it somewhere, or remove it at
the location I pointed at.

I found 1 error in 1 file.

This shouldn’t be reported, should it? Or am I missing something 🤔

@jfmengels
Copy link
Owner Author

Yeah, it shouldn't. I made some mistakes in my tests and forgot to handle an essential thing. It should be fixed now though!

@lydell
Copy link
Contributor

lydell commented Mar 26, 2021

Thanks! Yes, now it seems to be fixed. Awesome! 🥇

@jfmengels jfmengels merged commit 6d242c3 into master Mar 26, 2021
@jfmengels jfmengels deleted the issue-25 branch March 26, 2021 19:56
@jfmengels
Copy link
Owner Author

Alright, released in 1.1.7 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive on NoUnused.CustomTypeConstructorArg
2 participants