lue-bird / elm-review-upgrade

tell me how to get rid of outdated stuff
https://dark.elm.dmy.fr/packages/lue-bird/elm-review-upgrade/latest/
MIT License
0 stars 1 forks source link

Upgrade.reference Removes Function Arguments #1

Open matzko opened 6 months ago

matzko commented 6 months ago

I noticed when following the instructions here

That

npx elm-review --template elmcraft/core-extra/upgrade#2.0.0 --fix

was removing the arguments for my deprecated functions.

Here's a test that fails when added to elm-review-upgrade/tests/Tests.elm:

        , Test.test "upgrades deprecated functions without deleting their arguments"
            (\() ->
                """module A exposing (..)
import List.Extra

result =
    [ 1, 2, 3 ]
        |> List.Extra.filterNot isEven
"""
                    |> Review.Test.run
                        (Upgrade.rule
                            [ Upgrade.reference { old = ( "List.Extra", "filterNot" ), new = ( "List.Extra", "removeWhen" ) }
                            ]
                        )
                    |> Review.Test.expectErrors
                        [ Review.Test.error
                            { message = "List.Extra.filterNot can be upgraded to List.Extra.removeWhen"
                            , details =
                                [ "I suggest applying the automatic fix, then cleaning it up in a way you like."
                                ]
                            , under = "List.Extra.filterNot"
                            }
                            |> Review.Test.whenFixed
                                """module A exposing (..)
import List.Extra

result =
    [ 1, 2, 3 ]
        |> List.Extra.removeWhen isEven
"""
                        ]
            )

The results:


↓ Tests
↓ elm-review-upgrade
✗ upgrades deprecated functions without deleting their arguments

    FIXED CODE MISMATCH

    I found a different fixed source code than expected for the error with the
    following message:

      `List.Extra.filterNot can be upgraded to List.Extra.removeWhen`

    I expected the following result after the fixes have been applied:
    module A exposing (..)
    import List.Extra

    result =
        [ 1, 2, 3 ]
            |> List.Extra.removeWhen isEven

  ```

but I found:

  ```
    module A exposing (..)
    import List.Extra

    result =
        [ 1, 2, 3 ]
            |> (
               List.Extra.removeWhen)

  ```


Thanks!
lue-bird commented 6 months ago

Heyy, thanks a lot for the detailed report! Should be fixed now with that test passing. I'll soon release a new version and bump it for elmcraft/core-extra, which should be a more robust around import expose shadowing and multi-line strings as well.