Skip to content

Commit 3679845

Browse files
committed
Cut 2.13.0
1 parent 3cae05d commit 3679845

File tree

7 files changed

+147
-5
lines changed

7 files changed

+147
-5
lines changed

CHANGELOG.md

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

33
## master (unreleased)
44

5+
## 2.13.0 (2021-12-25)
6+
57
### New features
68

79
* [#586](https://github.com/rubocop/rubocop-rails/pull/586): Add new `Rails/RootJoinChain` cop. ([@leoarnold][])

config/default.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Rails/CompactBlank:
184184
Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
185185
Enabled: pending
186186
Safe: false
187-
VersionAdded: '<<next>>'
187+
VersionAdded: '2.13'
188188

189189
Rails/ContentTag:
190190
Description: 'Use `tag.something` instead of `tag(:something)`.'
@@ -627,7 +627,7 @@ Rails/RedundantForeignKey:
627627
Rails/RedundantPresenceValidationOnBelongsTo:
628628
Description: 'Checks for redundant presence validation on belongs_to association.'
629629
Enabled: pending
630-
VersionAdded: '<<next>>'
630+
VersionAdded: '2.13'
631631

632632
Rails/RedundantReceiverInWithOptions:
633633
Description: 'Checks for redundant receiver in `with_options`.'
@@ -715,7 +715,7 @@ Rails/ReversibleMigrationMethodDefinition:
715715
Rails/RootJoinChain:
716716
Description: 'Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.'
717717
Enabled: pending
718-
VersionAdded: '<<next>>'
718+
VersionAdded: '2.13'
719719

720720
Rails/SafeNavigation:
721721
Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."

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: master
5+
version: '2.13'
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
@@ -33,6 +33,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
3333
* xref:cops_rails.adoc#railsbelongsto[Rails/BelongsTo]
3434
* xref:cops_rails.adoc#railsblank[Rails/Blank]
3535
* xref:cops_rails.adoc#railsbulkchangetable[Rails/BulkChangeTable]
36+
* xref:cops_rails.adoc#railscompactblank[Rails/CompactBlank]
3637
* xref:cops_rails.adoc#railscontenttag[Rails/ContentTag]
3738
* xref:cops_rails.adoc#railscreatetablewithtimestamps[Rails/CreateTableWithTimestamps]
3839
* xref:cops_rails.adoc#railsdate[Rails/Date]
@@ -83,6 +84,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
8384
* xref:cops_rails.adoc#railsreadwriteattribute[Rails/ReadWriteAttribute]
8485
* xref:cops_rails.adoc#railsredundantallownil[Rails/RedundantAllowNil]
8586
* xref:cops_rails.adoc#railsredundantforeignkey[Rails/RedundantForeignKey]
87+
* xref:cops_rails.adoc#railsredundantpresencevalidationonbelongsto[Rails/RedundantPresenceValidationOnBelongsTo]
8688
* xref:cops_rails.adoc#railsredundantreceiverinwithoptions[Rails/RedundantReceiverInWithOptions]
8789
* xref:cops_rails.adoc#railsredundanttravelback[Rails/RedundantTravelBack]
8890
* xref:cops_rails.adoc#railsreflectionclassname[Rails/ReflectionClassName]
@@ -94,6 +96,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
9496
* xref:cops_rails.adoc#railsrequiredependency[Rails/RequireDependency]
9597
* xref:cops_rails.adoc#railsreversiblemigration[Rails/ReversibleMigration]
9698
* xref:cops_rails.adoc#railsreversiblemigrationmethoddefinition[Rails/ReversibleMigrationMethodDefinition]
99+
* xref:cops_rails.adoc#railsrootjoinchain[Rails/RootJoinChain]
97100
* xref:cops_rails.adoc#railssafenavigation[Rails/SafeNavigation]
98101
* xref:cops_rails.adoc#railssafenavigationwithblank[Rails/SafeNavigationWithBlank]
99102
* xref:cops_rails.adoc#railssavebang[Rails/SaveBang]

docs/modules/ROOT/pages/cops_rails.adoc

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,52 @@ end
848848
| Array
849849
|===
850850

851+
== Rails/CompactBlank
852+
853+
|===
854+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
855+
856+
| Pending
857+
| No
858+
| Yes (Unsafe)
859+
| 2.13
860+
| -
861+
|===
862+
863+
Checks if collection can be blank-compacted with `compact_blank`.
864+
865+
=== Safety
866+
867+
It is unsafe by default because false positives may occur in the
868+
blank check of block arguments to the receiver object.
869+
870+
For example, `[[1, 2], [3, nil]].reject { |first, second| second.blank? }` and
871+
`[[1, 2], [3, nil]].compact_blank` are not compatible. The same is true for `empty?`.
872+
This will work fine when the receiver is a hash object.
873+
874+
=== Examples
875+
876+
[source,ruby]
877+
----
878+
# bad
879+
collection.reject(&:blank?)
880+
collection.reject(&:empty?)
881+
collection.reject { |_k, v| v.blank? }
882+
collection.reject { |_k, v| v.empty? }
883+
884+
# good
885+
collection.compact_blank
886+
887+
# bad
888+
collection.reject!(&:blank?)
889+
collection.reject!(&:empty?)
890+
collection.reject! { |_k, v| v.blank? }
891+
collection.reject! { |_k, v| v.empty? }
892+
893+
# good
894+
collection.compact_blank!
895+
----
896+
851897
== Rails/ContentTag
852898

853899
|===
@@ -3507,6 +3553,46 @@ class Comment
35073553
end
35083554
----
35093555

3556+
== Rails/RedundantPresenceValidationOnBelongsTo
3557+
3558+
|===
3559+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
3560+
3561+
| Pending
3562+
| Yes
3563+
| Yes
3564+
| 2.13
3565+
| -
3566+
|===
3567+
3568+
Since Rails 5.0 the default for `belongs_to` is `optional: false`
3569+
unless `config.active_record.belongs_to_required_by_default` is
3570+
explicitly set to `false`. The presence validator is added
3571+
automatically, and explicit presence validation is redundant.
3572+
3573+
=== Examples
3574+
3575+
[source,ruby]
3576+
----
3577+
# bad
3578+
belongs_to :user
3579+
validates :user, presence: true
3580+
3581+
# bad
3582+
belongs_to :user
3583+
validates :user_id, presence: true
3584+
3585+
# bad
3586+
belongs_to :author, foreign_key: :user_id
3587+
validates :user_id, presence: true
3588+
3589+
# good
3590+
belongs_to :user
3591+
3592+
# good
3593+
belongs_to :author, foreign_key: :user_id
3594+
----
3595+
35103596
== Rails/RedundantReceiverInWithOptions
35113597

35123598
|===
@@ -4232,6 +4318,37 @@ end
42324318
| Array
42334319
|===
42344320

4321+
== Rails/RootJoinChain
4322+
4323+
|===
4324+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
4325+
4326+
| Pending
4327+
| Yes
4328+
| Yes
4329+
| 2.13
4330+
| -
4331+
|===
4332+
4333+
Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.
4334+
4335+
=== Examples
4336+
4337+
[source,ruby]
4338+
----
4339+
# bad
4340+
Rails.root.join('db').join('schema.rb')
4341+
Rails.root.join('db').join(migrate).join('migration.rb')
4342+
Rails.public_path.join('path').join('file.pdf')
4343+
Rails.public_path.join('path').join(to).join('file.pdf')
4344+
4345+
# good
4346+
Rails.root.join('db', 'schema.rb')
4347+
Rails.root.join('db', migrate, 'migration.rb')
4348+
Rails.public_path.join('path', 'file.pdf')
4349+
Rails.public_path.join('path', to, 'file.pdf')
4350+
----
4351+
42354352
== Rails/SafeNavigation
42364353

42374354
|===

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.12.4'
7+
STRING = '2.13.0'
88

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

relnotes/v2.13.0.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### New features
2+
3+
* [#586](https://github.com/rubocop/rubocop-rails/pull/586): Add new `Rails/RootJoinChain` cop. ([@leoarnold][])
4+
* [#571](https://github.com/rubocop/rubocop-rails/issues/571): Add `Rails/DurationArithmetic` cop. ([@pirj][])
5+
* [#594](https://github.com/rubocop/rubocop-rails/pull/594): Add `Rails/RedundantPresenceValidationOnBelongsTo` cop. ([@pirj][])
6+
* [#568](https://github.com/rubocop/rubocop-rails/issues/568): Add `Rails/SchemaComment` cop. ([@vitormd][])
7+
8+
### Changes
9+
10+
* [#591](https://github.com/rubocop/rubocop-rails/issues/591): Add `change_column` check to `Rails/ReversibleMigration`. ([@mattmccormick][])
11+
* Add `remove_reference` check to `Rails/ReversibleMigration`. ([@mattmccormick][])
12+
* [#576](https://github.com/rubocop/rubocop-rails/pull/576): Mark `Rails/TimeZone` as unsafe auto-correction from unsafe. ([@koic][])
13+
* [#582](https://github.com/rubocop/rubocop-rails/pull/582): Unmark `AutoCorrect: false` from `Rails/RelativeDateConstant`. ([@koic][])
14+
* [#580](https://github.com/rubocop/rubocop-rails/pull/580): Unmark `AutoCorrect: false` from `Rails/UniqBeforePluck`. ([@koic][])
15+
16+
[@leoarnold]: https://github.com/leoarnold
17+
[@pirj]: https://github.com/pirj
18+
[@vitormd]: https://github.com/vitormd
19+
[@mattmccormick]: https://github.com/mattmccormick
20+
[@koic]: https://github.com/koic

0 commit comments

Comments
 (0)