From 983f2643f71334680aec149b1784f7cf89bf0ccc Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 18 Jan 2025 15:44:30 +0900 Subject: [PATCH] Cut 2.29.0 --- CHANGELOG.md | 2 + config/default.yml | 4 +- docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops.adoc | 2 + docs/modules/ROOT/pages/cops_rails.adoc | 97 +++++++++++++++++++++++++ lib/rubocop/rails/version.rb | 2 +- relnotes/v2.29.0.md | 24 ++++++ 7 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 relnotes/v2.29.0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index cb41487083..1ed798e23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ## master (unreleased) +## 2.29.0 (2025-01-18) + ### New features * [#1407](https://github.com/rubocop/rubocop-rails/pull/1407): Add new `Rails/MultipleRoutePaths` cop. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 8aba7bcca1..a14fa09acd 100644 --- a/config/default.yml +++ b/config/default.yml @@ -702,7 +702,7 @@ Rails/MultipleRoutePaths: Description: 'Checks for mapping a route with multiple paths, which is deprecated and will be removed in Rails 8.1.' Enabled: pending Severity: warning - VersionAdded: '<>' + VersionAdded: '2.29' Include: - config/routes.rb - config/routes/**/*.rb @@ -1088,7 +1088,7 @@ Rails/StrongParametersExpect: Include: - app/controllers/**/*.rb SafeAutoCorrect: false - VersionAdded: '<>' + VersionAdded: '2.29' Rails/TableNameAssignment: Description: >- diff --git a/docs/antora.yml b/docs/antora.yml index 9e0ff48acb..5a69a42487 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -2,6 +2,6 @@ name: rubocop-rails title: RuboCop Rails # We always provide version without patch here (e.g. 1.1), # as patch versions should not appear in the docs. -version: ~ +version: '2.29' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 10c6b8a388..55d104db48 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -84,6 +84,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide]. * xref:cops_rails.adoc#railsmailername[Rails/MailerName] * xref:cops_rails.adoc#railsmatchroute[Rails/MatchRoute] * xref:cops_rails.adoc#railsmigrationclassname[Rails/MigrationClassName] +* xref:cops_rails.adoc#railsmultipleroutepaths[Rails/MultipleRoutePaths] * xref:cops_rails.adoc#railsnegateinclude[Rails/NegateInclude] * xref:cops_rails.adoc#railsnotnullcolumn[Rails/NotNullColumn] * xref:cops_rails.adoc#railsorderbyid[Rails/OrderById] @@ -127,6 +128,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide]. * xref:cops_rails.adoc#railsskipsmodelvalidations[Rails/SkipsModelValidations] * xref:cops_rails.adoc#railssquishedsqlheredocs[Rails/SquishedSQLHeredocs] * xref:cops_rails.adoc#railsstripheredoc[Rails/StripHeredoc] +* xref:cops_rails.adoc#railsstrongparametersexpect[Rails/StrongParametersExpect] * xref:cops_rails.adoc#railstablenameassignment[Rails/TableNameAssignment] * xref:cops_rails.adoc#railsthreestatebooleancolumn[Rails/ThreeStateBooleanColumn] * xref:cops_rails.adoc#railstimezone[Rails/TimeZone] diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index 3a87f4e8ed..4f504ab62c 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -3975,6 +3975,49 @@ end | Array |=== +[#railsmultipleroutepaths] +== Rails/MultipleRoutePaths + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Always +| 2.29 +| - +|=== + +Checks for mapping a route with multiple paths, which is deprecated and will be removed in Rails 8.1. + +[#examples-railsmultipleroutepaths] +=== Examples + +[source,ruby] +---- +# bad +get '/users', '/other_path', to: 'users#index' + +# good +get '/users', to: 'users#index' +get '/other_path', to: 'users#index' +---- + +[#configurable-attributes-railsmultipleroutepaths] +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| Severity +| `warning` +| String + +| Include +| `config/routes.rb`, `+config/routes/**/*.rb+` +| Array +|=== + [#railsnegateinclude] == Rails/NegateInclude @@ -6602,6 +6645,60 @@ EOS * https://rails.rubystyle.guide/#prefer-squiggly-heredoc +[#railsstrongparametersexpect] +== Rails/StrongParametersExpect + +NOTE: Required Rails version: 8.0 + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Always (Unsafe) +| 2.29 +| - +|=== + +Enforces the use of `ActionController::Parameters#expect` as a method for strong parameter handling. + +[#safety-railsstrongparametersexpect] +=== Safety + +This cop's autocorrection is considered unsafe because there are cases where the HTTP status may change +from 500 to 400 when handling invalid parameters. This change, however, reflects an intentional +incompatibility introduced for valid reasons by the `expect` method, which aligns better with +strong parameter conventions. + +[#examples-railsstrongparametersexpect] +=== Examples + +[source,ruby] +---- +# bad +params.require(:user).permit(:name, :age) +params.permit(user: [:name, :age]).require(:user) + +# good +params.expect(user: [:name, :age]) +---- + +[#configurable-attributes-railsstrongparametersexpect] +=== Configurable attributes + +|=== +| Name | Default value | Configurable values + +| Include +| `+app/controllers/**/*.rb+` +| Array +|=== + +[#references-railsstrongparametersexpect] +=== References + +* https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect + [#railstablenameassignment] == Rails/TableNameAssignment diff --git a/lib/rubocop/rails/version.rb b/lib/rubocop/rails/version.rb index 37bfe99f68..16caa42d21 100644 --- a/lib/rubocop/rails/version.rb +++ b/lib/rubocop/rails/version.rb @@ -4,7 +4,7 @@ module RuboCop module Rails # This module holds the RuboCop Rails version information. module Version - STRING = '2.28.0' + STRING = '2.29.0' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v2.29.0.md b/relnotes/v2.29.0.md new file mode 100644 index 0000000000..84ed2f0aef --- /dev/null +++ b/relnotes/v2.29.0.md @@ -0,0 +1,24 @@ +### New features + +* [#1407](https://github.com/rubocop/rubocop-rails/pull/1407): Add new `Rails/MultipleRoutePaths` cop. ([@koic][]) +* [#1358](https://github.com/rubocop/rubocop-rails/issues/1358): Add new `Rails/StrongParametersExpect` cop. ([@koic][]) + +### Bug fixes + +* [#1409](https://github.com/rubocop/rubocop-rails/pull/1409): Fix an error for `Rails/ReversibleMigration` when calling `drop_table` without any arguments. ([@earlopain][]) +* [#1397](https://github.com/rubocop/rubocop-rails/pull/1397): Fix an incorrect autocorrect for `Rails/TimeZone` when Time.new has a string argument. ([@mterada1228][]) +* [#1406](https://github.com/rubocop/rubocop-rails/pull/1406): Fix autocorrection for `Rails/IndexBy` and `Rails/IndexWith` when `map { ... }.to_h` is enclosed in another block. ([@franzliedke][], [@eugeneius][]) +* [#1404](https://github.com/rubocop/rubocop-rails/pull/1404): Update `Rails/IndexBy` and `Rails/IndexWith` to support numbered block parameters. ([@eugeneius][]) +* [#1405](https://github.com/rubocop/rubocop-rails/pull/1405): Fix autocorrection for `Rails/IndexWith` when the value is a hash literal without braces. ([@koic][], [@eugeneius][]) +* [#1414](https://github.com/rubocop/rubocop-rails/pull/1414): Fix `Rails/HttpPositionalArguments` cop false positives with arguments forwarding. ([@viralpraxis][]) + +### Changes + +* [#1410](https://github.com/rubocop/rubocop-rails/issues/1410): Make registered cops aware of `AllCops: MigratedSchemaVersion`. ([@koic][]) + +[@koic]: https://github.com/koic +[@earlopain]: https://github.com/earlopain +[@mterada1228]: https://github.com/mterada1228 +[@franzliedke]: https://github.com/franzliedke +[@eugeneius]: https://github.com/eugeneius +[@viralpraxis]: https://github.com/viralpraxis