-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
Add allowSimpleOperations
option to no-array-reduce
rule
#1418
Add allowSimpleOperations
option to no-array-reduce
rule
#1418
Conversation
I think it should be |
@sindresorhus I am totally open to that and can start whipping up changes. I figured it was best to start it off as a non-breaking change until a conversation could be had. |
@sindresorhus with the flipping of default to It's this from MDN's reduce documentation on parameters (emphasis added):
For example: const nums = [1, 2, 3, 4, 5];
console.log(nums.reduce((total, item) => total + item, 0)); // -> 15
console.log(nums.reduce((total, item) => total + item)); // -> 15 I am unsure of how to check the assumed values that are being iterated on without the ability to check Any great ideas? Or should the rule only work / pass when |
I think an initial value helps readability, so I agree we can just enforce that if they want it to pass. |
@sindresorhus I've changed the default value to |
Do you think the following cases are simple enough to ignore? const getValueByPath = (object, path) =>
path.split('.').reduce((value, key) => value[key], object); const queue = steps =>
steps.reduce((promise, step) => promise.then(step), Promise.resolve()); |
IMHO, no. |
I think we should also check the callback function body, only allow simple |
We can also change these two lines in our codebase back And |
Yeah, and |
@sindresorhus @fisker both your comments make sense and seem doable. I was in all day meetings today and will be again tomorrow. I should be able to circle back to this on Friday or into the weekend. Thanks for the feedback! |
I've updated the PR to allow a direct I also renamed the lint rule option to And @fisker, I tried changing the lines of code from your comment back to using |
allowNumericInitialValue
option to no-array-reduce
rule.allowSimpleOperations
option to no-array-reduce
rule.
@sindresorhus @fisker do either of you have any feedback you'd like me to address? |
allowSimpleOperations
option to no-array-reduce
rule.allowSimpleOperations
option to no-array-reduce
rule
c873345
to
5aadd69
Compare
Can you fix the lint violation? |
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Unless I am misunderstanding the failure, I believe it's coming from I can address it here if you'd like or in a separate PR. Your call. Either way. It take a little more work (not a ton) because it's a dynamically generated message. |
@sindresorhus aside from the lint issue and my comment above regarding the issue, I believe everything else on the PR has been addressed. |
@sindresorhus all |
This is my first time contributing something to this project besides from minor documentation tweaks, so don't feel bad telling me I did something incorrectly.
I took a stab at the open issue to allow simple sums when using
reduce
. I am not married to the option name, so please offer better suggestions if you have them.Fixes #1348