From 3fa6f672b08311842e43478598726d6bf2845e96 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 9 Apr 2023 15:39:11 +0900 Subject: [PATCH] Cut 1.17.0 --- CHANGELOG.md | 2 + docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops_performance.adoc | 48 ++++++++++++++++--- lib/rubocop/performance/version.rb | 2 +- relnotes/v1.17.0.md | 11 +++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 relnotes/v1.17.0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 839229b37a..489908a598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ## master (unreleased) +## 1.17.0 (2023-04-09) + ### New features * [#347](https://github.com/rubocop/rubocop-performance/pull/347): Add `AllowRegexpMatch` option to `Performance/RedundantEqualityComparisonBlock`. ([@koic][]) diff --git a/docs/antora.yml b/docs/antora.yml index 21b1815a34..96218f744a 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -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.17' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops_performance.adoc b/docs/modules/ROOT/pages/cops_performance.adoc index 197bdb07f9..387391d5d8 100644 --- a/docs/modules/ROOT/pages/cops_performance.adoc +++ b/docs/modules/ROOT/pages/cops_performance.adoc @@ -754,12 +754,9 @@ chained to `select`, `find_all` or `filter` and change them to use === Safety -This cop is unsafe because is assumes the class implements the -`Enumerable` interface, but can't reliably detect this. This creates -known compatibility issues with `Hash`, `ActiveRecord` and other -frameworks. `Hash` and `ActiveRecord` do not implement a `detect` -method and `find` has its own meaning. Correcting `Hash` and -`ActiveRecord` methods with this cop should be considered unsafe. +This cop is unsafe because it assumes that the receiver is an +`Array` or equivalent, but can't reliably detect it. For example, +if the receiver is a `Hash`, it may report a false positive. === Examples @@ -1357,6 +1354,16 @@ By default, `Object#===` behaves the same as `Object#==`, but this behavior is appropriately overridden in subclass. For example, `Range#===` returns `true` when argument is within the range. +This cop has `AllowRegexpMatch` option and it is false by default because +`regexp.match?('string')` often used in block changes to the opposite result: + +[source,ruby] +---- +[/pattern/].all? { |regexp| regexp.match?('pattern') } # => true +[/pattern/].all? { |regexp| regexp =~ 'pattern' } # => true +[/pattern/].all?('pattern') # => false +---- + === Safety This cop is unsafe because `===` and `==` do not always behave the same. @@ -1373,8 +1380,37 @@ items.all? { |item| item.kind_of?(Klass) } # good items.all?(pattern) +items.all?(Klass) +---- + +==== AllowRegexpMatch: true (default) + +[source,ruby] +---- +# good +items.all? { |item| item =~ pattern } +items.all? { |item| item.match?(pattern) } +---- + +==== AllowRegexpMatch: false + +[source,ruby] +---- +# bad +items.all? { |item| item =~ pattern } +items.all? { |item| item.match?(pattern) } ---- +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| AllowRegexpMatch +| `false` +| Boolean +|=== + === References * https://github.com/rails/rails/pull/41363 diff --git a/lib/rubocop/performance/version.rb b/lib/rubocop/performance/version.rb index 0de76a386c..68aaf61b2c 100644 --- a/lib/rubocop/performance/version.rb +++ b/lib/rubocop/performance/version.rb @@ -4,7 +4,7 @@ module RuboCop module Performance # This module holds the RuboCop Performance version information. module Version - STRING = '1.16.0' + STRING = '1.17.0' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v1.17.0.md b/relnotes/v1.17.0.md new file mode 100644 index 0000000000..d871cf44ec --- /dev/null +++ b/relnotes/v1.17.0.md @@ -0,0 +1,11 @@ +### New features + +* [#347](https://github.com/rubocop/rubocop-performance/pull/347): Add `AllowRegexpMatch` option to `Performance/RedundantEqualityComparisonBlock`. ([@koic][]) + +### Bug fixes + +* [#346](https://github.com/rubocop/rubocop-performance/issues/346): Fix a false positive for `Performance/StringIdentifierArgument` when using a command method with receiver. ([@koic][]) +* [#344](https://github.com/rubocop/rubocop-performance/issues/344): Fix `Performance/FlatMap` autocorrection for chained methods on separate lines. ([@fatkodima][]) + +[@koic]: https://github.com/koic +[@fatkodima]: https://github.com/fatkodima