Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct String.words and String.lines simplifications #302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The rule now simplifies:
- `List.length (Dict.toList dict)` to `Dict.size dict` (same for `Dict.values` and `Dict.keys`)
- `List.isEmpty (Dict.toList dict)` to `Dict.isEmpty dict` (same for `Dict.values` and `Dict.keys`)

Bug fixes:
- Fixed an issue where `String.words ""` would be fixed to `[]`
- Fixed an issue where `String.lines ""` would be fixed to `[]`

## [2.1.3] - 2023-10-23

The rule now simplifies:
Expand Down
8 changes: 4 additions & 4 deletions src/Simplify.elm
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ Destructuring using case expressions
--> "z" -- only when resulting string is unchanged

String.words ""
--> []
--> [ "" ]

String.lines ""
--> []
--> [ "" ]

String.reverse ""
--> ""
Expand Down Expand Up @@ -4687,13 +4687,13 @@ stringRepeatChecks =
stringWordsChecks : IntoFnCheck
stringWordsChecks =
intoFnCheckOnlyCall
(callOnEmptyReturnsCheck { resultAsString = listCollection.empty.specific.asString } stringCollection)
(callOnEmptyReturnsCheck { resultAsString = \_ -> "[ \"\" ]" } stringCollection)


stringLinesChecks : IntoFnCheck
stringLinesChecks =
intoFnCheckOnlyCall
(callOnEmptyReturnsCheck { resultAsString = listCollection.empty.specific.asString } stringCollection)
(callOnEmptyReturnsCheck { resultAsString = \_ -> "[ \"\" ]" } stringCollection)


stringToListChecks : IntoFnCheck
Expand Down
14 changes: 7 additions & 7 deletions tests/Simplify/StringTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -660,20 +660,20 @@ b = String.words str
"""
|> Review.Test.run ruleWithDefaults
|> Review.Test.expectNoErrors
, test """should replace String.words "" by []""" <|
, test """should replace String.words "" by [ "" ]""" <|
\() ->
"""module A exposing (..)
a = String.words ""
"""
|> Review.Test.run ruleWithDefaults
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "String.words on \"\" will result in []"
, details = [ "You can replace this call by []." ]
{ message = "String.words on \"\" will result in [ \"\" ]"
, details = [ "You can replace this call by [ \"\" ]." ]
, under = "String.words"
}
|> Review.Test.whenFixed """module A exposing (..)
a = []
a = [ "" ]
"""
]
]
Expand All @@ -698,12 +698,12 @@ a = String.lines ""
|> Review.Test.run ruleWithDefaults
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "String.lines on \"\" will result in []"
, details = [ "You can replace this call by []." ]
{ message = "String.lines on \"\" will result in [ \"\" ]"
, details = [ "You can replace this call by [ \"\" ]." ]
, under = "String.lines"
}
|> Review.Test.whenFixed """module A exposing (..)
a = []
a = [ "" ]
"""
]
]
Expand Down
Loading