I have the following line of CoffeeScript
:
names = (mail.folder for mail in @data when mail.service_name is service.name).unique()
This line is too long, so it won't pass linting by CoffeeLint
.
I'm trying to break it, but I always get indentation errors by CoffeeLint
.
What is the proper way to indent this?
This is the most readable version of that without getting overly lengthy:
names =
(for mail in @data when mail.service_name is service.name
mail.folder).unique()
You can't split list comprehensions over multiple lines, but a normal for loop can also return a value, so using one of those solves the problem. If you're willing to grant an extra line, there's no need for the awkward parentheses around the loop:
names =
for mail in @data when mail.service_name is service.name
mail.folder
names = names.unique()
Finally, the indentation of the for
line is up to you; I find my first version more readable but this is also valid:
names =
(for mail in @data when mail.service_name is service.name
mail.folder).unique()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With