Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

ensure_comprehensions should warn about comprehensions of or within implicit object literals #624

Open
rodovich opened this issue Oct 26, 2017 · 0 comments

Comments

@rodovich
Copy link

()-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'])
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant