jfmengels / elm-review-unused

Provides elm-review rules to detect unused elements in your Elm project
https://package.elm-lang.org/packages/jfmengels/elm-review-unused/latest/
BSD 3-Clause "New" or "Revised" License
23 stars 12 forks source link

Don't report exposed custom types whose constructors are used elsewhere #62

Closed jfmengels closed 2 years ago

jfmengels commented 2 years ago

Fixes #61

@Janiczek This fixes the problem in the SSCCE. Can you try it out and confirm whether it works on your original code if you still have it?

elm-review --template jfmengels/elm-review-unused/preview#fix-61 --rules NoUnused.Exports
Janiczek commented 2 years ago

@jfmengels It helps with one of the false positives but doesn't help with the other one (LabelOrientation). 🤔

jfmengels commented 2 years ago

@Janiczek Hmm. Could you have some time to create an SSCCE for that one? No rush though!

Janiczek commented 2 years ago

@jfmengels Hey there, here is a SSCCE for the second case. Seems like whenever I add the missing type annotation for the unwrapper, the false positive goes away.

src/Main.elm

module Main exposing (main)

import Config
import Html

main =
    let
        config =
            Config.a
                |> Config.useB
                |> Config.unwrap
    in
    case config of
        Config.A ->
            Html.text "a"

        Config.B ->
            Html.text "b"

src/Config.elm

module Config exposing
    ( Variant(..)
    , a
    , unwrap
    , useB
    )

type Config
    = Config Variant

type Variant
    = A
    | B

{-| The missing type annotation is important!
-}
unwrap (Config config) =
    config

a : Config
a =
    Config A

useB : Config -> Config
useB _ =
    Config B