linter icon indicating copy to clipboard operation
linter copied to clipboard

consider `list_comprehensions` lint

Open pq opened this issue 5 years ago • 4 comments

Follow-up from https://github.com/flutter/devtools/pull/1837#discussion_r411544355, where @jacobr suggested:

nit: consider using List comprehensions for this case instead of map followed by toList(). this might be a reasonable general lint to encourage users to take advantage of list comprehensions if we think the list comprehension way is easier to read.

ExceptionMode.modes.map((mode) {
  return DropdownMenuItem<ExceptionMode>(
    value: mode,
    child: Text(mode.name),
  );
}).toList();

vs

[ for (mode in ExceptionMode.modes)
  DropdownMenuItem<ExceptionMode>(
    value: mode,
    child: Text(mode.name),
  )
]

pq avatar Apr 20 '20 18:04 pq

Fyi @munificent for whether the style guide should also have an opinion on this case. For example: "do use list comprehension for loops instead of map when it will avoid a call to toList".

jacob314 avatar Apr 21 '20 15:04 jacob314

Yes please, @munificent: any guidance would be hugely appreciated!

pq avatar Apr 21 '20 16:04 pq

We deliberately don't have guidance on this yet because we're still waiting to get enough user experience to figure out what the best practice is. Right now, I don't think we know so it's best to give users the freedom to explore.

munificent avatar Apr 23 '20 18:04 munificent

thanks @munificent!

/fyi @inmatrix @jayoung-lee @bwilkerson this makes for another potential research area when we do corpus analysis...

pq avatar Apr 23 '20 19:04 pq