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

Add Performance/MapCompact cop #229

Merged
merged 1 commit into from
Apr 14, 2021
Merged

Commits on Apr 12, 2021

  1. Add Performance/MapCompact cop

    Follow rubocop#211 (comment)
    
    This PR adds `Performance/MapCompact` cop
    
    In Ruby 2.7, `Enumerable#filter_map` has been added.
    
    This cop identifies places where `map { ... }.compact` can be replaced by `filter_map`.
    It is marked as unsafe auto-correction by default because `map { ... }.compact`
    that is not compatible with `filter_map`.
    
    The following is good and bad cases.
    
    ```ruby
    # bad
    ary.map(&:foo).compact
    ary.collect(&:foo).compact
    
    # good
    ary.filter_map(&:foo)
    ary.map(&:foo).compact!
    ```
    koic committed Apr 12, 2021
    Configuration menu
    Copy the full SHA
    77de934 View commit details
    Browse the repository at this point in the history