Skip to content

[Fix #500] Mark Performance/MapCompact cop as unsafe #501

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_mark_performance_map_compact_cop_as.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#500](https://github.com/rubocop/rubocop-performance/issues/500): Mark `Performance/MapCompact` cop as unsafe. ([@jbpextra][])
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Performance/IoReadlines:
Performance/MapCompact:
Description: 'Use `filter_map` instead of `collection.map(&:do_something).compact`.'
Enabled: pending
SafeAutoCorrect: false
Safe: false
VersionAdded: '1.11'

Performance/MapMethodChain:
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/cops_performance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ NOTE: Requires Ruby version 2.7
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| Yes
| No
| Always (Unsafe)
| 1.11
| -
Expand All @@ -1269,7 +1269,7 @@ This cop identifies places where `map { ... }.compact` can be replaced by `filte
[#safety-performancemapcompact]
=== Safety

This cop's autocorrection is unsafe because `map { ... }.compact` might yield
This cop is unsafe because `map { ... }.compact` might yield
different results than `filter_map`. As illustrated in the example, `filter_map`
also filters out falsy values, while `compact` only gets rid of `nil`.

Expand Down