From e5a164a26f8ecba81d44e974e8e3569c550968cd Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 11 Dec 2023 11:24:03 +0100 Subject: [PATCH] Cut 1.59 --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- CHANGELOG.md | 2 + CONTRIBUTING.md | 2 +- README.md | 2 +- config/default.yml | 2 +- docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops.adoc | 1 + docs/modules/ROOT/pages/cops_layout.adoc | 2 +- docs/modules/ROOT/pages/cops_lint.adoc | 50 ++++++++++++++++++++--- docs/modules/ROOT/pages/cops_metrics.adoc | 6 +-- docs/modules/ROOT/pages/cops_style.adoc | 19 ++++++--- docs/modules/ROOT/pages/installation.adoc | 2 +- lib/rubocop/version.rb | 2 +- relnotes/v1.59.0.md | 49 ++++++++++++++++++++++ 14 files changed, 121 insertions(+), 22 deletions(-) create mode 100644 relnotes/v1.59.0.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 19dd71e099e0..92afb0aacce1 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example: ``` $ [bundle exec] rubocop -V -1.58.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] +1.59.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 ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index f953555b1286..44cdc3f2ad5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ## master (unreleased) +## 1.59.0 (2023-12-11) + ### New features * [#12516](https://github.com/rubocop/rubocop/pull/12516): Add new `Lint/ItWithoutArgumentsInBlock` cop. ([@koic][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f92160e9603a..48895c1a7a7e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ```console $ rubocop -V -1.58.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] +1.59.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 ``` diff --git a/README.md b/README.md index 976342ca492d..42df4af363a7 100644 --- a/README.md +++ b/README.md @@ -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.58', require: false +gem 'rubocop', '~> 1.59', require: false ``` See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details. diff --git a/config/default.yml b/config/default.yml index 96847bbdf3b9..003aac98f03d 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1967,7 +1967,7 @@ Lint/ItWithoutArgumentsInBlock: Description: 'Checks uses of `it` calls without arguments in block.' Reference: 'https://bugs.ruby-lang.org/issues/18980' Enabled: pending - VersionAdded: '<>' + VersionAdded: '1.59' Lint/LambdaWithoutLiteralBlock: Description: 'Checks uses of lambda without a literal block.' diff --git a/docs/antora.yml b/docs/antora.yml index 9c897ea03d1d..c68c28222788 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -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.59' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 4b65e6a8d4c8..0aea3d2af73f 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -253,6 +253,7 @@ In the following section you find all available cops: * xref:cops_lint.adoc#lintineffectiveaccessmodifier[Lint/IneffectiveAccessModifier] * xref:cops_lint.adoc#lintinheritexception[Lint/InheritException] * xref:cops_lint.adoc#lintinterpolationcheck[Lint/InterpolationCheck] +* xref:cops_lint.adoc#lintitwithoutargumentsinblock[Lint/ItWithoutArgumentsInBlock] * xref:cops_lint.adoc#lintlambdawithoutliteralblock[Lint/LambdaWithoutLiteralBlock] * xref:cops_lint.adoc#lintliteralascondition[Lint/LiteralAsCondition] * xref:cops_lint.adoc#lintliteralassignmentincondition[Lint/LiteralAssignmentInCondition] diff --git a/docs/modules/ROOT/pages/cops_layout.adoc b/docs/modules/ROOT/pages/cops_layout.adoc index 6e6be1ed7f30..047265e216d8 100644 --- a/docs/modules/ROOT/pages/cops_layout.adoc +++ b/docs/modules/ROOT/pages/cops_layout.adoc @@ -3734,7 +3734,7 @@ are indented one step. Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default), this cop does not add any offenses for long here documents to - avoid `Layout/LineLength`'s offenses. + avoid ``Layout/LineLength``'s offenses. === Examples diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index 1d9fecdd6465..71c3db199266 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -440,10 +440,10 @@ BigDecimal(123.456, 3) Checks for places where binary operator has identical operands. It covers arithmetic operators: `-`, `/`, `%`; -comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`; +comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, ``<=``; bitwise operators: `|`, `^`, `&`; boolean operators: `&&`, `||` -and "spaceship" operator - `<=>`. +and "spaceship" operator - ``<=>``. Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`, `<<` and `>>`. Although these can be rewritten in a different way, it should not be necessary to @@ -693,7 +693,7 @@ end | - |=== -Checks for overwriting an exception with an exception result by use `rescue =>`. +Checks for overwriting an exception with an exception result by use ``rescue =>``. You intended to write as `rescue StandardError`. However, you have written `rescue => StandardError`. @@ -3027,6 +3027,46 @@ foo = 'something with #{interpolation} inside' foo = "something with #{interpolation} inside" ---- +== Lint/ItWithoutArgumentsInBlock + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| No +| 1.59 +| - +|=== + +Emulates the following Ruby warning in Ruby 3.3. + +[source,ruby] +---- +$ ruby -e '0.times { it }' +-e:1: warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; +use it() or self.it +---- + +`it` calls without arguments will refer to the first block param in Ruby 3.4. +So use `it()` or `self.it` to ensure compatibility. + +=== Examples + +[source,ruby] +---- +# bad +do_something { it } + +# good +do_something { it() } +do_something { self.it } +---- + +=== References + +* https://bugs.ruby-lang.org/issues/18980 + == Lint/LambdaWithoutLiteralBlock |=== @@ -3999,7 +4039,7 @@ fails. Cop prefer parsing with number class instead. Conversion with `Integer`, `Float`, etc. will raise an `ArgumentError` if given input that is not numeric (eg. an empty string), whereas -`to_i`, etc. will try to convert regardless of input (`''.to_i => 0`). +`to_i`, etc. will try to convert regardless of input (``''.to_i => 0``). As such, this cop is disabled by default because it's not necessarily always correct to raise if a value is not numeric. @@ -7489,7 +7529,7 @@ end |=== Checks for uses of `Integer#times` that will never yield -(when the integer <= 0) or that will only ever yield once +(when the integer ``<= 0``) or that will only ever yield once (`1.times`). === Safety diff --git a/docs/modules/ROOT/pages/cops_metrics.adoc b/docs/modules/ROOT/pages/cops_metrics.adoc index 473d0a9a8f33..5e2d1e63b407 100644 --- a/docs/modules/ROOT/pages/cops_metrics.adoc +++ b/docs/modules/ROOT/pages/cops_metrics.adoc @@ -19,9 +19,9 @@ and https://en.wikipedia.org/wiki/ABC_Software_Metric. Interpreting ABC size: -* <= 17 satisfactory -* 18..30 unsatisfactory -* > 30 dangerous +* ``<= 17`` satisfactory +* `18..30` unsatisfactory +* `>` 30 dangerous You can have repeated "attributes" calls count as a single "branch". For this purpose, attributes are any method with no argument; no attempt diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index d369350acc8c..0f9da9f90513 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -7587,6 +7587,9 @@ Checks for unwanted parentheses in parameterless method calls. This cop can be customized allowed methods with `AllowedMethods`. By default, there are no methods to allowed. +NOTE: This cop allows the use of `it()` without arguments in blocks, +as in `0.times { it() }`, following `Lint/ItWithoutArgumentsInBlock` cop. + === Examples [source,ruby] @@ -10124,8 +10127,8 @@ allow(test_double).to receive(:a).and_return('b') |=== Checks for redundant dot before operator method call. -The target operator methods are `|`, `^`, `&`, `<=>`, `==`, `===`, `=~`, `>`, `>=`, `<`, -`<=`, `<<`, `>>`, `+`, `-`, `*`, `/`, `%`, `**`, `~`, `!`, `!=`, and `!~`. +The target operator methods are `|`, `^`, `&`, ``<=>``, `==`, `===`, `=~`, `>`, `>=`, `<`, +``<=``, `<<`, `>>`, `+`, `-`, `*`, `/`, `%`, `**`, `~`, `!`, `!=`, and `!~`. === Examples @@ -12268,7 +12271,8 @@ Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way. Note we allow uses of `self` with operators because it would be awkward -otherwise. +otherwise. Also allows the use of `self.it` without arguments in blocks, +as in `0.times { self.it }`, following `Lint/ItWithoutArgumentsInBlock` cop. === Examples @@ -12402,7 +12406,7 @@ after which only the first or last element is used. This cop is unsafe, because `sort...last` and `max` may not return the same element in all cases. -In an enumerable where there are multiple elements where `a <=> b == 0`, +In an enumerable where there are multiple elements where ``a <=> b == 0``, or where the transformation done by the `sort_by` block has the same result, `sort.last` and `max` (or `sort_by.last` and `max_by`) will return different elements. `sort.last` will return the last @@ -13558,8 +13562,11 @@ explicit_receiver.raise | - |=== -Sometimes using dig method ends up with just a single -argument. In such cases, dig should be replaced with []. +Sometimes using `dig` method ends up with just a single +argument. In such cases, dig should be replaced with `[]`. + +Since replacing `hash&.dig(:key)` with `hash[:key]` could potentially lead to error, +calls to the `dig` method using safe navigation will be ignored. === Safety diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index 05522589998d..63648fcff37f 100644 --- a/docs/modules/ROOT/pages/installation.adoc +++ b/docs/modules/ROOT/pages/installation.adoc @@ -22,7 +22,7 @@ in your `Gemfile`: [source,rb] ---- -gem 'rubocop', '~> 1.58', require: false +gem 'rubocop', '~> 1.59', require: false ---- .A Modular RuboCop diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index 8e642a8ae44c..fe36149b32dc 100644 --- a/lib/rubocop/version.rb +++ b/lib/rubocop/version.rb @@ -3,7 +3,7 @@ module RuboCop # This module holds the RuboCop version information. module Version - STRING = '1.58.0' + STRING = '1.59.0' MSG = '%s (using Parser %s, ' \ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.59.0.md b/relnotes/v1.59.0.md new file mode 100644 index 000000000000..db7fef2106a7 --- /dev/null +++ b/relnotes/v1.59.0.md @@ -0,0 +1,49 @@ +### New features + +* [#12516](https://github.com/rubocop/rubocop/pull/12516): Add new `Lint/ItWithoutArgumentsInBlock` cop. ([@koic][]) + +### Bug fixes + +* [#12434](https://github.com/rubocop/rubocop/issues/12434): Fix a false positive for `Lint/LiteralAssignmentInCondition` when using interpolated string or xstring literals. ([@koic][]) +* [#12435](https://github.com/rubocop/rubocop/issues/12435): Fix a false positive for `Lint/SelfAssignment` when using attribute assignment with method call with arguments. ([@koic][]) +* [#12444](https://github.com/rubocop/rubocop/issues/12444): Fix false positive for `Style/HashEachMethods` when receiver literal is not a hash literal. ([@koic][]) +* [#12524](https://github.com/rubocop/rubocop/issues/12524): Fix a false positive for `Style/MethodCallWithArgsParentheses` when `EnforcedStyle: omit_parentheses` and parens in `when` clause is used to pass an argument. ([@koic][]) +* [#12505](https://github.com/rubocop/rubocop/pull/12505): Fix a false positive for `Style/RedundantParentheses` when using parenthesized `lambda` or `proc` with `do`...`end` block. ([@koic][]) +* [#12442](https://github.com/rubocop/rubocop/issues/12442): Fix an incorrect autocorrect for `Style/CombinableLoops` when looping over the same data as previous loop in `do`...`end` and `{`...`}` blocks. ([@koic][]) +* [#12432](https://github.com/rubocop/rubocop/pull/12432): Fix a false positive for `Lint/LiteralAssignmentInCondition` when using parallel assignment with splat operator in block of guard condition. ([@koic][]) +* [#12441](https://github.com/rubocop/rubocop/issues/12441): Fix false positives for `Style/HashEachMethods` when using destructed block arguments. ([@koic][]) +* [#12436](https://github.com/rubocop/rubocop/issues/12436): Fix false positives for `Style/RedundantParentheses` when a part of range is a parenthesized condition. ([@koic][]) +* [#12429](https://github.com/rubocop/rubocop/issues/12429): Fix incorrect autocorrect for `Style/MapToHash` when using dot method calls for `to_h`. ([@koic][]) +* [#12488](https://github.com/rubocop/rubocop/issues/12488): Make `Lint/HashCompareByIdentity` aware of safe navigation operator. ([@koic][]) +* [#12489](https://github.com/rubocop/rubocop/issues/12489): Make `Lint/NextWithoutAccumulator` aware of safe navigation operator. ([@koic][]) +* [#12490](https://github.com/rubocop/rubocop/issues/12490): Make `Lint/NumberConversion` aware of safe navigation operator. ([@koic][]) +* [#12491](https://github.com/rubocop/rubocop/issues/12491): Make `Lint/RedundantWithIndex` aware of safe navigation operator. ([@koic][]) +* [#12492](https://github.com/rubocop/rubocop/issues/12492): Make `Lint/RedundantWithObject` aware of safe navigation operator. ([@koic][]) +* [#12493](https://github.com/rubocop/rubocop/issues/12493): Make `Lint/UnmodifiedReduceAccumulator` aware of safe navigation operator. ([@koic][]) +* [#12473](https://github.com/rubocop/rubocop/issues/12473): Make `Style/ClassCheck` aware of safe navigation operator. ([@koic][]) +* [#12445](https://github.com/rubocop/rubocop/issues/12445): Make `Style/CollectionCompact` aware of safe navigation operator. ([@koic][]) +* [#12474](https://github.com/rubocop/rubocop/issues/12474): Make `Style/ConcatArrayLiterals` aware of safe navigation operator. ([@koic][]) +* [#12476](https://github.com/rubocop/rubocop/issues/12476): Make `Style/DateTime` aware of safe navigation operator. ([@koic][]) +* [#12479](https://github.com/rubocop/rubocop/issues/12479): Make `Style/EachWithObject` aware of safe navigation operator. ([@koic][]) +* [#12446](https://github.com/rubocop/rubocop/issues/12446): Make `Style/HashExcept` aware of safe navigation operator. ([@koic][]) +* [#12447](https://github.com/rubocop/rubocop/issues/12447): Make `Style/MapCompactWithConditionalBlock` aware of safe navigation operator. ([@koic][]) +* [#12484](https://github.com/rubocop/rubocop/issues/12484): Make `Style/Next` aware of safe navigation operator. ([@koic][]) +* [#12486](https://github.com/rubocop/rubocop/issues/12486): Make `Style/RedundantArgument` aware of safe navigation operator. ([@koic][]) +* [#12454](https://github.com/rubocop/rubocop/issues/12454): Make `Style/RedundantFetchBlock` aware of safe navigation operator. ([@koic][]) +* [#12495](https://github.com/rubocop/rubocop/issues/12495): Make `Layout/RedundantLineBreak` aware of safe navigation operator. ([@koic][]) +* [#12455](https://github.com/rubocop/rubocop/issues/12455): Make `Style/RedundantSortBy` aware of safe navigation operator. ([@koic][]) +* [#12456](https://github.com/rubocop/rubocop/issues/12456): Make `Style/RedundantSortBy` aware of safe navigation operator. ([@koic][]) +* [#12480](https://github.com/rubocop/rubocop/issues/12480): Make `Style/ExactRegexpMatch` aware of safe navigation operator. ([@koic][]) +* [#12457](https://github.com/rubocop/rubocop/issues/12457): Make `Style/Sample` aware of safe navigation operator. ([@koic][]) +* [#12458](https://github.com/rubocop/rubocop/issues/12458): Make `Style/SelectByRegexp` cops aware of safe navigation operator. ([@koic][]) +* [#12494](https://github.com/rubocop/rubocop/issues/12494): Make `Layout/SingleLineBlockChain` aware of safe navigation operator. ([@koic][]) +* [#12461](https://github.com/rubocop/rubocop/issues/12461): Make `Style/StringChars` aware of safe navigation operator. ([@koic][]) +* [#12468](https://github.com/rubocop/rubocop/issues/12468): Make `Style/Strip` aware of safe navigation operator. ([@koic][]) +* [#12469](https://github.com/rubocop/rubocop/issues/12469): Make `Style/UnpackFirst` aware of safe navigation operator. ([@koic][]) + +### Changes + +* [#12522](https://github.com/rubocop/rubocop/pull/12522): Make `Style/MethodCallWithoutArgsParentheses` allow the parenthesized `it` method in a block. ([@koic][]) +* [#12523](https://github.com/rubocop/rubocop/pull/12523): Make `Style/RedundantSelf` allow the `self.it` method in a block. ([@koic][]) + +[@koic]: https://github.com/koic