diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 0c635680c900..26e78f5c15e1 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.39.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] +1.40.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 b93b57202b5e..3204aca7c8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +## 1.40.0 (2022-12-08) + ### New features * [#11179](https://github.com/rubocop/rubocop/pull/11179): Add `Style/ConstantBase` cop. ([@r7kamura][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2566c165abc3..265b31b53a72 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ```console $ rubocop -V -1.39.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] +1.40.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 2c2911499ac9..dfc29bc4ca1d 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.39', require: false +gem 'rubocop', '~> 1.40', 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 097cd76ce61c..dd2aa9524d4e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -163,7 +163,7 @@ Bundler/DuplicatedGem: Enabled: true Severity: warning VersionAdded: '0.46' - VersionChanged: '<>' + VersionChanged: '1.40' Include: - '**/*.gemfile' - '**/Gemfile' @@ -217,7 +217,7 @@ Bundler/InsecureProtocolSource: Enabled: true Severity: warning VersionAdded: '0.50' - VersionChanged: '<>' + VersionChanged: '1.40' AllowHttpProtocol: true Include: - '**/*.gemfile' @@ -258,7 +258,7 @@ Gemspec/DeprecatedAttributeAssignment: Enabled: pending Severity: warning VersionAdded: '1.30' - VersionChanged: '<>' + VersionChanged: '1.40' Include: - '**/*.gemspec' @@ -267,7 +267,7 @@ Gemspec/DuplicatedAssignment: Enabled: true Severity: warning VersionAdded: '0.52' - VersionChanged: '<>' + VersionChanged: '1.40' Include: - '**/*.gemspec' @@ -288,7 +288,7 @@ Gemspec/RequireMFA: Enabled: pending Severity: warning VersionAdded: '1.23' - VersionChanged: '<>' + VersionChanged: '1.40' Reference: - https://guides.rubygems.org/mfa-requirement-opt-in/ Include: @@ -299,7 +299,7 @@ Gemspec/RequiredRubyVersion: Enabled: true Severity: warning VersionAdded: '0.52' - VersionChanged: '<>' + VersionChanged: '1.40' Include: - '**/*.gemspec' @@ -309,7 +309,7 @@ Gemspec/RubyVersionGlobalsUsage: Enabled: true Severity: warning VersionAdded: '0.72' - VersionChanged: '<>' + VersionChanged: '1.40' Include: - '**/*.gemspec' @@ -393,7 +393,7 @@ Layout/AssignmentIndentation: Enabled: true SafeAutoCorrect: false VersionAdded: '0.49' - VersionChanged: '<>' + VersionChanged: '1.40' # By default the indentation width from `Layout/IndentationWidth` is used, # but it can be overridden by setting this parameter. IndentationWidth: ~ @@ -1657,7 +1657,7 @@ Lint/DeprecatedConstants: Description: 'Checks for deprecated constants.' Enabled: pending VersionAdded: '1.8' - VersionChanged: '<>' + VersionChanged: '1.40' # You can configure deprecated constants. # If there is an alternative method, you can set alternative value as `Alternative`. # And you can set the deprecated version as `DeprecatedVersion`. @@ -1918,7 +1918,7 @@ Lint/InterpolationCheck: Enabled: true SafeAutoCorrect: false VersionAdded: '0.50' - VersionChanged: '<>' + VersionChanged: '1.40' Lint/LambdaWithoutLiteralBlock: Description: 'Checks uses of lambda without a literal block.' @@ -3037,7 +3037,7 @@ Style/ArrayCoercion: Style/ArrayIntersect: Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.' Enabled: 'pending' - VersionAdded: '<>' + VersionAdded: '1.40' Style/ArrayJoin: Description: 'Use Array#join instead of Array#*.' @@ -4686,7 +4686,7 @@ Style/RedundantArgument: Enabled: pending Safe: false VersionAdded: '1.4' - VersionChanged: '<>' + VersionChanged: '1.40' Methods: # Array#join join: '' @@ -4729,7 +4729,7 @@ Style/RedundantConditional: Style/RedundantConstantBase: Description: Avoid redundant `::` prefix on constant. Enabled: pending - VersionAdded: '<>' + VersionAdded: '1.40' Style/RedundantEach: Description: 'Checks for redundant `each`.' @@ -4875,7 +4875,7 @@ Style/RequireOrder: Description: Sort `require` and `require_relative` in alphabetical order. Enabled: false SafeAutoCorrect: false - VersionAdded: '<>' + VersionAdded: '1.40' Style/RescueModifier: Description: 'Avoid using rescue in its modifier form.' @@ -5161,7 +5161,7 @@ Style/SymbolProc: Enabled: true Safe: false VersionAdded: '0.26' - VersionChanged: '<>' + VersionChanged: '1.40' AllowMethodsWithArguments: false # A list of method names to be always allowed by the check. # The names should be fairly unique, otherwise you'll end up ignoring lots of code. diff --git a/docs/antora.yml b/docs/antora.yml index 9c897ea03d1d..557e377371cf 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.40' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 6f114550d0bc..9c2474423dcd 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -384,6 +384,7 @@ In the following section you find all available cops: * xref:cops_style.adoc#styleandor[Style/AndOr] * xref:cops_style.adoc#styleargumentsforwarding[Style/ArgumentsForwarding] * xref:cops_style.adoc#stylearraycoercion[Style/ArrayCoercion] +* xref:cops_style.adoc#stylearrayintersect[Style/ArrayIntersect] * xref:cops_style.adoc#stylearrayjoin[Style/ArrayJoin] * xref:cops_style.adoc#styleasciicomments[Style/AsciiComments] * xref:cops_style.adoc#styleattr[Style/Attr] @@ -540,6 +541,7 @@ In the following section you find all available cops: * xref:cops_style.adoc#styleredundantcapitalw[Style/RedundantCapitalW] * xref:cops_style.adoc#styleredundantcondition[Style/RedundantCondition] * xref:cops_style.adoc#styleredundantconditional[Style/RedundantConditional] +* xref:cops_style.adoc#styleredundantconstantbase[Style/RedundantConstantBase] * xref:cops_style.adoc#styleredundanteach[Style/RedundantEach] * xref:cops_style.adoc#styleredundantexception[Style/RedundantException] * xref:cops_style.adoc#styleredundantfetchblock[Style/RedundantFetchBlock] @@ -559,6 +561,7 @@ In the following section you find all available cops: * xref:cops_style.adoc#styleredundantsortby[Style/RedundantSortBy] * xref:cops_style.adoc#styleredundantstringescape[Style/RedundantStringEscape] * xref:cops_style.adoc#styleregexpliteral[Style/RegexpLiteral] +* xref:cops_style.adoc#stylerequireorder[Style/RequireOrder] * xref:cops_style.adoc#stylerescuemodifier[Style/RescueModifier] * xref:cops_style.adoc#stylerescuestandarderror[Style/RescueStandardError] * xref:cops_style.adoc#stylereturnnil[Style/ReturnNil] diff --git a/docs/modules/ROOT/pages/cops_bundler.adoc b/docs/modules/ROOT/pages/cops_bundler.adoc index c9ea1a605b6c..454d018e8c4a 100644 --- a/docs/modules/ROOT/pages/cops_bundler.adoc +++ b/docs/modules/ROOT/pages/cops_bundler.adoc @@ -9,7 +9,7 @@ | Yes | No | 0.46 -| - +| 1.40 |=== A Gem's requirements should be listed only once in a Gemfile. @@ -54,6 +54,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemfile+`, `+**/Gemfile+`, `+**/gems.rb+` | Array @@ -339,7 +343,7 @@ gem 'rubocop', tag: 'v1.17.0' | Yes | Yes | 0.50 -| - +| 1.40 |=== Passing symbol arguments to `source` (e.g. `source :rubygems`) is @@ -392,6 +396,10 @@ source 'http://rubygems.org' |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | AllowHttpProtocol | `true` | Boolean diff --git a/docs/modules/ROOT/pages/cops_gemspec.adoc b/docs/modules/ROOT/pages/cops_gemspec.adoc index 6246cd958935..16cf6ac10991 100644 --- a/docs/modules/ROOT/pages/cops_gemspec.adoc +++ b/docs/modules/ROOT/pages/cops_gemspec.adoc @@ -94,7 +94,7 @@ end | Yes | Yes | 1.30 -| - +| 1.40 |=== Checks that deprecated attribute attributes are not set in a gemspec file. @@ -127,6 +127,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemspec+` | Array @@ -141,7 +145,7 @@ end | Yes | No | 0.52 -| - +| 1.40 |=== An attribute assignment method calls should be listed only once @@ -185,6 +189,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemspec+` | Array @@ -281,7 +289,7 @@ spec.add_dependency 'rspec' | Yes | Yes | 1.23 -| - +| 1.40 |=== Requires a gemspec to have `rubygems_mfa_required` metadata set. @@ -350,6 +358,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemspec+` | Array @@ -368,7 +380,7 @@ end | Yes | No | 0.52 -| 1.22 +| 1.40 |=== Checks that `required_ruby_version` in a gemspec file is set to a valid @@ -430,6 +442,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemspec+` | Array @@ -444,7 +460,7 @@ end | Yes | No | 0.72 -| - +| 1.40 |=== Checks that `RUBY_VERSION` constant is not used in gemspec. @@ -477,6 +493,10 @@ end |=== | Name | Default value | Configurable values +| Severity +| `warning` +| String + | Include | `+**/*.gemspec+` | Array diff --git a/docs/modules/ROOT/pages/cops_layout.adoc b/docs/modules/ROOT/pages/cops_layout.adoc index 5694e9e1e011..ae1dda95dbcd 100644 --- a/docs/modules/ROOT/pages/cops_layout.adoc +++ b/docs/modules/ROOT/pages/cops_layout.adoc @@ -229,9 +229,9 @@ array = [1, 2, 3, | Enabled | Yes -| Yes +| Yes (Unsafe) | 0.49 -| 0.77 +| 1.40 |=== Checks the indentation of the first line of the diff --git a/docs/modules/ROOT/pages/cops_lint.adoc b/docs/modules/ROOT/pages/cops_lint.adoc index 7d56e94c6ef3..f38090b27ba5 100644 --- a/docs/modules/ROOT/pages/cops_lint.adoc +++ b/docs/modules/ROOT/pages/cops_lint.adoc @@ -339,7 +339,7 @@ do_something(/pattern/i) | Enabled | Yes -| No +| Yes | 0.9 | - |=== @@ -352,6 +352,11 @@ By safe assignment we mean putting parentheses around an assignment to indicate "I know I'm using an assignment as a condition. It's not a mistake." +=== Safety + +This cop's autocorrection is unsafe because it assumes that +the author meant to use an assignment result as a condition. + === Examples [source,ruby] @@ -953,7 +958,7 @@ Addrinfo.tcp(host, port).getnameinfo | Yes | Yes | 1.8 -| 1.22 +| 1.40 |=== Checks for deprecated constants. @@ -967,7 +972,8 @@ alternative value as `Alternative`. And you can set the deprecated version as Alternative: 'alternative_value' DeprecatedVersion: 'deprecated_version' -By default, `NIL`, `TRUE`, `FALSE` and `Random::DEFAULT` are configured. +By default, `NIL`, `TRUE`, `FALSE`, `Net::HTTPServerException, `Random::DEFAULT`, +`Struct::Group`, and `Struct::Passwd` are configured. === Examples @@ -977,13 +983,19 @@ By default, `NIL`, `TRUE`, `FALSE` and `Random::DEFAULT` are configured. NIL TRUE FALSE +Net::HTTPServerException Random::DEFAULT # Return value of Ruby 2 is `Random` instance, Ruby 3.0 is `Random` class. +Struct::Group +Struct::Passwd # good nil true false +Net::HTTPClientException Random.new # `::DEFAULT` has been deprecated in Ruby 3, `.new` is compatible with Ruby 2. +Etc::Group +Etc::Passwd ---- === Configurable attributes @@ -992,7 +1004,7 @@ Random.new # `::DEFAULT` has been deprecated in Ruby 3, `.new` is compatible wit | Name | Default value | Configurable values | DeprecatedConstants -| `{"NIL"=>{"Alternative"=>"nil", "DeprecatedVersion"=>"2.4"}, "TRUE"=>{"Alternative"=>"true", "DeprecatedVersion"=>"2.4"}, "FALSE"=>{"Alternative"=>"false", "DeprecatedVersion"=>"2.4"}, "Net::HTTPServerException"=>{"Alternative"=>"Net::HTTPClientException", "DeprecatedVersion"=>"2.6"}, "Random::DEFAULT"=>{"Alternative"=>"Random.new", "DeprecatedVersion"=>"3.0"}}` +| `{"NIL"=>{"Alternative"=>"nil", "DeprecatedVersion"=>"2.4"}, "TRUE"=>{"Alternative"=>"true", "DeprecatedVersion"=>"2.4"}, "FALSE"=>{"Alternative"=>"false", "DeprecatedVersion"=>"2.4"}, "Net::HTTPServerException"=>{"Alternative"=>"Net::HTTPClientException", "DeprecatedVersion"=>"2.6"}, "Random::DEFAULT"=>{"Alternative"=>"Random.new", "DeprecatedVersion"=>"3.0"}, "Struct::Group"=>{"Alternative"=>"Etc::Group", "DeprecatedVersion"=>"3.0"}, "Struct::Passwd"=>{"Alternative"=>"Etc::Passwd", "DeprecatedVersion"=>"3.0"}}` | |=== @@ -2881,19 +2893,20 @@ C = Class.new(RuntimeError) | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed | Enabled -| No +| Yes | Yes (Unsafe) | 0.50 -| 0.87 +| 1.40 |=== Checks for interpolation in a single quoted string. === Safety -This cop is generally safe, but is marked as unsafe because -it is possible to actually intentionally have text inside -`#{...}` in a single quoted string. +This cop's autocorrection is unsafe because although it always replaces single quotes as +if it were miswritten double quotes, it is not always the case. For example, +`'#{foo} bar'` would be replaced by `"#{foo} bar"`, so the replaced code would evaluate +the expression `foo`. === Examples @@ -7092,7 +7105,7 @@ do_something(1) | - |=== -Checks for operators, variables, literals, and nonmutating +Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context. === Examples diff --git a/docs/modules/ROOT/pages/cops_metrics.adoc b/docs/modules/ROOT/pages/cops_metrics.adoc index 53cd8ad0982b..d65a623df967 100644 --- a/docs/modules/ROOT/pages/cops_metrics.adoc +++ b/docs/modules/ROOT/pages/cops_metrics.adoc @@ -98,8 +98,8 @@ Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods. -You can set literals you want to fold with `CountAsOne`. -Available are: 'array', 'hash', and 'heredoc'. Each literal +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. @@ -111,7 +111,7 @@ NOTE: This cop does not apply for `Struct` definitions. === Examples -==== CountAsOne: ['array', 'heredoc'] +==== CountAsOne: ['array', 'heredoc', 'method_call'] [source,ruby] ---- @@ -129,7 +129,12 @@ something do Heredoc content. HEREDOC -end # 5 points + + foo( # +1 + 1, + 2 + ) +end # 6 points ---- === Configurable attributes @@ -225,15 +230,15 @@ Checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. -You can set literals you want to fold with `CountAsOne`. -Available are: 'array', 'hash', and 'heredoc'. Each literal +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 also applies for `Struct` definitions. === Examples -==== CountAsOne: ['array', 'heredoc'] +==== CountAsOne: ['array', 'heredoc', 'method_call'] [source,ruby] ---- @@ -251,7 +256,12 @@ class Foo Heredoc content. HEREDOC -end # 5 points + + foo( # +1 + 1, + 2 + ) +end # 6 points ---- === Configurable attributes @@ -349,8 +359,8 @@ Checks if the length of a method exceeds some maximum value. Comment lines can optionally be allowed. The maximum allowed length is configurable. -You can set literals you want to fold with `CountAsOne`. -Available are: 'array', 'hash', and 'heredoc'. Each literal +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: The `ExcludedMethods` and `IgnoredMethods` configuration is @@ -360,7 +370,7 @@ By default, there are no methods to allowed. === Examples -==== CountAsOne: ['array', 'heredoc'] +==== CountAsOne: ['array', 'heredoc', 'method_call'] [source,ruby] ---- @@ -378,7 +388,12 @@ def m Heredoc content. HEREDOC -end # 5 points + + foo( # +1 + 1, + 2 + ) +end # 6 points ---- === Configurable attributes @@ -435,13 +450,13 @@ Checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. -You can set literals you want to fold with `CountAsOne`. -Available are: 'array', 'hash', and 'heredoc'. Each literal +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. === Examples -==== CountAsOne: ['array', 'heredoc'] +==== CountAsOne: ['array', 'heredoc', 'method_call'] [source,ruby] ---- @@ -459,7 +474,12 @@ module M Heredoc content. HEREDOC -end # 5 points + + foo( # +1 + 1, + 2 + ) +end # 6 points ---- === Configurable attributes diff --git a/docs/modules/ROOT/pages/cops_style.adoc b/docs/modules/ROOT/pages/cops_style.adoc index 93a9dd7ef913..bd7240784ab9 100644 --- a/docs/modules/ROOT/pages/cops_style.adoc +++ b/docs/modules/ROOT/pages/cops_style.adoc @@ -444,6 +444,68 @@ Array(paths).each { |path| do_something(path) } * https://rubystyle.guide#array-coercion +== Style/ArrayIntersect + +NOTE: Required Ruby version: 3.1 + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Yes +| 1.40 +| - +|=== + +In Ruby 3.1, `Array#intersect?` has been added. + +This cop identifies places where `(array1 & array2).any?` +can be replaced by `array1.intersect?(array2)`. + +The `array1.intersect?(array2)` method is faster than +`(array1 & array2).any?` and is more readable. + +=== Safety + +This cop cannot guarantee that array1 and array2 are +actually arrays while method `intersect?` is for arrays only. + +=== Examples + +[source,ruby] +---- +# bad +(array1 & array2).any? +(array1 & array2).empty? + +# good +array1.intersect?(array2) +!array1.intersect?(array2) +---- + +==== AllCops:ActiveSupportExtensionsEnabled: false (default) + +[source,ruby] +---- +# good +(array1 & array2).present? +(array1 & array2).blank? +---- + +==== AllCops:ActiveSupportExtensionsEnabled: true + +[source,ruby] +---- +# bad +(array1 & array2).present? +(array1 & array2).blank? + +# good +array1.intersect?(array2) +!array1.intersect?(array2) +---- + == Style/ArrayJoin |=== @@ -10136,7 +10198,7 @@ rand(1...7) | No | Yes (Unsafe) | 1.4 -| 1.7 +| 1.40 |=== Checks for a redundant argument passed to certain methods. @@ -10149,6 +10211,7 @@ Method names and their redundant arguments can be configured like this: ---- Methods: join: '' + sum: 0 split: ' ' chomp: "\n" chomp!: "\n" @@ -10173,6 +10236,7 @@ This cop is unsafe because of the following limitations: # bad array.join('') [1, 2, 3].join("") +array.sum(0) string.split(" ") "first\nsecond".split(" ") string.chomp("\n") @@ -10182,6 +10246,7 @@ A.foo(2) # good array.join [1, 2, 3].join +array.sum string.split "first second".split string.chomp @@ -10195,7 +10260,7 @@ A.foo | Name | Default value | Configurable values | Methods -| `{"join"=>"", "split"=>" ", "chomp"=>"\n", "chomp!"=>"\n"}` +| `{"join"=>"", "sum"=>0, "split"=>" ", "chomp"=>"\n", "chomp!"=>"\n"}` | |=== @@ -10439,6 +10504,56 @@ x == y ? false : true x != y ---- +== Style/RedundantConstantBase + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Yes +| 1.40 +| - +|=== + +Avoid redundant `::` prefix on constant. + +How Ruby searches constant is a bit complicated, and it can often be difficult to +understand from the code whether the `::` is intended or not. Where `Module.nesting` +is empty, there is no need to prepend `::`, so it would be nice to consistently +avoid such meaningless `::` prefix to avoid confusion. + +=== Examples + +[source,ruby] +---- +# bad +::Const + +# good +Const + +# bad +class << self + ::Const +end + +# good +class << self + Const +end + +# good +class A + ::Const +end + +# good +module A + ::Const +end +---- + == Style/RedundantEach |=== @@ -11489,6 +11604,57 @@ x =~ /home\// * https://rubystyle.guide#percent-r +== Style/RequireOrder + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Disabled +| Yes +| Yes (Unsafe) +| 1.40 +| - +|=== + +Sort `require` and `require_relative` in alphabetical order. + +=== Safety + +This cop's autocorrection is unsafe because it will obviously change the execution order. + +=== Examples + +[source,ruby] +---- +# bad +require 'b' +require 'a' + +# good +require 'a' +require 'b' + +# bad +require_relative 'b' +require_relative 'a' + +# good +require_relative 'a' +require_relative 'b' + +# good (sorted within each section separated by a blank line) +require 'a' +require 'd' + +require 'b' +require 'c' + +# good +require 'b' +require_relative 'c' +require 'a' +---- + == Style/RescueModifier |=== @@ -11769,6 +11935,11 @@ foo && foo.bar(param1, param2) foo && foo.bar { |e| e.something } foo && foo.bar(param) { |e| e.something } +foo ? foo.bar : nil +foo.nil? ? nil : foo.bar +!foo.nil? ? foo.bar : nil +!foo ? nil : foo.bar + # good foo&.bar foo&.bar&.baz @@ -13248,14 +13419,14 @@ Checks symbol literal syntax. | No | Yes (Unsafe) | 0.26 -| 1.28 +| 1.40 |=== Use symbols as procs when possible. If you prefer a style that allows block for method with arguments, please set `true` to `AllowMethodsWithArguments`. -respond_to , and `define_method?` methods are allowed by default. +`define_method?` methods are allowed by default. These are customizable with `AllowedMethods` option. === Safety @@ -13341,12 +13512,11 @@ something.do_something do |s| # some comment end ---- -==== AllowedMethods: [respond_to, define_method] (default) +==== AllowedMethods: [define_method] (default) [source,ruby] ---- # good -respond_to { |foo| foo.bar } define_method(:foo) { |foo| foo.bar } ---- @@ -13376,7 +13546,7 @@ something.map { |s| s.upcase } | Boolean | AllowedMethods -| `respond_to`, `define_method` +| `define_method` | Array | AllowedPatterns diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index fc2580c37d39..96dd96f8eb2a 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.39', require: false +gem 'rubocop', '~> 1.40', require: false ---- .A Modular RuboCop diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index f593d6920dfe..0d1624128d1e 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.39.0' + STRING = '1.40.0' MSG = '%s (using Parser %s, ' \ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.40.0.md b/relnotes/v1.40.0.md new file mode 100644 index 000000000000..1f6417fd909b --- /dev/null +++ b/relnotes/v1.40.0.md @@ -0,0 +1,49 @@ +### New features + +* [#11179](https://github.com/rubocop/rubocop/pull/11179): Add `Style/ConstantBase` cop. ([@r7kamura][]) +* [#11205](https://github.com/rubocop/rubocop/pull/11205): Add `--[no-]auto-gen-enforced-style` CLI option. ([@ydah][]) +* [#11224](https://github.com/rubocop/rubocop/pull/11224): Add `Style/RequireOrder` cop. ([@r7kamura][]) +* [#11219](https://github.com/rubocop/rubocop/issues/11219): Make `Style/SelectByRegexp` aware of `!~` method. ([@koic][]) +* [#11224](https://github.com/rubocop/rubocop/pull/11224): Add new cop `Style/ArrayIntersect` which replaces `(array1 & array2).any?` with `array1.intersect?(array2)`, method `Array#intersect?` was added in ruby 3.1. ([@KirIgor][]) +* [#11211](https://github.com/rubocop/rubocop/pull/11211): Add autocorrect for `Lint/AssignmentInCondition`. ([@r7kamura][]) + +### Bug fixes + +* [#5251](https://github.com/rubocop/rubocop/issues/5251): Fix loading of configuration in multi-file edge case. ([@NobodysNightmare][]) +* [#11192](https://github.com/rubocop/rubocop/issues/11192): Fix a false positive for `Lint/ParenthesesAsGroupedExpression` when using a block argument. ([@ydah][]) +* [#11143](https://github.com/rubocop/rubocop/issues/11143): Fix RedundantCopDisableDirective errors when encountering several department comments. ([@isarcasm][]) +* [#11230](https://github.com/rubocop/rubocop/issues/11230): Fix an incorrect autocorrect for `Lint/SafeNavigationChain` when using safe navigation with `[]` operator followed by method chain. ([@koic][]) +* [#11181](https://github.com/rubocop/rubocop/pull/11181): Fix pattern to match .tool-versions files that specify multiple runtimes. ([@noelblaschke][]) +* [#11239](https://github.com/rubocop/rubocop/issues/11239): Fix an incorrect autocorrect for `Style/GuardClause` when using heredoc as an argument of raise in branch body. ([@koic][]) +* [#11182](https://github.com/rubocop/rubocop/issues/11182): Fix an incorrect autocorrect for `EnforcedShorthandSyntax: always` of `Style/HashSyntax` with `Style/IfUnlessModifier` when using Ruby 3.1. ([@koic][]) +* [#11184](https://github.com/rubocop/rubocop/issues/11184): Fix an error for `Lint/ShadowingOuterLocalVariable` when a block local variable has same name as an outer `until` scope variable. ([@koic][]) +* [#11198](https://github.com/rubocop/rubocop/pull/11198): Fix an error for `Lint/EmptyConditionalBody` when one using line if/;/end without then boby. ([@koic][]) +* [#11196](https://github.com/rubocop/rubocop/issues/11196): Fix a false positive for `Style/GuardClause` when using `raise` in `then` body of `if..elsif..end` form. ([@koic][]) +* [#11213](https://github.com/rubocop/rubocop/pull/11213): Support redundant department disable in scope of `Lint/RedundantCopDisableDirective` cop. ([@isarcasm][]) +* [#11200](https://github.com/rubocop/rubocop/issues/11200): Fix an incorrect autocorrect for `Layout/MultilineMethodCallBraceLayout` when using method chain for heredoc argument in multiline literal brace layout. ([@koic][]) +* [#11190](https://github.com/rubocop/rubocop/pull/11190): Fix an error for `Style/IfWithSemicolon` when using one line if/;/end without then boby. ([@koic][]) +* [#11244](https://github.com/rubocop/rubocop/pull/11244): Fix a false negative for `Style/RedundantReturn` when dynamic define methods. ([@ydah][]) + +### Changes + +* [#11218](https://github.com/rubocop/rubocop/pull/11218): Update severity of `Bundler/DuplicatedGem`, `Bundler/InsecureProtocolSource`, `Gemspec/DeprecatedAttributeAssignment`, `Gemspec/DuplicatedAssignment`, `Gemspec/RequireMFA`, `Gemspec/RequiredRubyVersion`, and `Gemspec/RubyVersionGlobalsUsage` cops to warning. ([@koic][]) +* [#11222](https://github.com/rubocop/rubocop/pull/11222): Make `Style/RedundantArgument` aware of `Array#sum`. ([@koic][]) +* [#11070](https://github.com/rubocop/rubocop/issues/11070): Add ability to count method calls as one line to code length related `Metric` cops. ([@fatkodima][]) +* [#11226](https://github.com/rubocop/rubocop/pull/11226): Make `Lint/Void` aware of used lambda and proc in void context. ([@koic][]) +* [#11205](https://github.com/rubocop/rubocop/pull/11205): Change `Lint/InterpolationCheck` from `Safe: false` to `SafeAutoCorrect: false`. ([@r7kamura][]) +* [#11212](https://github.com/rubocop/rubocop/issues/11212): Make `Lint/DeprecatedConstants` aware of deprecated `Struct::Group` and `Struct::Passwd` classes. ([@koic][]) +* [#11236](https://github.com/rubocop/rubocop/pull/11236): Remove `respond_to` from default value of `AllowedMethods` for `Style/SymbolProc`. ([@koic][]) +* [#11185](https://github.com/rubocop/rubocop/pull/11185): Make `Style/HashSyntax` aware of without parentheses call expr follows. ([@koic][]) +* [#11203](https://github.com/rubocop/rubocop/pull/11203): Support multiple arguments on `Lint/SendWithMixinArgument`. ([@r7kamura][]) +* [#11229](https://github.com/rubocop/rubocop/pull/11229): Add `cc` to `AllowedNames` of `MethodParameterName` cop. ([@tjschuck][]) +* [#11116](https://github.com/rubocop/rubocop/issues/11116): Handle ternaries in `Style/SafeNavigation`. ([@fatkodima][]) + +[@r7kamura]: https://github.com/r7kamura +[@ydah]: https://github.com/ydah +[@koic]: https://github.com/koic +[@KirIgor]: https://github.com/KirIgor +[@NobodysNightmare]: https://github.com/NobodysNightmare +[@isarcasm]: https://github.com/isarcasm +[@noelblaschke]: https://github.com/noelblaschke +[@fatkodima]: https://github.com/fatkodima +[@tjschuck]: https://github.com/tjschuck