Skip to content

Enable the no-array-reduce ESLint plugin rule #19788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

Snuffleupagus
Copy link
Collaborator

Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md

Note that this still allows "simple" usage of Array.prototype.reduce, however most of those cases will be possible to replace with Math.sumPrecise once that becomes generally available (currently not supported in Node.js or QuickJS).

Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md

Note that this still allows "simple" usage of `Array.prototype.reduce`, however most of those cases will be possible to replace with `Math.sumPrecise` once that becomes generally available (currently not supported in Node.js or QuickJS).
@Snuffleupagus
Copy link
Collaborator Author

About quickjs, for now Math.sumPrecise isn't implemented: https://github.com/bellard/quickjs/blob/9d3776d0d45ca437ddb7f9079ae0367102abc90f/test262.conf#L154

but we can cheat something, see what I did for Date.parse:

* https://github.com/mozilla/pdf.js.quickjs/blob/3ca8f480cd32240378d5e53b759c5e14b76a3549/src/quickjs_extra.c#L118-L132

* https://github.com/mozilla/pdf.js.quickjs/blob/3ca8f480cd32240378d5e53b759c5e14b76a3549/src/myjs.js#L71-L74

* https://github.com/mozilla/pdf.js.quickjs/blob/3ca8f480cd32240378d5e53b759c5e14b76a3549/0001-Extra-stuff-for-use-with-PDF.js.patch#L36-L39

Interesting, thank you.

Given that Math.sumPrecise is new enough that it can still be disabled in Firefox (via a preference), we probably want to hold off using it in the scripting_api/ folder since we'd then need to bundle a polyfill anyway.

Copy link
Contributor

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@Snuffleupagus Snuffleupagus merged commit 0e50125 into mozilla:master Apr 8, 2025
7 checks passed
@Snuffleupagus Snuffleupagus deleted the no-array-reduce branch April 8, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants