Skip to content

Commit

Permalink
Fix codemod import insertion in case where there is an exposing import.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonkearns committed Jan 10, 2024
1 parent 304b91b commit a943466
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ finalEvaluation context =
, details = [ "" ]
}
importAddRange
[ Review.Fix.insertAt importAddRange.end "\n\nimport FatalError\n\n"
[ Review.Fix.insertAt importAddRange.start "\nimport FatalError\n"
]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,69 @@ route =
data : BackendTask Data
data =
BackendTask.succeed ()
"""
]
, test "replaces import with exposing line" <|
\() ->
"""module View exposing (View, map, placeholder)
import Html.Styled as Html exposing (Html)
type alias View msg =
{ title : String
, body : List (Html msg)
}
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn view =
{ title = view.title
, body = List.map (Html.map fn) view.body
}
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder"
, body = [ Html.text moduleName ]
}
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Codemod"
, details =
[ "" ]
, under =
"""import Html.Styled as Html"""
}
|> Review.Test.whenFixed
"""module View exposing (View, map, placeholder)
import FatalError
import Html.Styled as Html exposing (Html)
type alias View msg =
{ title : String
, body : List (Html msg)
}
map : (msg1 -> msg2) -> View msg1 -> View msg2
map fn view =
{ title = view.title
, body = List.map (Html.map fn) view.body
}
placeholder : String -> View msg
placeholder moduleName =
{ title = "Placeholder"
, body = [ Html.text moduleName ]
}
"""
]
, test "supports aliased BackendTask module import" <|
Expand Down

0 comments on commit a943466

Please sign in to comment.