Skip to content

Commit

Permalink
Cut 1.57
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Oct 11, 2023
1 parent 872d713 commit bfdb5ff
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example:

```
$ [bundle exec] rubocop -V
1.56.4 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
1.57.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
- rubocop-performance 1.18.0
- rubocop-rspec 2.23.2
```
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

## master (unreleased)

## 1.57.0 (2023-10-11)

### New features

* [#12227](https://github.com/rubocop/rubocop/pull/12227): Add new `Style/SingleLineDoEndBlock` cop. ([@koic][])
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do so.

```console
$ rubocop -V
1.56.4 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
1.57.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
- rubocop-performance 1.18.0
- rubocop-rspec 2.23.2
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
in your `Gemfile`:

```rb
gem 'rubocop', '~> 1.56', require: false
gem 'rubocop', '~> 1.57', require: false
```

See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
Expand Down
8 changes: 4 additions & 4 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ Lint/RedundantRequireStatement:
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.76'
VersionChanged: '<<next>>'
VersionChanged: '1.57'

Lint/RedundantSafeNavigation:
Description: 'Checks for redundant safe navigation calls.'
Expand Down Expand Up @@ -3358,7 +3358,7 @@ Style/ClassEqualityComparison:
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.93'
VersionChanged: '<<next>>'
VersionChanged: '1.57'
AllowedMethods:
- ==
- equal?
Expand Down Expand Up @@ -4926,7 +4926,7 @@ Style/RedundantFilterChain:
Enabled: pending
SafeAutoCorrect: false
VersionAdded: '1.52'
VersionChanged: '<<next>>'
VersionChanged: '1.57'

Style/RedundantFreeze:
Description: "Checks usages of Object#freeze on immutable objects."
Expand Down Expand Up @@ -5191,7 +5191,7 @@ Style/SingleLineBlockParams:
Style/SingleLineDoEndBlock:
Description: 'Checks for single-line `do`...`end` blocks.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.57'

Style/SingleLineMethods:
Description: 'Avoid single-line methods.'
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: rubocop
title: RuboCop
# We always provide version without patch here (e.g. 1.1),
# as patch versions should not appear in the docs.
version: ~
version: '1.57'
nav:
- modules/ROOT/nav.adoc
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#stylesignalexception[Style/SignalException]
* xref:cops_style.adoc#stylesingleargumentdig[Style/SingleArgumentDig]
* xref:cops_style.adoc#stylesinglelineblockparams[Style/SingleLineBlockParams]
* xref:cops_style.adoc#stylesinglelinedoendblock[Style/SingleLineDoEndBlock]
* xref:cops_style.adoc#stylesinglelinemethods[Style/SingleLineMethods]
* xref:cops_style.adoc#styleslicingwithrange[Style/SlicingWithRange]
* xref:cops_style.adoc#stylesolenestedconditional[Style/SoleNestedConditional]
Expand Down
25 changes: 20 additions & 5 deletions docs/modules/ROOT/pages/cops_lint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ end

Checks for blocks without a body.
Such empty blocks are typically an oversight or we should provide a comment
be clearer what we're aiming for.
to clarify what we're aiming for.

Empty lambdas and procs are ignored by default.

Expand Down Expand Up @@ -4598,9 +4598,9 @@ because it's unknown what kind of string will be expanded as a result:

| Enabled
| Yes
| Yes
| Yes (Unsafe)
| 0.76
| -
| 1.57
|===

Checks for unnecessary `require` statement.
Expand All @@ -4624,6 +4624,11 @@ Below are the features that each `TargetRubyVersion` targets.

This cop target those features.

=== Safety

This cop's autocorrection is unsafe because if `require 'pp'` is removed from one file,
`NameError` can be encountered when another file uses `PP.pp`.

=== Examples

[source,ruby]
Expand All @@ -4649,8 +4654,12 @@ require 'unloaded_feature'
|===

Checks for redundant safe navigation calls.
`instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`, and `equal?` methods
are checked by default. These are customizable with `AllowedMethods` option.
Use cases where a constant is `nil` are rare and an offense is detected
when the receiver is a constant.

For all receivers, the `instance_of?`, `kind_of?`, `is_a?`, `eql?`, `respond_to?`,
and `equal?` methods are checked by default.
These are customizable with `AllowedMethods` option.

The `AllowedMethods` option specifies nil-safe methods,
in other words, it is a method that is allowed to skip safe navigation.
Expand All @@ -4670,6 +4679,9 @@ will be autocorrected to never return `nil`.

[source,ruby]
----
# bad
Const&.do_something
# bad
do_something if attrs&.respond_to?(:[])
Expand All @@ -4681,6 +4693,9 @@ while node&.is_a?(BeginNode)
node = node.parent
end
# good
Const.do_something
# good
while node.is_a?(BeginNode)
node = node.parent
Expand Down
3 changes: 1 addition & 2 deletions docs/modules/ROOT/pages/cops_metrics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ You can set constructs you want to fold with `CountAsOne`.
Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct
will be counted as one line regardless of its actual size.

NOTE: This cop does not apply for `Struct` definitions.

NOTE: The `ExcludedMethods` configuration is deprecated and only kept
for backwards compatibility. Please use `AllowedMethods` and `AllowedPatterns`
instead. By default, there are no methods to allowed.

NOTE: This cop does not apply for `Struct` definitions.

=== Examples

==== CountAsOne: ['array', 'heredoc', 'method_call']
Expand Down
108 changes: 102 additions & 6 deletions docs/modules/ROOT/pages/cops_style.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1419,16 +1419,22 @@ var.kind_of?(String)

| Enabled
| Yes
| Yes
| Yes (Unsafe)
| 0.93
| -
| 1.57
|===

Enforces the use of `Object#instance_of?` instead of class comparison
for equality.
`==`, `equal?`, and `eql?` custom method definitions are allowed by default.
These are customizable with `AllowedMethods` option.

=== Safety

This cop's autocorrection is unsafe because there is no guarantee that
the constant `Foo` exists when autocorrecting `var.class.name == 'Foo'` to
`var.instance_of?(Foo)`.

=== Examples

[source,ruby]
Expand Down Expand Up @@ -4731,13 +4737,25 @@ end
|===

Enforces the use of a single string formatting utility.
Valid options include Kernel#format, Kernel#sprintf and String#%.
Valid options include `Kernel#format`, `Kernel#sprintf`, and `String#%`.

The detection of String#% cannot be implemented in a reliable
The detection of `String#%` cannot be implemented in a reliable
manner for all cases, so only two scenarios are considered -
if the first argument is a string literal and if the second
argument is an array literal.

Autocorrection will be applied when using argument is a literal or known built-in conversion
methods such as `to_d`, `to_f`, `to_h`, `to_i`, `to_r`, `to_s`, and `to_sym` on variables,
provided that their return value is not an array. For example, when using `to_s`,
`'%s' % [1, 2, 3].to_s` can be autocorrected without any incompatibility:

[source,ruby]
----
'%s' % [1, 2, 3] #=> '1'
format('%s', [1, 2, 3]) #=> '[1, 2, 3]'
'%s' % [1, 2, 3].to_s #=> '[1, 2, 3]'
----

=== Examples

==== EnforcedStyle: format (default)
Expand Down Expand Up @@ -5213,6 +5231,25 @@ end
# good
foo || raise('exception') if something
ok
# bad
define_method(:test) do
if something
work
end
end
# good
define_method(:test) do
return unless something
work
end
# also good
define_method(:test) do
work if something
end
----

==== AllowConsecutiveConditionals: false (default)
Expand Down Expand Up @@ -11184,6 +11221,12 @@ do_something(**{foo: bar, baz: qux})
# good
do_something(foo: bar, baz: qux)
# bad
do_something(**{foo: bar, baz: qux}.merge(options))
# good
do_something(foo: bar, baz: qux, **options)
----

== Style/RedundantEach
Expand Down Expand Up @@ -11383,14 +11426,21 @@ require_relative '../foo.so'

| Pending
| Yes
| Yes
| Yes (Unsafe)
| 1.52
| -
| 1.57
|===

Identifies usages of `any?`, `empty?` or `none?` predicate methods
chained to `select`/`filter`/`find_all` and change them to use predicate method instead.

=== Safety

This cop's autocorrection is unsafe because `array.select.any?` evaluates all elements
through the `select` method, while `array.any?` uses short-circuit evaluation.
In other words, `array.select.any?` guarantees the evaluation of every element,
but `array.any?` does not necessarily evaluate all of them.

=== Examples

[source,ruby]
Expand Down Expand Up @@ -11419,6 +11469,9 @@ arr.select { |x| x > 1 }.any?(&:odd?)
----
# good
arr.select { |x| x > 1 }.many?
# good
arr.select { |x| x > 1 }.present?
----

==== AllCops:ActiveSupportExtensionsEnabled: true
Expand All @@ -11430,6 +11483,12 @@ arr.select { |x| x > 1 }.many?
# good
arr.many? { |x| x > 1 }
# bad
arr.select { |x| x > 1 }.present?
# good
arr.any? { |x| x > 1 }
----

== Style/RedundantFreeze
Expand Down Expand Up @@ -13457,6 +13516,43 @@ end
| Array
|===

== Style/SingleLineDoEndBlock

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

| Pending
| Yes
| Yes
| 1.57
| -
|===

Checks for single-line `do`...`end` block.

In practice a single line `do`...`end` is autocorrected when `EnforcedStyle: semantic`
in `Style/BlockDelimiters`. The autocorrection maintains the `do` ... `end` syntax to
preserve semantics and does not change it to `{`...`}` block.

=== Examples

[source,ruby]
----
# bad
foo do |arg| bar(arg) end
# good
foo do |arg|
bar(arg)
end
# bad
->(arg) do bar(arg) end
# good
->(arg) { bar(arg) }
----

== Style/SingleLineMethods

|===
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/installation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ in your `Gemfile`:

[source,rb]
----
gem 'rubocop', '~> 1.56', require: false
gem 'rubocop', '~> 1.57', require: false
----

.A Modular RuboCop
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
# This module holds the RuboCop version information.
module Version
STRING = '1.56.4'
STRING = '1.57.0'

MSG = '%<version>s (using Parser %<parser_version>s, ' \
'rubocop-ast %<rubocop_ast_version>s, ' \
Expand Down

0 comments on commit bfdb5ff

Please sign in to comment.