Skip to content

Commit

Permalink
Merge branch 'jxxcarlson:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfpleite authored Jun 2, 2024
2 parents 45bc174 + c17f074 commit 4b695df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "jxxcarlson/elm-review-codeinstaller",
"summary": "A set of rules for installing code in an existing Elm project.",
"license": "MIT",
"version": "2.0.4",
"version": "2.0.6",
"exposed-modules": [
"Install.ClauseInCase",
"Install.FieldInTypeAlias",
Expand Down
25 changes: 10 additions & 15 deletions src/Install/ClauseInCase.elm
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,13 @@ rangeToInsertClause insertAt cases expression =
|> Maybe.map Tuple.second
|> Maybe.withDefault expression

firstClauseExpression =
lastClauseStartingColumn =
cases
|> List.head
|> Maybe.map Tuple.second
|> Maybe.withDefault expression
|> List.Extra.last
|> Maybe.map Tuple.first
|> Maybe.map (Node.range >> .start >> .column)
|> Maybe.withDefault 0
|> (\x -> x - 1)
in
case insertAt of
After previousClause ->
Expand All @@ -232,43 +234,36 @@ rangeToInsertClause insertAt cases expression =
pattern
|> Tuple.second
|> Node.range
|> (\range -> ( range, 2, range.start.column ))
|> (\range -> ( range, 2, lastClauseStartingColumn ))

Nothing ->
( Node.range lastClauseExpression, 2, 0 )

AtBeginning ->
-- TODO: Review, is it correct?
-- TODO: this code is not correct
( Node.range expression, 1, (Node.range expression).start.column )

AtEnd ->
let
range =
Node.range lastClauseExpression
in
( range, 2, range.start.column )
( range, 2, lastClauseStartingColumn )


errorWithFix : CustomError -> String -> String -> Node a -> Maybe ( Range, Int, Int ) -> Error {}
errorWithFix (CustomError customError) clause functionCall node errorRange =
let
nodeStartRow =
(Node.range node).start.row
in
Rule.errorWithFix
customError
(Node.range node)
(case errorRange of
Just ( range, verticalOffset, horizontalOffset ) ->
let
horizontalPadding =
horizontalOffset - nodeStartRow + 1

insertionPoint =
{ row = range.end.row + verticalOffset, column = 0 }

prefix =
"\n" ++ String.repeat horizontalPadding " "
"\n" ++ String.repeat horizontalOffset " "
in
[ addMissingCase insertionPoint prefix clause functionCall ]

Expand Down
8 changes: 4 additions & 4 deletions tests/Install/ClauseInCaseTest2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ src1 =
updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
case msg of
CounterIncremented ->
CounterIncremented ->
let
newCounter =
model.counter + 1
Expand All @@ -92,15 +92,15 @@ fixed1 =
updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
case msg of
CounterIncremented ->
CounterIncremented ->
let
newCounter =
model.counter + 1
in
( { model | counter = newCounter }, broadcast (CounterNewValue newCounter clientId) )
ResetCounter -> ( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )
ResetCounter -> ( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )
"""
Expand All @@ -126,7 +126,7 @@ updateFromFrontend sessionId clientId msg model =

under1 =
"""case msg of
CounterIncremented ->
CounterIncremented ->
let
newCounter =
model.counter + 1
Expand Down

0 comments on commit 4b695df

Please sign in to comment.