Skip to content

Commit

Permalink
fix: identation when inserting clause at the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfpleite committed Jun 2, 2024
1 parent 4b695df commit 0dd4428
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/Install/ClauseInCase.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module Install.ClauseInCase exposing (init, makeRule, withInsertAfter, withCustomErrorMessage, Config, CustomError)
module Install.ClauseInCase exposing
( init, makeRule, withInsertAfter, withCustomErrorMessage, Config, CustomError
, withInsertAtBeginning
)

{-| Add a clause to a case expression in a specified function
in a specified module. For example, if you put the code below in your
Expand Down Expand Up @@ -240,8 +243,12 @@ rangeToInsertClause insertAt cases expression =
( Node.range lastClauseExpression, 2, 0 )

AtBeginning ->
-- TODO: this code is not correct
( Node.range expression, 1, (Node.range expression).start.column )
let
-- The clause must always be indented 3 columns after the start of the case expression
firstClauseOffset =
(Node.range expression).start.column + 3
in
( Node.range expression, 1, firstClauseOffset )

AtEnd ->
let
Expand Down
23 changes: 14 additions & 9 deletions tests/Install/ClauseInCaseTest2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ all =
describe "Install.ClauseInCase"
[ Run.testFix test1a
, Run.testFix test1b
, Run.testFix test1c

-- Run.testFix test1c
-- Run.testFix test2
]

Expand Down Expand Up @@ -43,7 +43,7 @@ test1b =
test1c =
{ description = "Test 1c, withInsertAtBeginning: should report an error and fix it"
, src = src1
, rule = rule1b
, rule = rule1c
, under = under1c
, fixed = fixed1c
, message = "Add handler for ResetCounter"
Expand All @@ -61,12 +61,10 @@ rule1b =
|> Install.ClauseInCase.makeRule



--
--rule1c =
-- Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
-- |> Install.ClauseInCase.withInsertAtBeginning
-- |> Install.ClauseInCase.makeRule
rule1c =
Install.ClauseInCase.init "Backend" "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.withInsertAtBeginning
|> Install.ClauseInCase.makeRule


src1 =
Expand Down Expand Up @@ -112,6 +110,7 @@ fixed1c =
updateFromFrontend : SessionId -> ClientId -> ToBackend -> Model -> ( Model, Cmd BackendMsg )
updateFromFrontend sessionId clientId msg model =
case msg of
ResetCounter -> ( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )
CounterIncremented ->
Expand All @@ -121,6 +120,7 @@ updateFromFrontend sessionId clientId msg model =
in
( { model | counter = newCounter }, broadcast (CounterNewValue newCounter clientId) )
"""


Expand All @@ -136,7 +136,12 @@ under1 =

under1c =
"""case msg of
"""
CounterIncremented ->
let
newCounter =
model.counter + 1
in
( { model | counter = newCounter }, broadcast (CounterNewValue newCounter clientId) )"""



Expand Down

0 comments on commit 0dd4428

Please sign in to comment.