Skip to content

Commit 02b06d9

Browse files
committed
Cut 2.19.0
1 parent d636e3a commit 02b06d9

File tree

7 files changed

+128
-29
lines changed

7 files changed

+128
-29
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.19.0 (2023-04-07)
13+
1214
### New features
1315

1416
* [#337](https://github.com/rubocop/rubocop-rails/issues/337): Add new `Rails/ThreeStateBooleanColumn` cop. ([@fatkodima][])

config/default.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ Rails/FindEach:
462462
Enabled: true
463463
Safe: false
464464
VersionAdded: '0.30'
465-
VersionChanged: '<<next>>'
465+
VersionChanged: '2.19'
466466
Include:
467467
- app/models/**/*.rb
468468
AllowedMethods:
@@ -845,7 +845,7 @@ Rails/ResponseParsedBody:
845845
Enabled: pending
846846
Safe: false
847847
VersionAdded: '2.18'
848-
VersionChanged: '<<next>>'
848+
VersionChanged: '2.19'
849849
Include:
850850
- spec/controllers/**/*.rb
851851
- spec/requests/**/*.rb
@@ -1001,7 +1001,7 @@ Rails/ThreeStateBooleanColumn:
10011001
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
10021002
StyleGuide: 'https://rails.rubystyle.guide/#three-state-boolean'
10031003
Enabled: pending
1004-
VersionAdded: '<<next>>'
1004+
VersionAdded: '2.19'
10051005
Include:
10061006
- db/**/*.rb
10071007

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.19'
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
@@ -123,6 +123,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
123123
* xref:cops_rails.adoc#railssquishedsqlheredocs[Rails/SquishedSQLHeredocs]
124124
* xref:cops_rails.adoc#railsstripheredoc[Rails/StripHeredoc]
125125
* xref:cops_rails.adoc#railstablenameassignment[Rails/TableNameAssignment]
126+
* xref:cops_rails.adoc#railsthreestatebooleancolumn[Rails/ThreeStateBooleanColumn]
126127
* xref:cops_rails.adoc#railstimezone[Rails/TimeZone]
127128
* xref:cops_rails.adoc#railstimezoneassignment[Rails/TimeZoneAssignment]
128129
* xref:cops_rails.adoc#railstoformatteds[Rails/ToFormattedS]

docs/modules/ROOT/pages/cops_rails.adoc

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ class HomeController < ApplicationController
4141
end
4242
----
4343

44-
=== References
45-
46-
* https://rails.rubystyle.guide/#flash-before-render
47-
* https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html
48-
4944
== Rails/ActionControllerTestCase
5045

5146
|===
@@ -1163,10 +1158,12 @@ tag(name, class: 'classname')
11631158
| -
11641159
|===
11651160

1166-
Checks the migration for which timestamps are not included
1167-
when creating a new table.
1161+
Checks the migration for which timestamps are not included when creating a new table.
11681162
In many cases, timestamps are useful information and should be added.
11691163

1164+
NOTE: Allow `timestamps` not written when `id: false` because this emphasizes respecting
1165+
user's editing intentions.
1166+
11701167
=== Examples
11711168

11721169
[source,ruby]
@@ -1203,6 +1200,12 @@ create_table :users do |t|
12031200
12041201
t.datetime :updated_at, default: -> { 'CURRENT_TIMESTAMP' }
12051202
end
1203+
1204+
# good
1205+
create_table :users, articles, id: false do |t|
1206+
t.integer :user_id
1207+
t.integer :article_id
1208+
end
12061209
----
12071210

12081211
=== Configurable attributes
@@ -1386,6 +1389,14 @@ end
13861389
# good
13871390
delegate :bar, to: :foo
13881391
1392+
# bad
1393+
def bar
1394+
self.bar
1395+
end
1396+
1397+
# good
1398+
delegate :bar, to: :self
1399+
13891400
# good
13901401
def bar
13911402
foo&.bar
@@ -2088,9 +2099,8 @@ date.all_year
20882099
| 2.4
20892100
|===
20902101

2091-
Identifies usages of file path joining process
2092-
to use `Rails.root.join` clause. It is used to add uniformity when
2093-
joining paths.
2102+
Identifies usages of file path joining process to use `Rails.root.join` clause.
2103+
It is used to add uniformity when joining paths.
20942104

20952105
=== Examples
20962106

@@ -2100,11 +2110,16 @@ joining paths.
21002110
----
21012111
# bad
21022112
Rails.root.join('app', 'models', 'goober')
2113+
2114+
# good
2115+
Rails.root.join('app/models/goober')
2116+
2117+
# bad
21032118
File.join(Rails.root, 'app/models/goober')
21042119
"#{Rails.root}/app/models/goober"
21052120
21062121
# good
2107-
Rails.root.join('app/models/goober')
2122+
Rails.root.join('app/models/goober').to_s
21082123
----
21092124

21102125
==== EnforcedStyle: arguments
@@ -2113,11 +2128,16 @@ Rails.root.join('app/models/goober')
21132128
----
21142129
# bad
21152130
Rails.root.join('app/models/goober')
2131+
2132+
# good
2133+
Rails.root.join('app', 'models', 'goober')
2134+
2135+
# bad
21162136
File.join(Rails.root, 'app/models/goober')
21172137
"#{Rails.root}/app/models/goober"
21182138
21192139
# good
2120-
Rails.root.join('app', 'models', 'goober')
2140+
Rails.root.join('app', 'models', 'goober').to_s
21212141
----
21222142

21232143
=== Configurable attributes
@@ -2233,14 +2253,19 @@ User.find(id)
22332253
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
22342254

22352255
| Enabled
2236-
| Yes
2237-
| Yes
2256+
| No
2257+
| Yes (Unsafe)
22382258
| 0.30
2239-
| 2.9
2259+
| 2.19
22402260
|===
22412261

2242-
Identifies usages of `all.each` and
2243-
change them to use `all.find_each` instead.
2262+
Identifies usages of `all.each` and change them to use `all.find_each` instead.
2263+
2264+
=== Safety
2265+
2266+
This cop is unsafe if the receiver object is not an Active Record object.
2267+
Also, `all.each` returns an `Array` instance and `all.find_each` returns nil,
2268+
so the return values are different.
22442269

22452270
=== Examples
22462271

@@ -2506,6 +2531,9 @@ If you are running Rails < 5 you should disable the
25062531
Rails/HttpPositionalArguments cop or set your TargetRailsVersion in your
25072532
.rubocop.yml file to 4.2.
25082533

2534+
NOTE: It does not detect any cases where `include Rack::Test::Methods` is used
2535+
which makes the http methods incompatible behavior.
2536+
25092537
=== Examples
25102538

25112539
[source,ruby]
@@ -4450,7 +4478,7 @@ end
44504478

44514479
| Enabled
44524480
| No
4453-
| No
4481+
| Yes (Unsafe)
44544482
| 0.64
44554483
| 2.10
44564484
|===
@@ -4770,19 +4798,19 @@ require_dependency 'some_lib'
47704798
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
47714799

47724800
| Pending
4773-
| Yes
4801+
| No
47744802
| Yes (Unsafe)
47754803
| 2.18
4776-
| -
4804+
| 2.19
47774805
|===
47784806

47794807
Prefer `response.parsed_body` to `JSON.parse(response.body)`.
47804808

47814809
=== Safety
47824810

4783-
This cop's autocorrection is unsafe because Content-Type may not be `application/json`. For example, the
4784-
proprietary Content-Type provided by corporate entities such as `application/vnd.github+json` is not
4785-
supported at `response.parsed_body` by default, so you still have to use `JSON.parse(response.body)` there.
4811+
This cop is unsafe because Content-Type may not be `application/json`. For example, the proprietary
4812+
Content-Type provided by corporate entities such as `application/vnd.github+json` is not supported at
4813+
`response.parsed_body` by default, so you still have to use `JSON.parse(response.body)` there.
47864814

47874815
=== Examples
47884816

@@ -5801,6 +5829,50 @@ self.table_name = :some_other_name
58015829

58025830
* https://rails.rubystyle.guide/#keep-ar-defaults
58035831

5832+
== Rails/ThreeStateBooleanColumn
5833+
5834+
|===
5835+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
5836+
5837+
| Pending
5838+
| Yes
5839+
| No
5840+
| 2.19
5841+
| -
5842+
|===
5843+
5844+
Enforces that boolean columns are created with default values (`false` or `true`) and
5845+
`NOT NULL` constraint.
5846+
5847+
=== Examples
5848+
5849+
[source,ruby]
5850+
----
5851+
# bad
5852+
add_column :users, :active, :boolean
5853+
t.column :active, :boolean
5854+
t.boolean :active
5855+
5856+
# good
5857+
add_column :users, :active, :boolean, default: true, null: false
5858+
t.column :active, :boolean, default: true, null: false
5859+
t.boolean :active, default: true, null: false
5860+
----
5861+
5862+
=== Configurable attributes
5863+
5864+
|===
5865+
| Name | Default value | Configurable values
5866+
5867+
| Include
5868+
| `+db/**/*.rb+`
5869+
| Array
5870+
|===
5871+
5872+
=== References
5873+
5874+
* https://rails.rubystyle.guide/#three-state-boolean
5875+
58045876
== Rails/TimeZone
58055877

58065878
|===
@@ -6200,7 +6272,7 @@ customer.favourites.distinct.pluck(:color)
62006272
|===
62016273

62026274
When you define a uniqueness validation in Active Record model,
6203-
you also should add a unique index for the column. There are two reasons
6275+
you also should add a unique index for the column. There are two reasons.
62046276
First, duplicated records may occur even if Active Record's validation
62056277
is defined.
62066278
Second, it will cause slow queries. The validation executes a `SELECT`

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.18.0'
7+
STRING = '2.19.0'
88

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

relnotes/v2.19.0.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### New features
2+
3+
* [#337](https://github.com/rubocop/rubocop-rails/issues/337): Add new `Rails/ThreeStateBooleanColumn` cop. ([@fatkodima][])
4+
* [#45](https://github.com/rubocop/rubocop-rails/issues/45): Make `Rails/Delegate` aware of `self`. ([@koic][])
5+
6+
### Bug fixes
7+
8+
* [#934](https://github.com/rubocop/rubocop-rails/issues/934): Fix a false negative for `Rails/Output` when print methods without arguments. ([@koic][])
9+
* [#99](https://github.com/rubocop/rubocop-rails/issues/99): Fix a false positive for `Rails/HttpPositionalArguments` when using `include Rack::Test::Methods`. ([@koic][])
10+
* [#501](https://github.com/rubocop/rubocop-rails/issues/501): Fix a false positive for `Rails/OutputSafety` when using `html_safe` for `I18n` methods. ([@koic][])
11+
* [#860](https://github.com/rubocop/rubocop-rails/issues/860): Fix a false positive for `Rails/Pluck` when using regexp literal key for `String#[]`. ([@koic][])
12+
* [#938](https://github.com/rubocop/rubocop-rails/issues/938): Fix an error for `Rails/WhereNotWithMultipleConditions` when using `where.not.lt(condition)` as a Mongoid API'. ([@koic][])
13+
* [#941](https://github.com/rubocop/rubocop-rails/issues/941): Remove redundant config for `Style/InverseMethods`. ([@koic][])
14+
15+
### Changes
16+
17+
* [#299](https://github.com/rubocop/rubocop-rails/pull/299): Add autocorrection for `Rails/ReflectionClassName`. ([@tejasbubane][])
18+
* [#34](https://github.com/rubocop/rubocop-rails/issues/34): Allow `CreateTableWithTimestamps` when using `id: false` and not include `timestamps`. ([@koic][])
19+
* [#694](https://github.com/rubocop/rubocop-rails/issues/694): Mark `Rails/FindEach` as unsafe. ([@koic][])
20+
* [#940](https://github.com/rubocop/rubocop-rails/issues/940): Mark `Rails/ResponseParsedBody` as unsafe. ([@koic][])
21+
22+
[@fatkodima]: https://github.com/fatkodima
23+
[@koic]: https://github.com/koic
24+
[@tejasbubane]: https://github.com/tejasbubane

0 commit comments

Comments
 (0)