Skip to content

Commit

Permalink
Cut 1.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Apr 8, 2022
1 parent 4eab5cf commit 72bb04e
Show file tree
Hide file tree
Showing 12 changed files with 205 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.26.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux)
1.27.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux)
- rubocop-performance 1.9.1
- rubocop-rspec 2.0.0
```
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

## 1.27.0 (2022-04-08)

### New features

* [#10500](https://github.com/rubocop/rubocop/pull/10500): Add new `Lint/RefinementImportMethods` 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.

```
$ rubocop -V
1.26.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux)
1.27.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2 x86_64-linux)
- rubocop-performance 1.9.1
- rubocop-rspec 2.0.0
```
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.26', require: false
gem 'rubocop', '~> 1.27', require: false
```

See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
Expand Down
6 changes: 3 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ Lint/RefinementImportMethods:
Description: 'Use `Refinement#import_methods` when using `include` or `prepend` in `refine` block.'
Enabled: pending
SafeAutoCorrect: false
VersionAdded: '<<next>>'
VersionAdded: '1.27'

Lint/RegexpAsCondition:
Description: >-
Expand Down Expand Up @@ -4533,7 +4533,7 @@ Style/RedundantFreeze:
Style/RedundantInitialize:
Description: 'Checks for redundant `initialize` methods.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '1.27'

Style/RedundantInterpolation:
Description: 'Checks for strings that are just an interpolated expression.'
Expand Down Expand Up @@ -4656,7 +4656,7 @@ Style/SafeNavigation:
be `nil` or truthy, but never `false`.
Enabled: true
VersionAdded: '0.43'
VersionChanged: <<next>>
VersionChanged: '1.27'
# Safe navigation may cause a statement to start returning `nil` in addition
# to whatever it used to return.
ConvertCodeThatCanStartToReturnNil: false
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.27'
nav:
- modules/ROOT/nav.adoc
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ In the following section you find all available cops:
* xref:cops_lint.adoc#lintredundantstringcoercion[Lint/RedundantStringCoercion]
* xref:cops_lint.adoc#lintredundantwithindex[Lint/RedundantWithIndex]
* xref:cops_lint.adoc#lintredundantwithobject[Lint/RedundantWithObject]
* xref:cops_lint.adoc#lintrefinementimportmethods[Lint/RefinementImportMethods]
* xref:cops_lint.adoc#lintregexpascondition[Lint/RegexpAsCondition]
* xref:cops_lint.adoc#lintrequireparentheses[Lint/RequireParentheses]
* xref:cops_lint.adoc#lintrequirerelativeselfpath[Lint/RequireRelativeSelfPath]
Expand Down Expand Up @@ -524,6 +525,7 @@ In the following section you find all available cops:
* xref:cops_style.adoc#styleredundantfetchblock[Style/RedundantFetchBlock]
* xref:cops_style.adoc#styleredundantfileextensioninrequire[Style/RedundantFileExtensionInRequire]
* xref:cops_style.adoc#styleredundantfreeze[Style/RedundantFreeze]
* xref:cops_style.adoc#styleredundantinitialize[Style/RedundantInitialize]
* xref:cops_style.adoc#styleredundantinterpolation[Style/RedundantInterpolation]
* xref:cops_style.adoc#styleredundantparentheses[Style/RedundantParentheses]
* xref:cops_style.adoc#styleredundantpercentq[Style/RedundantPercentQ]
Expand Down
63 changes: 52 additions & 11 deletions docs/modules/ROOT/pages/cops_lint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,11 @@ array = [

This cop checks for `IO.select` that is incompatible with Fiber Scheduler since Ruby 3.0.

NOTE: When the method is successful the return value of `IO.select` is `[[IO]]`,
and the return value of `io.wait_readable` and `io.wait_writable` are `self`.
They are not auto-corrected when assigning a return value because these types are different.
It's up to user how to handle the return value.

=== Safety

This cop's autocorrection is unsafe because `NoMethodError` occurs
Expand Down Expand Up @@ -4342,6 +4347,52 @@ ary.each do |v|
end
----

== Lint/RefinementImportMethods

NOTE: Required Ruby version: 3.1

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

| Pending
| Yes
| No
| 1.27
| -
|===

This cop checks if `include` or `prepend` is called in `refine` block.
These methods are deprecated and should be replaced with `Refinement#import_methods`.

It emulates deprecation warnings in Ruby 3.1.

=== Safety

This cop's autocorrection is unsafe because `include M` will affect the included class
if any changes are made to module `M`.
On the other hand, `import_methods M` uses a snapshot of method definitions,
thus it will not be affected if module `M` changes.

=== Examples

[source,ruby]
----
# bad
refine Foo do
include Bar
end
# bad
refine Foo do
prepend Bar
end
# good
refine Foo do
import_methods Bar
end
----

== Lint/RegexpAsCondition

|===
Expand Down Expand Up @@ -6435,7 +6486,7 @@ end
| No
| Yes (Unsafe)
| 0.90
| -
| 0.91
|===

This cop checks for useless method definitions, specifically: empty constructors
Expand Down Expand Up @@ -6475,16 +6526,6 @@ def method(*args)
end
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| AllowComments
| `true`
| Boolean
|===

== Lint/UselessRuby2Keywords

|===
Expand Down
113 changes: 110 additions & 3 deletions docs/modules/ROOT/pages/cops_style.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,17 @@ File.binread(filename)

Favor `File.(bin)write` convenience methods.

NOTE: There are different method signatures between `File.write` (class method)
and `File#write` (instance method). The following case will be allowed because
static analysis does not know the contents of the splat argument:

[source,ruby]
----
File.open(filename, 'w') do |f|
f.write(*objects)
end
----

=== Examples

[source,ruby]
Expand Down Expand Up @@ -9708,6 +9719,95 @@ CONST = 1.freeze
CONST = 1
----

== Style/RedundantInitialize

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

| Pending
| Yes
| No
| 1.27
| -
|===

Checks for `initialize` methods that are redundant.

An initializer is redundant if it does not do anything, or if it only
calls `super` with the same arguments given to it. If the initializer takes
an argument that accepts multiple values (`restarg`, `kwrestarg`, etc.) it
will not register an offense, because it allows the initializer to take a different
number of arguments as its superclass potentially does.

NOTE: If an initializer argument has a default value, RuboCop assumes it
to *not* be redundant.

NOTE: Empty initializers are registered as offenses, but it is possible
to purposely create an empty `initialize` method to override a superclass's
initializer.

=== Examples

[source,ruby]
----
# bad
def initialize
end
# bad
def initialize
super
end
# bad
def initialize(a, b)
super
end
# bad
def initialize(a, b)
super(a, b)
end
# good
def initialize
do_something
end
# good
def initialize
do_something
super
end
# good (different number of parameters)
def initialize(a, b)
super(a)
end
# good (default value)
def initialize(a, b = 5)
super
end
# good (default value)
def initialize(a, b: 5)
super
end
# good (changes the parameter requirements)
def initialize(*)
end
# good (changes the parameter requirements)
def initialize(**)
end
# good (changes the parameter requirements)
def initialize(...)
end
----

== Style/RedundantInterpolation

|===
Expand Down Expand Up @@ -10570,15 +10670,14 @@ end
| Yes
| Yes (Unsafe)
| 0.43
| 0.77
| 1.27
|===

This cop transforms usages of a method call safeguarded by a non `nil`
check for the variable whose method is being called to
safe navigation (`&.`). If there is a method chain, all of the methods
in the chain need to be checked for safety, and all of the methods will
need to be changed to use safe navigation. We have limited the cop to
not register an offense for method chains that exceed 2 methods.
need to be changed to use safe navigation.

The default for `ConvertCodeThatCanStartToReturnNil` is `false`.
When configured to `true`, this will
Expand All @@ -10588,6 +10687,10 @@ of the method is. If this is converted to safe navigation,
`foo&.bar` can start returning `nil` as well as what the method
returns.

The default for `MaxChainLength` is `2`
We have limited the cop to not register an offense for method chains
that exceed this option is set.

=== Safety

Autocorrection is unsafe because if a value is `false`, the resulting
Expand Down Expand Up @@ -10661,6 +10764,10 @@ foo.bar > 2 if foo
| AllowedMethods
| `present?`, `blank?`, `presence`, `try`, `try!`
| Array

| MaxChainLength
| `2`
| Integer
|===

== Style/Sample
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.26', require: false
gem 'rubocop', '~> 1.27', require: false
----

NOTE: You can check out our progress on the road to version 1.0 https://github.com/rubocop/rubocop/milestone/4[here].
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.26.1'
STRING = '1.27.0'

MSG = '%<version>s (using Parser %<parser_version>s, '\
'rubocop-ast %<rubocop_ast_version>s, ' \
Expand Down
30 changes: 30 additions & 0 deletions relnotes/v1.27.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### New features

* [#10500](https://github.com/rubocop/rubocop/pull/10500): Add new `Lint/RefinementImportMethods` cop. ([@koic][])
* [#10438](https://github.com/rubocop/rubocop/issues/10438): Add new `Style/RedundantInitialize` cop to check for unnecessary `initialize` methods. ([@dvandersluis][])

### Bug fixes

* [#10464](https://github.com/rubocop/rubocop/issues/10464): Fix an incorrect autocorrect for `Lint/IncompatibleIoSelectWithFiberScheduler` when using `IO.select` with read (or write) argument and using return value. ([@koic][])
* [#10506](https://github.com/rubocop/rubocop/issues/10506): Fix an error for `Style/RaiseArgs` when `raise` with `new` method without receiver. ([@koic][])
* [#10479](https://github.com/rubocop/rubocop/issues/10479): Fix a false positive for `Lint/ShadowingOuterLocalVariable` conditional statement and block variable. ([@ydah][])
* [#10189](https://github.com/rubocop/rubocop/issues/10189): Fix `--display-style-guide` so it works together with `--format offenses`. ([@jonas054][])
* [#10465](https://github.com/rubocop/rubocop/issues/10465): Fix false positive for `Naming/BlockForwarding` when the block argument is assigned. ([@dvandersluis][])
* [#10491](https://github.com/rubocop/rubocop/pull/10491): Improve the handling of comments in `Lint/EmptyConditionalBody`, `Lint/EmptyInPattern` and `Lint/EmptyWhen` when `AllowComments` is set to `true`. ([@Darhazer][])
* [#10504](https://github.com/rubocop/rubocop/issues/10504): Fix a false positive for `Lint/UnusedMethodArgument` when using `raise NotImplementedError` with optional arguments. ([@koic][])
* [#10494](https://github.com/rubocop/rubocop/issues/10494): Fix a false positive for `Style/HashSyntax` when `return` with one line `if` condition follows (without parentheses). ([@koic][])
* [#10311](https://github.com/rubocop/rubocop/issues/10311): Fix false negative inside `do`..`end` for `Layout/RedundantLineBreak`. ([@jonas054][])
* [#10468](https://github.com/rubocop/rubocop/issues/10468): Fix a false positive for `Style/FileWrite` when a splat argument is passed to `f.write`. ([@koic][])
* [#10474](https://github.com/rubocop/rubocop/issues/10474): Fix a false positive for `Style/DoubleNegation` with `EnforcedStyle: allowed_in_returns` when inside returned conditional clauses. ([@ydah][])
* [#10388](https://github.com/rubocop/rubocop/issues/10388): Fix an incorrectly adds a disable statement for `Layout/SpaceInsideArrayLiteralBrackets` with `--disable-uncorrectable`. ([@ydah][])
* [#10489](https://github.com/rubocop/rubocop/issues/10489): Fix a false positive for `Lint/LambdaWithoutLiteralBlock` when using lambda with a symbol proc. ([@koic][])

### Changes

* [#10191](https://github.com/rubocop/rubocop/issues/10191): Add `MaxChainLength` option to `Style/SafeNavigation` and the option is 2 by default. ([@ydah][])

[@koic]: https://github.com/koic
[@dvandersluis]: https://github.com/dvandersluis
[@ydah]: https://github.com/ydah
[@jonas054]: https://github.com/jonas054
[@Darhazer]: https://github.com/Darhazer

0 comments on commit 72bb04e

Please sign in to comment.