Skip to content

Commit ff99b24

Browse files
committed
Cut 2.34.0
1 parent 4d6c3c8 commit ff99b24

File tree

7 files changed

+199
-13
lines changed

7 files changed

+199
-13
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.34.0 (2025-11-16)
13+
1214
### New features
1315

1416
* [#1520](https://github.com/rubocop/rubocop-rails/pull/1520): New `Rails/HttpStatusNameConsistency` cop. ([@tuxagon][])

config/default.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ Rails/EnumUniqueness:
471471
Rails/Env:
472472
Description: 'Use Feature Flags or config instead of `Rails.env`.'
473473
Enabled: false
474-
VersionAdded: '<<next>>'
474+
VersionAdded: '2.34'
475475

476476
Rails/EnvLocal:
477477
Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
@@ -618,7 +618,7 @@ Rails/HttpStatusNameConsistency:
618618
Description: 'Enforces consistency by using the current HTTP status names.'
619619
Enabled: pending
620620
Severity: warning
621-
VersionAdded: '<<next>>'
621+
VersionAdded: '2.34'
622622
Include:
623623
- '**/app/controllers/**/*.rb'
624624

@@ -844,7 +844,7 @@ Rails/Presence:
844844
Description: 'Checks code that can be written more easily using `Object#presence` defined by Active Support.'
845845
Enabled: true
846846
VersionAdded: '0.52'
847-
VersionChanged: '<<next>>'
847+
VersionChanged: '2.34'
848848

849849
Rails/Present:
850850
Description: 'Enforces use of `present?`.'
@@ -887,7 +887,7 @@ Rails/RedirectBackOrTo:
887887
`fallback_location` option.
888888
Enabled: pending
889889
Severity: warning
890-
VersionAdded: '<<next>>'
890+
VersionAdded: '2.34'
891891

892892
Rails/RedundantActiveRecordAllMethod:
893893
Description: Detect redundant `all` used as a receiver for Active Record query methods.

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.34'
66
nav:
77
- modules/ROOT/nav.adoc

docs/modules/ROOT/pages/cops.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
5555
* xref:cops_rails.adoc#railsenumhash[Rails/EnumHash]
5656
* xref:cops_rails.adoc#railsenumsyntax[Rails/EnumSyntax]
5757
* xref:cops_rails.adoc#railsenumuniqueness[Rails/EnumUniqueness]
58+
* xref:cops_rails.adoc#railsenv[Rails/Env]
5859
* xref:cops_rails.adoc#railsenvlocal[Rails/EnvLocal]
5960
* xref:cops_rails.adoc#railsenvironmentcomparison[Rails/EnvironmentComparison]
6061
* xref:cops_rails.adoc#railsenvironmentvariableaccess[Rails/EnvironmentVariableAccess]
@@ -71,6 +72,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
7172
* xref:cops_rails.adoc#railshelperinstancevariable[Rails/HelperInstanceVariable]
7273
* xref:cops_rails.adoc#railshttppositionalarguments[Rails/HttpPositionalArguments]
7374
* xref:cops_rails.adoc#railshttpstatus[Rails/HttpStatus]
75+
* xref:cops_rails.adoc#railshttpstatusnameconsistency[Rails/HttpStatusNameConsistency]
7476
* xref:cops_rails.adoc#railsi18nlazylookup[Rails/I18nLazyLookup]
7577
* xref:cops_rails.adoc#railsi18nlocaleassignment[Rails/I18nLocaleAssignment]
7678
* xref:cops_rails.adoc#railsi18nlocaletexts[Rails/I18nLocaleTexts]
@@ -101,6 +103,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
101103
* xref:cops_rails.adoc#railspresent[Rails/Present]
102104
* xref:cops_rails.adoc#railsrakeenvironment[Rails/RakeEnvironment]
103105
* xref:cops_rails.adoc#railsreadwriteattribute[Rails/ReadWriteAttribute]
106+
* xref:cops_rails.adoc#railsredirectbackorto[Rails/RedirectBackOrTo]
104107
* xref:cops_rails.adoc#railsredundantactiverecordallmethod[Rails/RedundantActiveRecordAllMethod]
105108
* xref:cops_rails.adoc#railsredundantallownil[Rails/RedundantAllowNil]
106109
* xref:cops_rails.adoc#railsredundantforeignkey[Rails/RedundantForeignKey]

docs/modules/ROOT/pages/cops_rails.adoc

Lines changed: 160 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ has_one :foo
18271827
| 2.18
18281828
|===
18291829
1830-
Checks for multiple scopes in a model that have the same `where` clause. This
1830+
Checks for multiple scopes in a model that have the same expression. This
18311831
often means you copy/pasted a scope, updated the name, and forgot to change the condition.
18321832
18331833
[#examples-railsduplicatescope]
@@ -2184,6 +2184,35 @@ enum status: [:active, :archived]
21842184
| Array
21852185
|===
21862186
2187+
[#railsenv]
2188+
== Rails/Env
2189+
2190+
|===
2191+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
2192+
2193+
| Disabled
2194+
| Yes
2195+
| No
2196+
| 2.34
2197+
| -
2198+
|===
2199+
2200+
Checks for usage of `Rails.env` which can be replaced with Feature Flags
2201+
2202+
[#examples-railsenv]
2203+
=== Examples
2204+
2205+
[source,ruby]
2206+
----
2207+
# bad
2208+
Rails.env.production? || Rails.env.local?
2209+
2210+
# good
2211+
if FeatureFlag.enabled?(:new_feature)
2212+
# new feature code
2213+
end
2214+
----
2215+
21872216
[#railsenvlocal]
21882217
== Rails/EnvLocal
21892218
@@ -2227,7 +2256,7 @@ Rails.env.local?
22272256
| -
22282257
|===
22292258
2230-
Checks that Rails.env is compared using `.production?`-like
2259+
Checks that `Rails.env` is compared using `.production?`-like
22312260
methods instead of equality against a string or symbol.
22322261
22332262
[#examples-railsenvironmentcomparison]
@@ -2237,6 +2266,7 @@ methods instead of equality against a string or symbol.
22372266
----
22382267
# bad
22392268
Rails.env == 'production'
2269+
Rails.env.to_sym == :production
22402270
22412271
# bad, always returns false
22422272
Rails.env == :test
@@ -2351,7 +2381,7 @@ ENV["FOO"] = "bar"
23512381
| -
23522382
|===
23532383
2354-
Enforces that `exit` calls are not used within a rails app.
2384+
Enforces that `exit` and `abort` calls are not used within a rails app.
23552385
Valid options are instead to raise an error, break, return, or some
23562386
other form of stopping execution of current request.
23572387
@@ -2626,6 +2656,9 @@ Avoid memoizing `find_by` results with `||=`.
26262656
It is common to see code that attempts to memoize `find_by` result by `||=`,
26272657
but `find_by` may return `nil`, in which case it is not memoized as intended.
26282658
2659+
NOTE: Respecting the object shapes introduced in Ruby 3.2, instance variables used
2660+
for memoization that are initialized at object creation are ignored.
2661+
26292662
[#safety-railsfindbyorassignmentmemoization]
26302663
=== Safety
26312664
@@ -2921,7 +2954,7 @@ If it seems awkward to explicitly pass in each dependent
29212954
variable, consider moving the behavior elsewhere, for
29222955
example to a model, decorator or presenter.
29232956
2924-
Provided that a class inherits `ActionView::Helpers::FormBuilder`,
2957+
Provided that an instance variable belongs to a class,
29252958
an offense will not be registered.
29262959
29272960
[#examples-railshelperinstancevariable]
@@ -2940,8 +2973,16 @@ def welcome_message(user)
29402973
end
29412974
29422975
# good
2943-
class MyFormBuilder < ActionView::Helpers::FormBuilder
2944-
@template.do_something
2976+
module ButtonHelper
2977+
class Welcome
2978+
def initialize(text:)
2979+
@text = text
2980+
end
2981+
end
2982+
2983+
def welcome(**)
2984+
render Welcome.new(**)
2985+
end
29452986
end
29462987
----
29472988
@@ -3083,6 +3124,50 @@ assert_redirected_to '/some/path', status: 301
30833124
| `numeric`, `symbolic`
30843125
|===
30853126
3127+
[#railshttpstatusnameconsistency]
3128+
== Rails/HttpStatusNameConsistency
3129+
3130+
|===
3131+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
3132+
3133+
| Pending
3134+
| Yes
3135+
| Always
3136+
| 2.34
3137+
| -
3138+
|===
3139+
3140+
Enforces consistency by using the current HTTP status names.
3141+
3142+
[#examples-railshttpstatusnameconsistency]
3143+
=== Examples
3144+
3145+
[source,ruby]
3146+
----
3147+
# bad
3148+
render json: { error: "Invalid data" }, status: :unprocessable_entity
3149+
head :payload_too_large
3150+
3151+
# good
3152+
render json: { error: "Invalid data" }, status: :unprocessable_content
3153+
head :content_too_large
3154+
----
3155+
3156+
[#configurable-attributes-railshttpstatusnameconsistency]
3157+
=== Configurable attributes
3158+
3159+
|===
3160+
| Name | Default value | Configurable values
3161+
3162+
| Severity
3163+
| `warning`
3164+
| String
3165+
3166+
| Include
3167+
| `+**/app/controllers/**/*.rb+`
3168+
| Array
3169+
|===
3170+
30863171
[#railsi18nlazylookup]
30873172
== Rails/I18nLazyLookup
30883173
@@ -4716,7 +4801,7 @@ core extensions to the numeric classes.
47164801
| Yes
47174802
| Always
47184803
| 0.52
4719-
| -
4804+
| 2.34
47204805
|===
47214806
47224807
Checks code that can be written more easily using
@@ -4761,6 +4846,24 @@ a.blank? ? b : a
47614846
a.presence || b
47624847
----
47634848
4849+
[source,ruby]
4850+
----
4851+
# bad
4852+
a.present? ? a.foo : nil
4853+
4854+
# bad
4855+
!a.present? ? nil : a.foo
4856+
4857+
# bad
4858+
a.blank? ? nil : a.foo
4859+
4860+
# bad
4861+
!a.blank? ? a.foo : nil
4862+
4863+
# good
4864+
a.presence&.foo
4865+
----
4866+
47644867
[#railspresent]
47654868
== Rails/Present
47664869
@@ -4980,6 +5083,56 @@ end
49805083
49815084
* https://rails.rubystyle.guide#read-attribute
49825085
5086+
[#railsredirectbackorto]
5087+
== Rails/RedirectBackOrTo
5088+
5089+
NOTE: Requires Rails version 7.0
5090+
5091+
|===
5092+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
5093+
5094+
| Pending
5095+
| Yes
5096+
| Always
5097+
| 2.34
5098+
| -
5099+
|===
5100+
5101+
Checks for uses of `redirect_back(fallback_location: ...)` and
5102+
suggests using `redirect_back_or_to(...)` instead.
5103+
5104+
`redirect_back(fallback_location: ...)` was soft deprecated in Rails 7.0 and
5105+
`redirect_back_or_to` was introduced as a replacement.
5106+
5107+
[#examples-railsredirectbackorto]
5108+
=== Examples
5109+
5110+
[source,ruby]
5111+
----
5112+
# bad
5113+
redirect_back(fallback_location: root_path)
5114+
5115+
# good
5116+
redirect_back_or_to(root_path)
5117+
5118+
# bad
5119+
redirect_back(fallback_location: root_path, allow_other_host: false)
5120+
5121+
# good
5122+
redirect_back_or_to(root_path, allow_other_host: false)
5123+
----
5124+
5125+
[#configurable-attributes-railsredirectbackorto]
5126+
=== Configurable attributes
5127+
5128+
|===
5129+
| Name | Default value | Configurable values
5130+
5131+
| Severity
5132+
| `warning`
5133+
| String
5134+
|===
5135+
49835136
[#railsredundantactiverecordallmethod]
49845137
== Rails/RedundantActiveRecordAllMethod
49855138

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.33.4'
7+
STRING = '2.34.0'
88

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

relnotes/v2.34.0.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### New features
2+
3+
* [#1520](https://github.com/rubocop/rubocop-rails/pull/1520): New `Rails/HttpStatusNameConsistency` cop. ([@tuxagon][])
4+
* [#1376](https://github.com/rubocop/rubocop-rails/issues/1376): Add new `Rails/Env` cop. ([@cdudas17][])
5+
* [#1541](https://github.com/rubocop/rubocop-rails/pull/1541): Add new `Rails/RedirectBackOrTo` cop to suggest using `redirect_back_or_to` instead of `redirect_back` with `fallback_location`. ([@davidenglishmusic][])
6+
7+
### Bug fixes
8+
9+
* [#1539](https://github.com/rubocop/rubocop-rails/issues/1539): Fix an error in `Rails/ActionControllerFlashBeforeRender` when `flash` is used inside a block followed by method chaining. ([@koic][])
10+
* [#1553](https://github.com/rubocop/rubocop-rails/issues/1553): Fix false positives for `Rails/OutputSafety` when using non-interpolated multiline heredoc. ([@koic][])
11+
* [#1532](https://github.com/rubocop/rubocop-rails/issues/1532): Fix false positives for `Rails/FindByOrAssignmentMemoization` when assigning a memoization instance variable at `initialize` method. ([@koic][])
12+
* [#1549](https://github.com/rubocop/rubocop-rails/pull/1549): Fix `Rails/InverseOf` cop false positives when using dynamic association options. ([@viralpraxis][])
13+
14+
### Changes
15+
16+
* [#1537](https://github.com/rubocop/rubocop-rails/pull/1537): Add `abort` to the `Rails/Exit` cop. ([@adamstegman][])
17+
* [#932](https://github.com/rubocop/rubocop-rails/issues/932): Add support for chained method calls in `Rails/Presence`. ([@vlad-pisanov][])
18+
* [#1525](https://github.com/rubocop/rubocop-rails/issues/1525): Change `Rails::HelperInstanceVariable` not to detect offenses for instance variables within classes. ([@viralpraxis][])
19+
* [#1481](https://github.com/rubocop/rubocop-rails/pull/1481): Recognize `Rails.env.to_sym` in `Rails/EnvironmentComparison`. ([@lovro-bikic][])
20+
21+
[@tuxagon]: https://github.com/tuxagon
22+
[@cdudas17]: https://github.com/cdudas17
23+
[@davidenglishmusic]: https://github.com/davidenglishmusic
24+
[@koic]: https://github.com/koic
25+
[@viralpraxis]: https://github.com/viralpraxis
26+
[@adamstegman]: https://github.com/adamstegman
27+
[@vlad-pisanov]: https://github.com/vlad-pisanov
28+
[@lovro-bikic]: https://github.com/lovro-bikic

0 commit comments

Comments
 (0)