Skip to content
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

Style/CollectionMethods does not detect inject -> reduce in certain cases #9262

Closed
dgollahon opened this issue Dec 20, 2020 · 0 comments · Fixed by #9267
Closed

Style/CollectionMethods does not detect inject -> reduce in certain cases #9262

dgollahon opened this issue Dec 20, 2020 · 0 comments · Fixed by #9267
Labels

Comments

@dgollahon
Copy link
Contributor

dgollahon commented Dec 20, 2020

Expected behavior

[1, 2].inject(:+)     # =>  Style/CollectionMethods: Prefer reduce over inject.
[1, 2].inject(0, :+)  # =>  Style/CollectionMethods: Prefer reduce over inject.
[1, 2].inject(0, &:+) # =>  Style/CollectionMethods: Prefer reduce over inject.

Actual behavior

[1, 2].inject(:+)     # => Nothing is flagged
[1, 2].inject(0, :+)  # => Nothing is flagged
[1, 2].inject(0, &:+) # => Nothing is flagged

Note that the following works correctly:

[1, 2].inject(&:+)                 # => Style/CollectionMethods: Prefer reduce over inject.
[1, 2].inject(0) { |a, b| a + b }  # => Style/CollectionMethods: Prefer reduce over inject.

Steps to reproduce the problem

Add an .inject to some code and run rubocop.

RuboCop version

rubocop -V

warning: parser/current is loading parser/ruby27, which recognizes
warning: 2.7.2-compliant syntax, but you are running 2.7.1.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
1.6.1 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.7.1 x86_64-darwin19)
dgollahon added a commit to mbj/mutant that referenced this issue Dec 20, 2020
dgollahon added a commit to mbj/mutant that referenced this issue Dec 20, 2020
dgollahon added a commit to mbj/mutant that referenced this issue Dec 21, 2020
@bbatsov bbatsov added the bug label Dec 21, 2020
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Dec 21, 2020
…tional arguments and methods that accept a symbol instead of a block.
bbatsov pushed a commit that referenced this issue Dec 22, 2020
…arguments and methods that accept a symbol instead of a block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants