Linter: loosen `prefer_each` to allow chained calls

Created on 9 Dec 2016  路  12Comments  路  Source: dart-lang/linter

From Effective Dart.

forEach() functions are widely used in JavaScript because the built in for-in loop doesn鈥檛 do what you usually want. In Dart, if you want to iterate over a sequence, the idiomatic way to do that is using a loop.

enhancement false positive

Most helpful comment

To loosen this rule I think the corresponding Effective Dart rule should be updated to keep rules consistent.

All 12 comments

Perhaps it should distinguish if it's standalone or within a chain of calls (functional style)

someStream.where(...).map(...).forEach(...)

@munificent Is this still a recommendation?

Yup. I could maybe see us loosening it in cases like @zoechi describes, but, even there I prefer to use a for-in loop:

var stuff = someStream.where(...).map(...);
for (var thing in stuff) { ... }

@dikmax are you working on this?

@alexeieleusis No, just noticed duplicate issue.

@dikmax thank you ! :)

So I have a chain function call on an iterable -- a .where().forEach() and it's complaining .. I do not think this is unreasonable to do -- but it's whining. What is the status of this lint thing? I think within a chain set it's not a horrible thing? The code is cleaner (IMHO) .

It's been over a year and no movement on this @dikmax or @zoechi ??

Also - it doesn't appear that, unlike eslint, we can customize a rule to turn on/off parts of it? So we could add a "chainAllow" sort of thing for this rule? These rules appear to be On/Off only?

Thanks for chiming in @sjmcdowall!

I lean towards agreeing we should loosen this. I'll repurpose this report as a request to change prefer_foreach and update as a false positive.

Also - it doesn't appear that, unlike eslint, we can customize a rule to turn on/off parts of it?

True. This is something we've discussed a bit but never implemented.

To loosen this rule I think the corresponding Effective Dart rule should be updated to keep rules consistent.

So -- what are the next steps to actually get something moving here @pq ? Seems like this stuff can just sit around forever and not go anywhere if the 1 year time lapse is any indication .. (or almost 1 year anyway) ..

I agree w/ @a14n that we should start w/ the corresponding advice in Effective Dart. I've opened an issue to track (https://github.com/dart-lang/site-www/issues/1329); feel free to chime in / add more context there.

Seems like this stuff can just sit around forever and not go anywhere if the 1 year time lapse is any indication .

I hear you. Would that we had more time to keep up. It's been a busy year!

Anyway, thanks for the nudge. Let's see if we can get this one sorted out.

馃嵒

That would be great - I've given about as much as an example as I can to be honest.. this seems to be a fairly low level hanging fruit thing .. Let's get it passed ..

Was this page helpful?
0 / 5 - 0 ratings