Skip to content

Performance/Sum not autocorrecting injects or reduces with blocks #171

@jmkoni

Description

@jmkoni

Expected behavior

After enabling Performance/Sum, I expect that the following lines will all be autocorrected to use sum:

[1, 2, 3].inject(:+)
[1, 2, 3].reduce(10, :+)
[1, 2, 3].reduce { |acc, elem| acc + elem }

Actual behavior

It only autocorrects the second line:

[1, 2, 3].inject(:+)
[1, 2, 3].sum(10)
[1, 2, 3].reduce { |acc, elem| acc + elem }

Steps to reproduce the problem

  1. Create a test file with those lines.
  2. Run rubocop -A
    OR
    You can replicate this bug by pulling down this project, doing a bundle install, and running rubocop -A

RuboCop version

rubocop -V
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.2, running on ruby 2.7.0 x86_64-darwin19)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions