From c3111370dcd300628af89c26cadddf7b679cfbd8 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Tue, 10 Jan 2023 12:32:07 +0200 Subject: [PATCH] Cut 1.43 --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- CHANGELOG.md | 2 + CONTRIBUTING.md | 2 +- README.md | 2 +- config/default.yml | 4 +- docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops.adoc | 1 + docs/modules/ROOT/pages/cops_lint.adoc | 59 +++++++++++++++++++++++ docs/modules/ROOT/pages/cops_metrics.adoc | 14 ++++++ docs/modules/ROOT/pages/cops_style.adoc | 15 ++++-- docs/modules/ROOT/pages/installation.adoc | 2 +- lib/rubocop/version.rb | 2 +- relnotes/v1.43.0.md | 34 +++++++++++++ 13 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 relnotes/v1.43.0.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 243968b497f3..07f80b90a59e 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.42.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] +1.43.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 ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 368211832299..63af6ee6557f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +## 1.43.0 (2023-01-10) + ### New features * [#11359](https://github.com/rubocop/rubocop/issues/11359): Add new `Lint/UselessRescue` cop. ([@fatkodima][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f3d4901928ef..7201133bcbc5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ```console $ rubocop -V -1.42.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] +1.43.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 ``` diff --git a/README.md b/README.md index ecd4820ed9e2..0db6082d7eaa 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.42', require: false +gem 'rubocop', '~> 1.43', 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 b25e1663da09..a7e6540b232a 100644 --- a/config/default.yml +++ b/config/default.yml @@ -2455,7 +2455,7 @@ Lint/UselessMethodDefinition: Lint/UselessRescue: Description: 'Checks for useless `rescue`s.' Enabled: pending - VersionAdded: '<>' + VersionAdded: '1.43' Lint/UselessRuby2Keywords: Description: 'Finds unnecessary uses of `ruby2_keywords`.' @@ -5449,7 +5449,7 @@ Style/YodaExpression: Enabled: false Safe: false VersionAdded: '1.42' - VersionChanged: '<>' + VersionChanged: '1.43' SupportedOperators: - '*' - '+' diff --git a/docs/antora.yml b/docs/antora.yml index 9c897ea03d1d..fd713522f989 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.43' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index afed750c98d7..140a2bed431f 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -324,6 +324,7 @@ In the following section you find all available cops: * xref:cops_lint.adoc#lintuselessassignment[Lint/UselessAssignment] * xref:cops_lint.adoc#lintuselesselsewithoutrescue[Lint/UselessElseWithoutRescue] * xref:cops_lint.adoc#lintuselessmethoddefinition[Lint/UselessMethodDefinition] +* xref:cops_lint.adoc#lintuselessrescue[Lint/UselessRescue] * xref:cops_lint.adoc#lintuselessruby2keywords[Lint/UselessRuby2Keywords] * xref:cops_lint.adoc#lintuselesssettercall[Lint/UselessSetterCall] * xref:cops_lint.adoc#lintuselesstimes[Lint/UselessTimes] diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index acaf52aa960e..09f9451460d6 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -6938,6 +6938,65 @@ def method(*args) end ---- +== Lint/UselessRescue + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| No +| 1.43 +| - +|=== + +Checks for useless `rescue`s, which only reraise rescued exceptions. + +=== Examples + +[source,ruby] +---- +# bad +def foo + do_something +rescue + raise +end + +# bad +def foo + do_something +rescue => e + raise # or 'raise e', or 'raise $!', or 'raise $ERROR_INFO' +end + +# good +def foo + do_something +rescue + do_cleanup + raise +end + +# bad (latest rescue) +def foo + do_something +rescue ArgumentError + # noop +rescue + raise +end + +# good (not the latest rescue) +def foo + do_something +rescue ArgumentError + raise +rescue + # noop +end +---- + == Lint/UselessRuby2Keywords |=== diff --git a/docs/modules/ROOT/pages/cops_metrics.adoc b/docs/modules/ROOT/pages/cops_metrics.adoc index d2dbe7571e68..0c57000dd97e 100644 --- a/docs/modules/ROOT/pages/cops_metrics.adoc +++ b/docs/modules/ROOT/pages/cops_metrics.adoc @@ -518,6 +518,20 @@ The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters. +Any number of arguments for `initialize` method inside a block of +`Struct.new` and `Data.define` like this is always allowed: + +[source,ruby] +---- +Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do + def initialize(one:, two:, three:, four:, five:) + end +end +---- + +This is because checking the number of arguments of the `initialize` method +does not make sense. + NOTE: Explicit block argument `&block` is not counted to prevent erroneous change that is avoided by making block argument implicit. diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index f92a730c7f7a..c830e54befd3 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -5171,7 +5171,7 @@ execute(sql).values.each { |v| p v } | Name | Default value | Configurable values | AllowedReceivers -| `[]` +| `Thread.current` | Array |=== @@ -7330,7 +7330,7 @@ a <= b ? a : b | Disabled | Yes -| No +| Yes | 0.30 | 0.38 |=== @@ -15256,17 +15256,24 @@ bar > 10 |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed -| Pending +| Disabled | No | Yes (Unsafe) | 1.42 -| - +| 1.43 |=== Forbids Yoda expressions, i.e. binary operations (using `*`, `+`, `&`, `|`, and `^` operators) where the order of expression is reversed, eg. `1 + x`. This cop complements `Style/YodaCondition` cop, which has a similar purpose. +This cop is disabled by default to respect user intentions such as: + +[source,ruby] +---- +config.server_port = 9000 + ENV["TEST_ENV_NUMBER"].to_i +---- + === Safety This cop is unsafe because binary operators can be defined diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index eacd3d8c3315..74cd01c5b076 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.42', require: false +gem 'rubocop', '~> 1.43', require: false ---- .A Modular RuboCop diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index c5ca8847b4ac..8affc8370628 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.42.0' + STRING = '1.43.0' MSG = '%s (using Parser %s, ' \ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.43.0.md b/relnotes/v1.43.0.md new file mode 100644 index 000000000000..8d0acfbd0b35 --- /dev/null +++ b/relnotes/v1.43.0.md @@ -0,0 +1,34 @@ +### New features + +* [#11359](https://github.com/rubocop/rubocop/issues/11359): Add new `Lint/UselessRescue` cop. ([@fatkodima][]) +* [#11389](https://github.com/rubocop/rubocop/pull/11389): Add autocorrect for `Style/MissingElse`. ([@FnControlOption][]) + +### Bug fixes + +* [#11386](https://github.com/rubocop/rubocop/pull/11386): Fix a false positive for `Style/OperatorMethodCall` when using anonymous forwarding. ([@koic][]) +* [#11409](https://github.com/rubocop/rubocop/issues/11409): Fix an incorrect autocorrect for `Style/HashSyntax` when using hash value omission and `EnforcedStyle: no_mixed_keys`. ([@koic][]) +* [#11405](https://github.com/rubocop/rubocop/issues/11405): Fix undefined method `range_between' for Style/WhileUntilModifier. ([@such][]) +* [#11374](https://github.com/rubocop/rubocop/pull/11374): Fix an error for `Style/StringHashKeys` when using invalid symbol in encoding UTF-8 as keys. ([@koic][]) +* [#11392](https://github.com/rubocop/rubocop/pull/11392): Fix an incorrect autocorrect for `Style/RedundantDoubleSplatHashBraces` using double splat in double splat hash braces. ([@koic][]) +* [#8990](https://github.com/rubocop/rubocop/issues/8990): Make `Style/HashEachMethods` aware of built-in `Thread.current`. ([@koic][]) +* [#11390](https://github.com/rubocop/rubocop/issues/11390): Fix an incorrect autocorrect for `Style/HashSyntax` when hash first argument key and hash value only are the same which has a method call on the next line. ([@koic][]) +* [#11379](https://github.com/rubocop/rubocop/pull/11379): Fix a false negative for `Style/OperatorMethodCall` when using `a.+ b.something`. ([@koic][]) +* [#11180](https://github.com/rubocop/rubocop/issues/11180): Fix an error for `Style/RedundantRegexpEscape` when using `%r` to provide regexp expressions. ([@si-lens][]) +* [#11403](https://github.com/rubocop/rubocop/pull/11403): Fix bad offense for parenthesised calls in literals for `omit_parentheses` style in `Style/MethodCallWithArgsParentheses`. ([@gsamokovarov][]) +* [#11407](https://github.com/rubocop/rubocop/pull/11407): Fix an error for `Style/HashSyntax` when expression follows hash key assignment. ([@fatkodima][]) +* [#11377](https://github.com/rubocop/rubocop/issues/11377): Fix `Style/OperatorMethodCall` when forwarding arguments. ([@sambostock][]) + +### Changes + +* [#11382](https://github.com/rubocop/rubocop/pull/11382): Require `unicode-display_width` 2.4.0 or higher. ([@fatkodima][]) +* [#11381](https://github.com/rubocop/rubocop/pull/11381): Require Parser 3.2.0.0 or higher. ([@koic][]) +* [#11380](https://github.com/rubocop/rubocop/pull/11380): Disable `Style/YodaExpression` by default. ([@koic][]) +* [#11303](https://github.com/rubocop/rubocop/issues/11303): Make `Metrics/ParameterLists` aware of `Struct.new` and `Data.define` blocks. ([@koic][]) + +[@fatkodima]: https://github.com/fatkodima +[@FnControlOption]: https://github.com/FnControlOption +[@koic]: https://github.com/koic +[@such]: https://github.com/such +[@si-lens]: https://github.com/si-lens +[@gsamokovarov]: https://github.com/gsamokovarov +[@sambostock]: https://github.com/sambostock