Skip to content

Commit

Permalink
Cut 2.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Dec 25, 2021
1 parent 3cae05d commit 3679845
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)

## 2.13.0 (2021-12-25)

### New features

* [#586](https://github.com/rubocop/rubocop-rails/pull/586): Add new `Rails/RootJoinChain` cop. ([@leoarnold][])
Expand Down
6 changes: 3 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Rails/CompactBlank:
Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
Enabled: pending
Safe: false
VersionAdded: '<<next>>'
VersionAdded: '2.13'

Rails/ContentTag:
Description: 'Use `tag.something` instead of `tag(:something)`.'
Expand Down Expand Up @@ -627,7 +627,7 @@ Rails/RedundantForeignKey:
Rails/RedundantPresenceValidationOnBelongsTo:
Description: 'Checks for redundant presence validation on belongs_to association.'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '2.13'

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

Rails/SafeNavigation:
Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: master
version: '2.13'
nav:
- modules/ROOT/nav.adoc
3 changes: 3 additions & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railsbelongsto[Rails/BelongsTo]
* xref:cops_rails.adoc#railsblank[Rails/Blank]
* xref:cops_rails.adoc#railsbulkchangetable[Rails/BulkChangeTable]
* xref:cops_rails.adoc#railscompactblank[Rails/CompactBlank]
* xref:cops_rails.adoc#railscontenttag[Rails/ContentTag]
* xref:cops_rails.adoc#railscreatetablewithtimestamps[Rails/CreateTableWithTimestamps]
* xref:cops_rails.adoc#railsdate[Rails/Date]
Expand Down Expand Up @@ -83,6 +84,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railsreadwriteattribute[Rails/ReadWriteAttribute]
* xref:cops_rails.adoc#railsredundantallownil[Rails/RedundantAllowNil]
* xref:cops_rails.adoc#railsredundantforeignkey[Rails/RedundantForeignKey]
* xref:cops_rails.adoc#railsredundantpresencevalidationonbelongsto[Rails/RedundantPresenceValidationOnBelongsTo]
* xref:cops_rails.adoc#railsredundantreceiverinwithoptions[Rails/RedundantReceiverInWithOptions]
* xref:cops_rails.adoc#railsredundanttravelback[Rails/RedundantTravelBack]
* xref:cops_rails.adoc#railsreflectionclassname[Rails/ReflectionClassName]
Expand All @@ -94,6 +96,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railsrequiredependency[Rails/RequireDependency]
* xref:cops_rails.adoc#railsreversiblemigration[Rails/ReversibleMigration]
* xref:cops_rails.adoc#railsreversiblemigrationmethoddefinition[Rails/ReversibleMigrationMethodDefinition]
* xref:cops_rails.adoc#railsrootjoinchain[Rails/RootJoinChain]
* xref:cops_rails.adoc#railssafenavigation[Rails/SafeNavigation]
* xref:cops_rails.adoc#railssafenavigationwithblank[Rails/SafeNavigationWithBlank]
* xref:cops_rails.adoc#railssavebang[Rails/SaveBang]
Expand Down
117 changes: 117 additions & 0 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,52 @@ end
| Array
|===

== Rails/CompactBlank

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| No
| Yes (Unsafe)
| 2.13
| -
|===

Checks if collection can be blank-compacted with `compact_blank`.

=== Safety

It is unsafe by default because false positives may occur in the
blank check of block arguments to the receiver object.

For example, `[[1, 2], [3, nil]].reject { |first, second| second.blank? }` and
`[[1, 2], [3, nil]].compact_blank` are not compatible. The same is true for `empty?`.
This will work fine when the receiver is a hash object.

=== Examples

[source,ruby]
----
# bad
collection.reject(&:blank?)
collection.reject(&:empty?)
collection.reject { |_k, v| v.blank? }
collection.reject { |_k, v| v.empty? }
# good
collection.compact_blank
# bad
collection.reject!(&:blank?)
collection.reject!(&:empty?)
collection.reject! { |_k, v| v.blank? }
collection.reject! { |_k, v| v.empty? }
# good
collection.compact_blank!
----

== Rails/ContentTag

|===
Expand Down Expand Up @@ -3507,6 +3553,46 @@ class Comment
end
----

== Rails/RedundantPresenceValidationOnBelongsTo

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| Yes
| Yes
| 2.13
| -
|===

Since Rails 5.0 the default for `belongs_to` is `optional: false`
unless `config.active_record.belongs_to_required_by_default` is
explicitly set to `false`. The presence validator is added
automatically, and explicit presence validation is redundant.

=== Examples

[source,ruby]
----
# bad
belongs_to :user
validates :user, presence: true
# bad
belongs_to :user
validates :user_id, presence: true
# bad
belongs_to :author, foreign_key: :user_id
validates :user_id, presence: true
# good
belongs_to :user
# good
belongs_to :author, foreign_key: :user_id
----

== Rails/RedundantReceiverInWithOptions

|===
Expand Down Expand Up @@ -4232,6 +4318,37 @@ end
| Array
|===

== Rails/RootJoinChain

|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| Yes
| Yes
| 2.13
| -
|===

Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.

=== Examples

[source,ruby]
----
# bad
Rails.root.join('db').join('schema.rb')
Rails.root.join('db').join(migrate).join('migration.rb')
Rails.public_path.join('path').join('file.pdf')
Rails.public_path.join('path').join(to).join('file.pdf')
# good
Rails.root.join('db', 'schema.rb')
Rails.root.join('db', migrate, 'migration.rb')
Rails.public_path.join('path', 'file.pdf')
Rails.public_path.join('path', to, 'file.pdf')
----

== Rails/SafeNavigation

|===
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RuboCop
module Rails
# This module holds the RuboCop Rails version information.
module Version
STRING = '2.12.4'
STRING = '2.13.0'

def self.document_version
STRING.match('\d+\.\d+').to_s
Expand Down
20 changes: 20 additions & 0 deletions relnotes/v2.13.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### New features

* [#586](https://github.com/rubocop/rubocop-rails/pull/586): Add new `Rails/RootJoinChain` cop. ([@leoarnold][])
* [#571](https://github.com/rubocop/rubocop-rails/issues/571): Add `Rails/DurationArithmetic` cop. ([@pirj][])
* [#594](https://github.com/rubocop/rubocop-rails/pull/594): Add `Rails/RedundantPresenceValidationOnBelongsTo` cop. ([@pirj][])
* [#568](https://github.com/rubocop/rubocop-rails/issues/568): Add `Rails/SchemaComment` cop. ([@vitormd][])

### Changes

* [#591](https://github.com/rubocop/rubocop-rails/issues/591): Add `change_column` check to `Rails/ReversibleMigration`. ([@mattmccormick][])
* Add `remove_reference` check to `Rails/ReversibleMigration`. ([@mattmccormick][])
* [#576](https://github.com/rubocop/rubocop-rails/pull/576): Mark `Rails/TimeZone` as unsafe auto-correction from unsafe. ([@koic][])
* [#582](https://github.com/rubocop/rubocop-rails/pull/582): Unmark `AutoCorrect: false` from `Rails/RelativeDateConstant`. ([@koic][])
* [#580](https://github.com/rubocop/rubocop-rails/pull/580): Unmark `AutoCorrect: false` from `Rails/UniqBeforePluck`. ([@koic][])

[@leoarnold]: https://github.com/leoarnold
[@pirj]: https://github.com/pirj
[@vitormd]: https://github.com/vitormd
[@mattmccormick]: https://github.com/mattmccormick
[@koic]: https://github.com/koic

0 comments on commit 3679845

Please sign in to comment.