question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`no-array-reduce` should not apply where it's not easily replaceable (objects, JSX)

See original GitHub issue

Applying the rule on this code would mean either adding an IIFE with a for-of loop inside or splitting the object declaration from the application (which requires assertions or dead code in TypeScript)

I think this would be a similar exception to #1348 (of which this issue might be a slight duplicate)

return {
	huge: 'object',
	with: 'many',
	keys: array.reduce(etc)
};
<Display>
	<Title>{title}</Title>
	<Modal>
		<List>{array.reduce(reducer)}</List>
	</Modal>
</Display>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chasmcommented, Jul 2, 2021

This is a remarkably stupid rule. Instead of simply teaching programmers to use reduce well, just ban it entirely. Really?

If you can replace it with map, then you are using it wrongly. If you can replace it with filter, then you are using it wrongly. And there is no reason to believe that those who use for-of instead will write any more intelligible code.

This rule is patronizing and rude. These rules should help discern good usage from poor usage, not tell me what I can or cannot use.

0reactions
fiskercommented, Jul 4, 2021

I don’t really understand why the argument, I disabled no-array-reduce myself. I also disabled some rules wrote by myself, I wrote them not because it’s right, it’s because someone need it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Updating React state when state is an array of objects
What I'm having trouble with is then updating the array and then subsequently updating state without mutation. //make sure we're not mutating state...
Read more >
JSX In Depth - React
React thinks <hello /> is an HTML tag because it's not capitalized: ... This is a component and should be capitalized:function Hello(props) {...
Read more >
Immutability in React: Should you mutate objects?
String values are immutable, but string objects are not. If an object is immutable, you cannot change its state or the value of...
Read more >
Render a String with Non-breaking Spaces in React | Pluralsight
React has successfully done so with its easy-to-understand component ... You can write JavaScript in a React component to do almost anything ...
Read more >
Do React Hooks Replace Redux?. TL;DR - Medium
Since the React hooks API was introduced, a lot of questions have risen about whether or not React hooks will replace Redux.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found