-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
[Fix #178] Add new Performance/SelectMap
cop
#211
Conversation
bd31073
to
11d3c61
Compare
I'm not sure we should enable this cop by default; in many cases (including the examples with |
Yeah, I have no strong objection to disabling this cop by default. On the other hand, Performance department's cop may prioritize performance over code readability (e.g. |
2751929
to
28b6369
Compare
I agree that generally it's fine to have the performance cop optimize for speed over clarity. After all that's what they are meant to do, and that's also part of the reason they are not part of the main RuboCop anymore. |
I think about splitting this cop into two. 1.
|
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 `select.map` 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.select(&:foo).compact # good ary.filter_map(&:foo) ary.map(&:foo).compact! ```
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! ```
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! ```
28b6369
to
f31af62
Compare
The cop have been split into |
Performance/FilterMap
copPerformance/SelectMap
cop
I agree performance cops should be disabled by default, also because many of them depend on VM implementation details, so they may sometimes be slower on a different Ruby version from which it was first tested. As far as I know, no-one keeps track of these micro-optimizations across Ruby versions. |
Sure. Since the performance result of Performance cops depends on Ruby implementations, I think it would be better to add to documentation that it is at least based on CRuby.
Which the Performance cops does this refer to? If all the Performance cops were pointed to, rubocop-performance gem itself would be meaningless 😅 I think it will be considered individually whether it can be disabled by default. To return to this PR topic :-) |
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! ```
Fixes rubocop#178 and rubocop#193. This PR adds new `Performance/SelectMap` cop. In Ruby 2.7, `Enumerable#filter_map` has been added. This cop identifies places where `select.map` can be replaced by `filter_map`. The following is good and bad cases. ```ruby # bad ary.select(&:foo).map(&:bar) ary.filter(&:foo).map(&:bar) # good ary.filter_map { |o| o.bar if o.foo } ```
f31af62
to
f267ffe
Compare
Follow rubocop/rubocop-performance#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! ```
Follow rubocop/rubocop-performance#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! ```
Follow rubocop/rubocop-performance#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! ```
Follow rubocop/rubocop-performance#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! ```
Fixes #178 and #193.
This PR adds new
Performance/SelectMap
cop.In Ruby 2.7,
Enumerable#filter_map
has been added.This cop identifies places where
select.map
can be replaced byfilter_map
. And it allowsmap { ... }.compact
that is not compatible withfilter_map
.The following is good and bad cases.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.