()-less comprehensions and {}-less object literals can interact to form more ambiguous scenarios than are currently flagged by ensure_comprehensions.
Strings like this…
fish: f for f in ['albacore', 'bass', 'carp']
…can have different meanings depending where parentheses or braces are added:
# [ { fish: 'albacore' }, { fish: 'bass' }, { fish: 'carp' } ]
(fish: f) for f in ['albacore', 'bass', 'carp']
{fish: f} for f in ['albacore', 'bass', 'carp']
# { fish: [ 'albacore', 'bass', 'carp' ] }
fish: (f for f in ['albacore', 'bass', 'carp'])
{fish: f for f in ['albacore', 'bass', 'carp']}
This can arise in function arguments, function results, and nested object literals:
# should warn
setPuddleContents fish: f for f in ['albacore', 'bass', 'carp']
setPuddleContents(fish: f for f in ['albacore', 'bass', 'carp'])
setPuddleContents
fish: f for f in ['albacore', 'bass', 'carp']
# unambiguous
(setPuddleContents fish: f) for f in ['albacore', 'bass', 'carp']
setPuddleContents(fish: f) for f in ['albacore', 'bass', 'carp']
setPuddleContents fish: (f for f in ['albacore', 'bass', 'carp'])
setPuddleContents {fish: f for f in ['albacore', 'bass', 'carp']}
setPuddleContents
{fish: f} for f in ['albacore', 'bass', 'carp']
setPuddleContents
fish: (f for f in ['albacore', 'bass', 'carp'])
# should warn
getPuddleContents = -> fish: f for f in ['albacore', 'bass', 'carp']
getPuddleContents = -> (fish: f for f in ['albacore', 'bass', 'carp'])
# unambiguous
(getPuddleContents = -> fish: f) for f in ['albacore', 'bass', 'carp']
getPuddleContents = -> ({fish: f} for f in ['albacore', 'bass', 'carp'])
getPuddleContents = ->
{fish: f} for f in ['albacore', 'bass', 'carp']
getPuddleContents = -> fish: (f for f in ['albacore', 'bass', 'carp'])
getPuddleContents = -> {fish: f for f in ['albacore', 'bass', 'carp']}
# should warn
puddleContents: fish: f for f in ['albacore', 'bass', 'carp']
# unambiguous
{puddleContents: fish: f} for f in ['albacore', 'bass', 'carp']
puddleContents: {fish: f for f in ['albacore', 'bass', 'carp']}
puddleContents: fish: (f for f in ['albacore', 'bass', 'carp'])
puddleContents: ({fish: f} for f in ['albacore', 'bass', 'carp'])
()
-less comprehensions and{}
-less object literals can interact to form more ambiguous scenarios than are currently flagged byensure_comprehensions
.Strings like this…
…can have different meanings depending where parentheses or braces are added:
This can arise in function arguments, function results, and nested object literals: