Forbid { field, ... } record patterns.
readability and error prone-ness: Similar to exposing from an import, it becomes hard to follow where a certain value originated from
checkForConcatOnMap { nodeRange, firstArg } =
case toSpecificCall ( "List", "map" ) firstArg of
Just { fnRange } ->
let ...
in
Fix.replaceByExpression nodeRange firstArg
++ Fix.replace fnRange "List.concatMap"
Nothing ->
NothingSince fnRange, nodeRange and firstArg could have all come from either call,
it's really hard to trace their origin without jumping around in your code.
checkForConcatOnMap concatCall =
case toSpecificCall ( "List", "map" ) concatCall.firstArg of
Just mapCall ->
let ...
in
Fix.replaceByExpression concatCall.nodeRange concatCall.firstArg
++ Fix.replace mapCall.fnRange "List.concatMap"
Nothing ->
NothingHere it's always very clear what thing a field refers to. Don't you agree this is much easier to understand?
less syntax to learn to use right and keep in your head
name clashes: Using record destructuring relies on the assumption that no values with the same name will ever in the lifetime of this file be introduced.
module Ui exposing (icon)
icon { image, style } =
...future iteration
module Ui exposing (icon, image)
image { proportions, url } =
...
icon { image, style } =
...Ok, we have to change this one completely unrelated field into a record access. That's not too bad.
module Ui exposing (icon, image)
image { proportions, url } =
...
icon ({ style } as config) =
...future iteration
module Ui exposing (icon, image, url)
image { proportions, url } =
...
icon ({ style } as config) =
...
url { path, openInNewTab } =
...Oh well, another clash
module Ui exposing (icon, image, url)
image ({ proportions } as config) =
...
icon ({ style } as config) =
...
url { path, openInNewTab } =
...This mixed use of record access and record destructuring is quite ugly I'd say. Maybe just use record access consistently so you don't have these problems?
leaves potential future need to refactor: You can't really use record destructuring anywhere except at the most outer argument/let level because the field names quickly lose context and introduce name clashes.
checkForConcatOnMap { nodeRange, firstArg } =
case toSpecificCall ( "List", "map" ) firstArg of
Just { fnRange, nodeRange } ->
let ...
in
Fix.replaceByExpression nodeRange nodeRange -- well...
++ Fix.replace fnRange "List.concatMap"
Nothing ->
Nothing
Forbid
{ field, ... }record patterns.For example
will be fixed to
Patterns without
aswill not get an auto-fix, so either manually apply this change or add a temporaryas.