Skip to content

Commit

Permalink
Don't simplify String.slice 0 to left (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
lue-bird authored Feb 6, 2023
1 parent d72a8ae commit 294d26e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
15 changes: 0 additions & 15 deletions src/Simplify.elm
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ Destructuring using case expressions
String.slice n n str
--> ""
String.slice 0 n str
--> String.left n str
String.slice n 0 str
--> ""
Expand Down Expand Up @@ -3178,18 +3175,6 @@ stringSliceChecks checkInfo =
(replaceByEmptyFix emptyStringAsString checkInfo.parentRange (thirdArg checkInfo))
]

( Node startArgumentRange (Expression.Integer 0), _, _ ) ->
[ Rule.errorWithFix
{ message = "Use String.left instead"
, details = [ "Using String.slice with start index 0 is the same as using String.left." ]
}
checkInfo.fnRange
[ Fix.replaceRangeBy
{ start = checkInfo.fnRange.start, end = startArgumentRange.end }
"String.left"
]
]

( start, Just end, _ ) ->
Maybe.map2
(\startInt endInt ->
Expand Down
24 changes: 8 additions & 16 deletions tests/SimplifyTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5232,6 +5232,14 @@ stringSliceTests =
\() ->
"""module A exposing (..)
a = String.slice b c
"""
|> Review.Test.run (rule defaults)
|> Review.Test.expectNoErrors
, test "should not report String.slice 0 n" <|
\() ->
"""module A exposing (..)
a = String.slice 0
b = String.slice 0 n
"""
|> Review.Test.run (rule defaults)
|> Review.Test.expectNoErrors
Expand Down Expand Up @@ -5313,22 +5321,6 @@ a = String.slice a z ""
}
|> Review.Test.whenFixed """module A exposing (..)
a = ""
"""
]
, test "should replace String.slice 0 by String.left" <|
\() ->
"""module A exposing (..)
a = String.slice 0
"""
|> Review.Test.run (rule defaults)
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Use String.left instead"
, details = [ "Using String.slice with start index 0 is the same as using String.left." ]
, under = "String.slice"
}
|> Review.Test.whenFixed """module A exposing (..)
a = String.left
"""
]
, test "should replace String.slice 0 0 by always \"\"" <|
Expand Down

0 comments on commit 294d26e

Please sign in to comment.