Skip to content

Commit

Permalink
Cut 1.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Apr 9, 2023
1 parent f6fa98b commit 3fa6f67
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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][])
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.17'
nav:
- modules/ROOT/nav.adoc
48 changes: 42 additions & 6 deletions docs/modules/ROOT/pages/cops_performance.adoc
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
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.16.0'
STRING = '1.17.0'

def self.document_version
STRING.match('\d+\.\d+').to_s
Expand Down
11 changes: 11 additions & 0 deletions 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

0 comments on commit 3fa6f67

Please sign in to comment.