Skip to content

Commit

Permalink
Cut 1.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Aug 13, 2023
1 parent 4eba6e9 commit ed66e63
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,8 @@

## master (unreleased)

## 1.19.0 (2023-08-13)

### New features

* [#364](https://github.com/rubocop/rubocop-performance/pull/364): Add new `Performance/MapMethodChain` cop. ([@koic][])
Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Expand Up @@ -197,7 +197,7 @@ Performance/MapMethodChain:
Description: 'Checks if the `map` method is used in a chain.'
Enabled: pending
Safe: false
VersionAdded: '<<next>>'
VersionAdded: '1.19'

Performance/MethodObjectAsBlock:
Description: 'Use block explicitly instead of block-passing a method object.'
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Expand Up @@ -2,6 +2,6 @@ name: rubocop-performance
title: RuboCop Performance
# We always provide version without patch here (e.g. 1.1),
# as patch versions should not appear in the docs.
version: ~
version: '1.19'
nav:
- modules/ROOT/nav.adoc
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/cops.adoc
Expand Up @@ -36,6 +36,7 @@ Performance cops optimization analysis for your projects.
* xref:cops_performance.adoc#performanceinefficienthashsearch[Performance/InefficientHashSearch]
* xref:cops_performance.adoc#performanceioreadlines[Performance/IoReadlines]
* xref:cops_performance.adoc#performancemapcompact[Performance/MapCompact]
* xref:cops_performance.adoc#performancemapmethodchain[Performance/MapMethodChain]
* xref:cops_performance.adoc#performancemethodobjectasblock[Performance/MethodObjectAsBlock]
* xref:cops_performance.adoc#performanceopenstruct[Performance/OpenStruct]
* xref:cops_performance.adoc#performancerangeinclude[Performance/RangeInclude]
Expand Down
53 changes: 53 additions & 0 deletions docs/modules/ROOT/pages/cops_performance.adoc
Expand Up @@ -1175,6 +1175,59 @@ ary.map(&:foo).compact!
ary.compact.map(&:foo)
----

== Performance/MapMethodChain

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| No
| No
| 1.19
| -
|===

Checks if the map method is used in a chain.

Autocorrection is not supported because an appropriate block variable name cannot be determined automatically.

[source,ruby]
----
class X
def initialize
@@num = 0
end
def foo
@@num += 1
self
end
def bar
@@num * 2
end
end
[X.new, X.new].map(&:foo).map(&:bar) # => [4, 4]
[X.new, X.new].map { |x| x.foo.bar } # => [2, 4]
----

=== Safety

This cop is unsafe because false positives occur if the number of times the first method is executed
affects the return value of subsequent methods.

=== Examples

[source,ruby]
----
# bad
array.map(&:foo).map(&:bar)
# good
array.map { |item| item.foo.bar }
----

== Performance/MethodObjectAsBlock

|===
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/performance/version.rb
Expand Up @@ -4,7 +4,7 @@ module RuboCop
module Performance
# This module holds the RuboCop Performance version information.
module Version
STRING = '1.18.0'
STRING = '1.19.0'

def self.document_version
STRING.match('\d+\.\d+').to_s
Expand Down
6 changes: 6 additions & 0 deletions relnotes/v1.19.0.md
@@ -0,0 +1,6 @@
### New features

* [#364](https://github.com/rubocop/rubocop-performance/pull/364): Add new `Performance/MapMethodChain` cop. ([@koic][])
* [#363](https://github.com/rubocop/rubocop-performance/pull/363): Support safe navigation operator for `Performance/ArraySemiInfiniteRangeSlice`, `Performance/DeletePrefix`, `Performance/DeleteSuffix`, `Performance/Detect`, `Performance/EndWith`, `Performance/InefficientHashSearch`, `Performance/MapCompact`, `Performance/RedundantSplitRegexpArgument`, `Performance/ReverseEach`, `Performance/ReverseFirst`, `Performance/SelectMap`, `Performance/Squeeze`, `Performance/StartWith`, `Performance/StringInclude`, and `Performance/StringReplacement` cops. ([@koic][])

[@koic]: https://github.com/koic

0 comments on commit ed66e63

Please sign in to comment.