diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c190dbd56..7aa8f93bbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ## master (unreleased) +## 2.28.0 (2024-12-25) + ### New features * [#1383](https://github.com/rubocop/rubocop-rails/pull/1383): Introduce `AllCops: MigratedSchemaVersion` config. ([@koic][]) diff --git a/docs/antora.yml b/docs/antora.yml index 9e0ff48acb..04dba5080f 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.28' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index af8158a478..3a87f4e8ed 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -2075,7 +2075,7 @@ enum status: { active: 0, archived: 1 } [#railsenumsyntax] == Rails/EnumSyntax -NOTE: Required Ruby version: 3.0 +NOTE: Requires Ruby version 3.0 NOTE: Required Rails version: 7.0 @@ -4324,6 +4324,24 @@ Enforces the use of `pluck` over `map`. element in an enumerable. When called on an Active Record relation, it results in a more efficient query that only selects the necessary key. +NOTE: If the receiver's relation is not loaded and `pluck` is used inside an iteration, +it may result in N+1 queries because `pluck` queries the database on each iteration. +This cop ignores offenses for `map/collect` when they are suspected to be part of an iteration +to prevent such potential issues. + +[source,ruby] +---- +users = User.all +5.times do + users.map { |user| user[:foo] } # Only one query is executed +end + +users = User.all +5.times do + users.pluck(:id) # A query is executed on every iteration +end +---- + [#safety-railspluck] === Safety @@ -5928,7 +5946,7 @@ Rails.public_path.join('file.pdf') [#railssafenavigation] == Rails/SafeNavigation -NOTE: Required Ruby version: 2.3 +NOTE: Requires Ruby version 2.3 |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -6544,7 +6562,7 @@ SQL [#railsstripheredoc] == Rails/StripHeredoc -NOTE: Required Ruby version: 2.3 +NOTE: Requires Ruby version 2.3 |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed @@ -7670,7 +7688,7 @@ User.where.not('trashed = ? OR role = ?', true, 'admin') [#railswhererange] == Rails/WhereRange -NOTE: Required Ruby version: 2.6 +NOTE: Requires Ruby version 2.6 NOTE: Required Rails version: 6.0 diff --git a/lib/rubocop/rails/version.rb b/lib/rubocop/rails/version.rb index 090716add8..37bfe99f68 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.27.0' + STRING = '2.28.0' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v2.28.0.md b/relnotes/v2.28.0.md new file mode 100644 index 0000000000..5bc46c1395 --- /dev/null +++ b/relnotes/v2.28.0.md @@ -0,0 +1,19 @@ +### New features + +* [#1383](https://github.com/rubocop/rubocop-rails/pull/1383): Introduce `AllCops: MigratedSchemaVersion` config. ([@koic][]) + +### Bug fixes + +* [#1390](https://github.com/rubocop/rubocop-rails/pull/1390): Fix an incorrect autocorrect for `Rails/SelectMap` when `select` has no receiver and method chains are used. ([@masato-bkn][]) +* [#1382](https://github.com/rubocop/rubocop-rails/pull/1382): Fix false negatives for `Rails/RedundantActiveRecordAllMethod` when using `all` method in block. ([@masato-bkn][]) +* [#1397](https://github.com/rubocop/rubocop-rails/pull/1397): Fix `Rails/FilePath` cop error on `join` method with implicit receiver. ([@viralpraxis][]) +* [#1398](https://github.com/rubocop/rubocop-rails/pull/1398): Fix `Rails/FilePath` cop error in case of extra operations in `Rails.root` interpolation. ([@viralpraxis][]) +* [#1392](https://github.com/rubocop/rubocop-rails/pull/1392): Fix `Rails/FilePath` cop error with rescued `Rails.root`. ([@viralpraxis][]) + +### Changes + +* [#1388](https://github.com/rubocop/rubocop-rails/pull/1388): Modify `Rails/Pluck` to ignore `map/collect` when used inside blocks to prevent potential N+1 queries. ([@masato-bkn][]) + +[@koic]: https://github.com/koic +[@masato-bkn]: https://github.com/masato-bkn +[@viralpraxis]: https://github.com/viralpraxis