-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 new Style/MapCompactWithConditionalBlock
cop
#10608
Add new Style/MapCompactWithConditionalBlock
cop
#10608
Conversation
d8bf005
to
c768a4a
Compare
c768a4a
to
c9daa11
Compare
c9daa11
to
55dc876
Compare
55dc876
to
d2dc8b3
Compare
Style/RedundantMapCompact
copStyle/MapCompactWithConditionalBlock
cop
Style/MapCompactWithConditionalBlock
copStyle/MapCompactWithConditionalBlock
cop
Thank you for your review. I've renamed the cop and tweaked the message. |
d2dc8b3
to
bf4012e
Compare
Prefer `select` or `reject` over `map { ... }.compact`. ## example ```ruby # bad array.map { |e| some_condition? ? e : next }.compact # bad array.map do |e| if some_condition? e else next end end.compact # bad array.map do |e| next if some_condition? e end.compact # bad array.map do |e| e if some_condition? end.compact # good array.select { |e| some_condition? } # good array.reject { |e| some_condition? } ```
bf4012e
to
0d55cb2
Compare
One more thing regarding the name - how about simply |
I'm fine with that. @koic How do you think? |
It may not be ambiguous to user because the department is different between That may be over-thinking, though... |
So... Which should we name? I feel like they're both reasonable, but a little too geeky about the difference in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming is hard. :-) Let's just go with the current name.
This cop checks for usage of
select
orreject
instead of
map { ... }.compact
.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.