Skip to content

Commit 334861e

Browse files
committed
Cut 2.26.0
1 parent 91c0f30 commit 334861e

File tree

7 files changed

+133
-20
lines changed

7 files changed

+133
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
## master (unreleased)
1111

12+
## 2.26.0 (2024-08-24)
13+
1214
### New features
1315

1416
* [#1238](https://github.com/rubocop/rubocop-rails/issues/1238): Add new `Rails/EnumSyntax` cop. ([@maxprokopiev][], [@koic][])

config/default.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Rails/EnumSyntax:
428428
Description: 'Use positional arguments over keyword arguments when defining enums.'
429429
Enabled: pending
430430
Severity: warning
431-
VersionAdded: '<<next>>'
431+
VersionAdded: '2.26'
432432
Include:
433433
- app/models/**/*.rb
434434

@@ -1198,7 +1198,7 @@ Rails/WhereEquals:
11981198
Enabled: 'pending'
11991199
SafeAutoCorrect: false
12001200
VersionAdded: '2.9'
1201-
VersionChanged: <<next>>
1201+
VersionChanged: '2.26'
12021202

12031203
Rails/WhereExists:
12041204
Description: 'Prefer `exists?(...)` over `where(...).exists?`.'

docs/antora.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ name: rubocop-rails
22
title: RuboCop Rails
33
# We always provide version without patch here (e.g. 1.1),
44
# as patch versions should not appear in the docs.
5-
version: ~
5+
version: '2.26'
66
nav:
77
- modules/ROOT/nav.adoc

docs/modules/ROOT/pages/cops.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
5353
* xref:cops_rails.adoc#railsdynamicfindby[Rails/DynamicFindBy]
5454
* xref:cops_rails.adoc#railseagerevaluationlogmessage[Rails/EagerEvaluationLogMessage]
5555
* xref:cops_rails.adoc#railsenumhash[Rails/EnumHash]
56+
* xref:cops_rails.adoc#railsenumsyntax[Rails/EnumSyntax]
5657
* xref:cops_rails.adoc#railsenumuniqueness[Rails/EnumUniqueness]
5758
* xref:cops_rails.adoc#railsenvlocal[Rails/EnvLocal]
5859
* xref:cops_rails.adoc#railsenvironmentcomparison[Rails/EnvironmentComparison]

docs/modules/ROOT/pages/cops_rails.adoc

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ This will work fine when the receiver is a hash object.
10841084
And `compact_blank!` has different implementations for `Array`, `Hash`, and
10851085
`ActionController::Parameters`.
10861086
`Array#compact_blank!`, `Hash#compact_blank!` are equivalent to `delete_if(&:blank?)`.
1087-
`ActionController::Parameters#compact_blank!` is equivalent to `reject!(&:blank?)`.
10881087
If the cop makes a mistake, autocorrected code may get unexpected behavior.
10891088
10901089
=== Examples
@@ -1094,15 +1093,17 @@ If the cop makes a mistake, autocorrected code may get unexpected behavior.
10941093
# bad
10951094
collection.reject(&:blank?)
10961095
collection.reject { |_k, v| v.blank? }
1096+
collection.select(&:present?)
1097+
collection.select { |_k, v| v.present? }
10971098
10981099
# good
10991100
collection.compact_blank
11001101
11011102
# bad
11021103
collection.delete_if(&:blank?) # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
11031104
collection.delete_if { |_k, v| v.blank? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
1104-
collection.reject!(&:blank?) # Same behavior as `ActionController::Parameters#compact_blank!`
1105-
collection.reject! { |_k, v| v.blank? } # Same behavior as `ActionController::Parameters#compact_blank!`
1105+
collection.keep_if(&:present?) # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
1106+
collection.keep_if { |_k, v| v.present? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
11061107
11071108
# good
11081109
collection.compact_blank!
@@ -1294,10 +1295,10 @@ Rails time zone. You must use `Time.zone.today` instead.
12941295
The cop also reports warnings when you are using `to_time` method,
12951296
because it doesn't know about Rails time zone either.
12961297
1297-
Two styles are supported for this cop. When `EnforcedStyle` is 'strict'
1298+
Two styles are supported for this cop. When `EnforcedStyle` is `strict`
12981299
then the Date methods `today`, `current`, `yesterday`, and `tomorrow`
12991300
are prohibited and the usage of both `to_time`
1300-
and 'to_time_in_current_zone' are reported as warning.
1301+
and `to_time_in_current_zone` are reported as warning.
13011302
13021303
When `EnforcedStyle` is `flexible` then only `Date.today` is prohibited.
13031304
@@ -1881,6 +1882,12 @@ value for each key prevents this from happening.
18811882
18821883
[source,ruby]
18831884
----
1885+
# bad
1886+
enum :status, [:active, :archived]
1887+
1888+
# good
1889+
enum :status, { active: 0, archived: 1 }
1890+
18841891
# bad
18851892
enum status: [:active, :archived]
18861893
@@ -1902,6 +1909,48 @@ enum status: { active: 0, archived: 1 }
19021909
19031910
* https://rails.rubystyle.guide#enums
19041911
1912+
== Rails/EnumSyntax
1913+
1914+
|===
1915+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
1916+
1917+
| Pending
1918+
| Yes
1919+
| Always
1920+
| 2.26
1921+
| -
1922+
|===
1923+
1924+
Looks for enums written with keyword arguments syntax.
1925+
1926+
Defining enums with keyword arguments syntax is deprecated and will be removed in Rails 8.0.
1927+
Positional arguments should be used instead:
1928+
1929+
=== Examples
1930+
1931+
[source,ruby]
1932+
----
1933+
# bad
1934+
enum status: { active: 0, archived: 1 }, _prefix: true
1935+
1936+
# good
1937+
enum :status, { active: 0, archived: 1 }, prefix: true
1938+
----
1939+
1940+
=== Configurable attributes
1941+
1942+
|===
1943+
| Name | Default value | Configurable values
1944+
1945+
| Severity
1946+
| `warning`
1947+
| String
1948+
1949+
| Include
1950+
| `+app/models/**/*.rb+`
1951+
| Array
1952+
|===
1953+
19051954
== Rails/EnumUniqueness
19061955
19071956
|===
@@ -1920,6 +1969,18 @@ Looks for duplicate values in enum declarations.
19201969
19211970
[source,ruby]
19221971
----
1972+
# bad
1973+
enum :status, { active: 0, archived: 0 }
1974+
1975+
# good
1976+
enum :status, { active: 0, archived: 1 }
1977+
1978+
# bad
1979+
enum :status, [:active, :archived, :active]
1980+
1981+
# good
1982+
enum :status, [:active, :archived]
1983+
19231984
# bad
19241985
enum status: { active: 0, archived: 0 }
19251986
@@ -4031,18 +4092,27 @@ Identifies places where `pluck` is used in `where` query methods
40314092
and can be replaced with `select`.
40324093
40334094
Since `pluck` is an eager method and hits the database immediately,
4034-
using `select` helps to avoid additional database queries.
4095+
using `select` helps to avoid additional database queries by running as
4096+
a subquery.
40354097
4036-
This cop has two different enforcement modes. When the `EnforcedStyle`
4037-
is `conservative` (the default) then only calls to `pluck` on a constant
4038-
(i.e. a model class) in the `where` is used as offenses.
4098+
This cop has two modes of enforcement. When the `EnforcedStyle` is set
4099+
to `conservative` (the default), only calls to `pluck` on a constant
4100+
(e.g. a model class) within `where` are considered offenses.
40394101
40404102
=== Safety
40414103
4042-
When the `EnforcedStyle` is `aggressive` then all calls to `pluck` in the
4043-
`where` is used as offenses. This may lead to false positives
4044-
as the cop cannot replace to `select` between calls to `pluck` on an
4045-
`ActiveRecord::Relation` instance vs a call to `pluck` on an `Array` instance.
4104+
When `EnforcedStyle` is set to `aggressive`, all calls to `pluck`
4105+
within `where` are considered offenses. This might lead to false
4106+
positives because the check cannot distinguish between calls to
4107+
`pluck` on an `ActiveRecord::Relation` instance and calls to `pluck`
4108+
on an `Array` instance.
4109+
4110+
Additionally, when using a subquery with the SQL `IN` operator,
4111+
databases like PostgreSQL and MySQL can't optimize complex queries as
4112+
well. They need to scan all records of the outer table against the
4113+
subquery result sequentially, rather than using an index. This can
4114+
cause significant performance issues compared to writing the query
4115+
differently or using `pluck`.
40464116
40474117
=== Examples
40484118
@@ -4107,10 +4177,14 @@ core extensions to the numeric classes.
41074177
# bad
41084178
3.day.ago
41094179
1.months.ago
4180+
5.megabyte
4181+
1.gigabyte
41104182
41114183
# good
41124184
3.days.ago
41134185
1.month.ago
4186+
5.megabytes
4187+
1.gigabyte
41144188
----
41154189
41164190
== Rails/Presence
@@ -6794,15 +6868,16 @@ validates :foo, uniqueness: true
67946868
| Yes
67956869
| Always (Unsafe)
67966870
| 2.9
6797-
| 2.10
6871+
| 2.26
67986872
|===
67996873
68006874
Identifies places where manually constructed SQL
6801-
in `where` can be replaced with `where(attribute: value)`.
6875+
in `where` and `where.not` can be replaced with
6876+
`where(attribute: value)` and `where.not(attribute: value)`.
68026877
68036878
=== Safety
68046879
6805-
This cop's autocorrection is unsafe because it may change SQL.
6880+
This cop's autocorrection is unsafe because is may change SQL.
68066881
See: https://github.com/rubocop/rubocop-rails/issues/403
68076882
68086883
=== Examples
@@ -6811,6 +6886,7 @@ See: https://github.com/rubocop/rubocop-rails/issues/403
68116886
----
68126887
# bad
68136888
User.where('name = ?', 'Gabe')
6889+
User.where.not('name = ?', 'Gabe')
68146890
User.where('name = :name', name: 'Gabe')
68156891
User.where('name IS NULL')
68166892
User.where('name IN (?)', ['john', 'jane'])
@@ -6819,6 +6895,7 @@ User.where('users.name = :name', name: 'Gabe')
68196895
68206896
# good
68216897
User.where(name: 'Gabe')
6898+
User.where.not(name: 'Gabe')
68226899
User.where(name: nil)
68236900
User.where(name: ['john', 'jane'])
68246901
User.where(users: { name: 'Gabe' })

lib/rubocop/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RuboCop
44
module Rails
55
# This module holds the RuboCop Rails version information.
66
module Version
7-
STRING = '2.25.1'
7+
STRING = '2.26.0'
88

99
def self.document_version
1010
STRING.match('\d+\.\d+').to_s

relnotes/v2.26.0.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### New features
2+
3+
* [#1238](https://github.com/rubocop/rubocop-rails/issues/1238): Add new `Rails/EnumSyntax` cop. ([@maxprokopiev][], [@koic][])
4+
* [#1309](https://github.com/rubocop/rubocop-rails/pull/1309): Support Rails 7 syntax for `Rails/EnumHash` cop. ([@ytjmt][])
5+
* [#1298](https://github.com/rubocop/rubocop-rails/pull/1298): Support Rails 7 syntax for `Rails/EnumUniqueness` cop. ([@ytjmt][])
6+
7+
### Bug fixes
8+
9+
* [#1335](https://github.com/rubocop/rubocop-rails/pull/1335): Fix an error for `Rails/BulkChangeTable` when the block for `change_table` is empty. ([@earlopain][])
10+
* [#1325](https://github.com/rubocop/rubocop-rails/pull/1325): Fix an error for `Rails/RenderPlainText` when the content type is passed as a constant. ([@earlopain][])
11+
* [#1337](https://github.com/rubocop/rubocop-rails/pull/1337): Fix an error for `Rails/Validation` when passing no arguments. ([@earlopain][])
12+
* [#1330](https://github.com/rubocop/rubocop-rails/pull/1330): Fix an error for `Rails/WhereNot` when using placeholder without second argument. ([@earlopain][])
13+
* [#1311](https://github.com/rubocop/rubocop-rails/pull/1311): Fix false negatives for `Rails/ActionControllerFlashBeforeRender` when using implicit render or rescue blocks. ([@tldn0718][])
14+
* [#1313](https://github.com/rubocop/rubocop-rails/pull/1313): Fix false positives for `Rails/CompactBlank` when using `collection.reject!`. ([@koic][])
15+
* [#1319](https://github.com/rubocop/rubocop-rails/issues/1319): Fix a false positive for `Rails/RedundantPresenceValidationOnBelongsTo` when removing `presence` would leave other non-validation options like `allow_blank` without validations. ([@earlopain][])
16+
* [#1306](https://github.com/rubocop/rubocop-rails/pull/1306): Make `Rails/PluralizationGrammar` aware of byte methods. ([@earlopain][])
17+
* [#1302](https://github.com/rubocop/rubocop-rails/pull/1302): Allow `params` receiver by default for `Style/CollectionMethods`. ([@koic][])
18+
* [#1321](https://github.com/rubocop/rubocop-rails/pull/1321): Fix an error for `Rails/WhereEquals` when the second argument is not yet typed (`where("foo = ?", )`). ([@earlopain][])
19+
20+
### Changes
21+
22+
* [#1308](https://github.com/rubocop/rubocop-rails/issues/1308): Change `Rails/CompactBlank` to handle `select(&:present?)`. ([@fatkodima][])
23+
* [#1303](https://github.com/rubocop/rubocop-rails/pull/1303): Change `Rails/IgnoredSkipActionFilterOption` to handle multiple callbacks. ([@fatkodima][])
24+
* [#1199](https://github.com/rubocop/rubocop-rails/issues/1199): Make `Rails/WhereEquals` aware of `where.not(...)`. ([@earlopain][])
25+
* [#1003](https://github.com/rubocop/rubocop-rails/pull/1003): Change `Rails/RootPathnameMethods` to detect offenses on `Dir.[]`. ([@r7kamura][])
26+
27+
[@maxprokopiev]: https://github.com/maxprokopiev
28+
[@koic]: https://github.com/koic
29+
[@ytjmt]: https://github.com/ytjmt
30+
[@earlopain]: https://github.com/earlopain
31+
[@tldn0718]: https://github.com/tldn0718
32+
[@fatkodima]: https://github.com/fatkodima
33+
[@r7kamura]: https://github.com/r7kamura

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy