From f36444ac39b525ce3d1f31f8d8ea8c9559c67419 Mon Sep 17 00:00:00 2001 From: GitHub Refactor Bot Date: Sat, 17 May 2025 14:29:38 +0200 Subject: [PATCH] [Fix #500] Mark `Performance/MapCompact` cop as unsafe --- changelog/fix_mark_performance_map_compact_cop_as.md | 1 + config/default.yml | 2 +- docs/modules/ROOT/pages/cops_performance.adoc | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelog/fix_mark_performance_map_compact_cop_as.md diff --git a/changelog/fix_mark_performance_map_compact_cop_as.md b/changelog/fix_mark_performance_map_compact_cop_as.md new file mode 100644 index 000000000..eca63d6f2 --- /dev/null +++ b/changelog/fix_mark_performance_map_compact_cop_as.md @@ -0,0 +1 @@ +* [#500](https://github.com/rubocop/rubocop-performance/issues/500): Mark `Performance/MapCompact` cop as unsafe. ([@jbpextra][]) diff --git a/config/default.yml b/config/default.yml index 606acb83d..d5a536369 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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: diff --git a/docs/modules/ROOT/pages/cops_performance.adoc b/docs/modules/ROOT/pages/cops_performance.adoc index 20d5fd0dc..3e6b044a1 100644 --- a/docs/modules/ROOT/pages/cops_performance.adoc +++ b/docs/modules/ROOT/pages/cops_performance.adoc @@ -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 | - @@ -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`.