Skip to content

Commit 177c92f

Browse files
committed
Cut 2.17.0
1 parent 1cb96f9 commit 177c92f

File tree

7 files changed

+155
-19
lines changed

7 files changed

+155
-19
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.17.0 (2022-10-22)
6+
57
### New features
68

79
* [#547](https://github.com/rubocop/rubocop-rails/pull/547): Add new `Rails/ActionOrder` cop. ([@mollerhoj][])

config/default.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Rails/ActionFilter:
101101
Rails/ActionOrder:
102102
Description: 'Enforce consistent ordering of controller actions.'
103103
Enabled: pending
104-
VersionAdded: '<<next>>'
104+
VersionAdded: '2.17'
105105
ExpectedOrder:
106106
- index
107107
- show
@@ -561,7 +561,7 @@ Rails/IgnoredColumnsAssignment:
561561
StyleGuide: 'https://rails.rubystyle.guide/#append-ignored-columns'
562562
Enabled: pending
563563
SafeAutoCorrect: false
564-
VersionAdded: '<<next>>'
564+
VersionAdded: '2.17'
565565

566566
Rails/IgnoredSkipActionFilterOption:
567567
Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
@@ -1121,7 +1121,7 @@ Rails/WhereNot:
11211121
Rails/WhereNotWithMultipleConditions:
11221122
Description: 'Do not use `where.not(...)` with multiple conditions.'
11231123
Enabled: 'pending'
1124-
VersionAdded: '<<next>>'
1124+
VersionAdded: '2.17'
11251125

11261126
# Accept `redirect_to(...) and return` and similar cases.
11271127
Style/AndOr:

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

docs/modules/ROOT/pages/cops.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
7070
* xref:cops_rails.adoc#railsi18nlazylookup[Rails/I18nLazyLookup]
7171
* xref:cops_rails.adoc#railsi18nlocaleassignment[Rails/I18nLocaleAssignment]
7272
* xref:cops_rails.adoc#railsi18nlocaletexts[Rails/I18nLocaleTexts]
73+
* xref:cops_rails.adoc#railsignoredcolumnsassignment[Rails/IgnoredColumnsAssignment]
7374
* xref:cops_rails.adoc#railsignoredskipactionfilteroption[Rails/IgnoredSkipActionFilterOption]
7475
* xref:cops_rails.adoc#railsindexby[Rails/IndexBy]
7576
* xref:cops_rails.adoc#railsindexwith[Rails/IndexWith]
@@ -136,5 +137,6 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
136137
* xref:cops_rails.adoc#railswhereexists[Rails/WhereExists]
137138
* xref:cops_rails.adoc#railswheremissing[Rails/WhereMissing]
138139
* xref:cops_rails.adoc#railswherenot[Rails/WhereNot]
140+
* xref:cops_rails.adoc#railswherenotwithmultipleconditions[Rails/WhereNotWithMultipleConditions]
139141

140142
// END_COP_LIST

docs/modules/ROOT/pages/cops_rails.adoc

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,19 @@ skip_after_filter :do_stuff
175175
== Rails/ActionOrder
176176

177177
|===
178-
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
178+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
179179

180-
| Disabled
180+
| Pending
181181
| Yes
182182
| Yes
183-
| 2.13
183+
| 2.17
184184
| -
185185
|===
186186

187-
This cop enforces consistent ordering of the standard Rails RESTful
188-
controller actions.
187+
Enforces consistent ordering of the standard Rails RESTful controller actions.
189188

190-
The cop is configurable and can enforce any ordering of the standard
191-
actions. All other methods are ignored.
189+
The cop is configurable and can enforce any ordering of the standard actions.
190+
All other methods are ignored.
192191

193192
[source,yaml]
194193
----
@@ -228,7 +227,7 @@ def destroy; end
228227
| Array
229228

230229
| Include
231-
| `app/controllers/**/*.rb`
230+
| `+app/controllers/**/*.rb+`
232231
| Array
233232
|===
234233

@@ -1672,26 +1671,30 @@ User.find_by(name: name, email: email)
16721671
User.find_by!(email: email)
16731672
----
16741673

1675-
==== AllowedMethods: find_by_sql
1674+
==== AllowedMethods: ['find_by_sql', 'find_by_token_for'] (default)
16761675

16771676
[source,ruby]
16781677
----
16791678
# bad
16801679
User.find_by_query(users_query)
1680+
User.find_by_token_for(:password_reset, token)
16811681
16821682
# good
16831683
User.find_by_sql(users_sql)
1684+
User.find_by_token_for(:password_reset, token)
16841685
----
16851686

1686-
==== AllowedReceivers: Gem::Specification
1687+
==== AllowedReceivers: ['Gem::Specification', 'page'] (default)
16871688

16881689
[source,ruby]
16891690
----
16901691
# bad
16911692
Specification.find_by_name('backend').gem_dir
1693+
page.find_by_id('a_dom_id').click
16921694
16931695
# good
16941696
Gem::Specification.find_by_name('backend').gem_dir
1697+
page.find_by_id('a_dom_id').click
16951698
----
16961699

16971700
=== Configurable attributes
@@ -1700,15 +1703,15 @@ Gem::Specification.find_by_name('backend').gem_dir
17001703
| Name | Default value | Configurable values
17011704

17021705
| Whitelist
1703-
| `find_by_sql`
1706+
| `find_by_sql`, `find_by_token_for`
17041707
| Array
17051708

17061709
| AllowedMethods
1707-
| `find_by_sql`
1710+
| `find_by_sql`, `find_by_token_for`
17081711
| Array
17091712

17101713
| AllowedReceivers
1711-
| `Gem::Specification`
1714+
| `Gem::Specification`, `page`
17121715
| Array
17131716
|===
17141717

@@ -2227,7 +2230,7 @@ User.all.find_each
22272230
User.order(:foo).each
22282231
----
22292232

2230-
==== AllowedPattern: [/order/]
2233+
==== AllowedPattern: ['order']
22312234

22322235
[source,ruby]
22332236
----
@@ -2524,13 +2527,15 @@ render json: { foo: 'bar' }, status: 200
25242527
render plain: 'foo/bar', status: 304
25252528
redirect_to root_url, status: 301
25262529
head 200
2530+
get '/foobar', to: redirect('/foobar/baz', status: 301)
25272531
25282532
# good
25292533
render :foo, status: :ok
25302534
render json: { foo: 'bar' }, status: :ok
25312535
render plain: 'foo/bar', status: :not_modified
25322536
redirect_to root_url, status: :moved_permanently
25332537
head :ok
2538+
get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
25342539
----
25352540

25362541
==== EnforcedStyle: numeric
@@ -2543,13 +2548,15 @@ render json: { foo: 'bar' }, status: :not_found
25432548
render plain: 'foo/bar', status: :not_modified
25442549
redirect_to root_url, status: :moved_permanently
25452550
head :ok
2551+
get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
25462552
25472553
# good
25482554
render :foo, status: 200
25492555
render json: { foo: 'bar' }, status: 404
25502556
render plain: 'foo/bar', status: 304
25512557
redirect_to root_url, status: 301
25522558
head 200
2559+
get '/foobar', to: redirect('/foobar/baz', status: 301)
25532560
----
25542561

25552562
=== Configurable attributes
@@ -2742,6 +2749,55 @@ end
27422749

27432750
* https://rails.rubystyle.guide/#locale-texts
27442751

2752+
== Rails/IgnoredColumnsAssignment
2753+
2754+
|===
2755+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
2756+
2757+
| Pending
2758+
| Yes
2759+
| Yes (Unsafe)
2760+
| 2.17
2761+
| -
2762+
|===
2763+
2764+
Looks for assignments of `ignored_columns` that may override previous
2765+
assignments.
2766+
2767+
Overwriting previous assignments is usually a mistake, since it will
2768+
un-ignore the first set of columns. Since duplicate column names is not
2769+
a problem, it is better to simply append to the list.
2770+
2771+
=== Examples
2772+
2773+
[source,ruby]
2774+
----
2775+
# bad
2776+
class User < ActiveRecord::Base
2777+
self.ignored_columns = [:one]
2778+
end
2779+
2780+
# bad
2781+
class User < ActiveRecord::Base
2782+
self.ignored_columns = [:one, :two]
2783+
end
2784+
2785+
# good
2786+
class User < ActiveRecord::Base
2787+
self.ignored_columns += [:one, :two]
2788+
end
2789+
2790+
# good
2791+
class User < ActiveRecord::Base
2792+
self.ignored_columns += [:one]
2793+
self.ignored_columns += [:two]
2794+
end
2795+
----
2796+
2797+
=== References
2798+
2799+
* https://rails.rubystyle.guide/#append-ignored-columns
2800+
27452801
== Rails/IgnoredSkipActionFilterOption
27462802

27472803
|===
@@ -6444,3 +6500,39 @@ User.where.not(users: { name: 'Gabe' })
64446500
=== References
64456501

64466502
* https://rails.rubystyle.guide/#hash-conditions
6503+
6504+
== Rails/WhereNotWithMultipleConditions
6505+
6506+
|===
6507+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
6508+
6509+
| Pending
6510+
| Yes
6511+
| No
6512+
| 2.17
6513+
| -
6514+
|===
6515+
6516+
Identifies calls to `where.not` with multiple hash arguments.
6517+
6518+
The behavior of `where.not` changed in Rails 6.1. Prior to the change,
6519+
`.where.not(trashed: true, role: 'admin')` evaluated to
6520+
`WHERE trashed != TRUE AND role != 'admin'`.
6521+
From Rails 6.1 onwards, this executes the query
6522+
`WHERE NOT (trashed == TRUE AND roles == 'admin')`.
6523+
6524+
=== Examples
6525+
6526+
[source,ruby]
6527+
----
6528+
# bad
6529+
User.where.not(trashed: true, role: 'admin')
6530+
User.where.not(trashed: true, role: ['moderator', 'admin'])
6531+
User.joins(:posts).where.not(posts: { trashed: true, title: 'Rails' })
6532+
6533+
# good
6534+
User.where.not(trashed: true)
6535+
User.where.not(role: ['moderator', 'admin'])
6536+
User.where.not(trashed: true).where.not(role: ['moderator', 'admin'])
6537+
User.where.not('trashed = ? OR role = ?', true, 'admin')
6538+
----

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.16.1'
7+
STRING = '2.17.0'
88

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

relnotes/v2.17.0.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
### New features
2+
3+
* [#547](https://github.com/rubocop/rubocop-rails/pull/547): Add new `Rails/ActionOrder` cop. ([@mollerhoj][])
4+
* [#565](https://github.com/rubocop/rubocop-rails/issues/565): Add cop Rails/WhereNotWithMultipleConditions. ([@niklas-hasselmeyer][])
5+
* [#771](https://github.com/rubocop/rubocop-rails/pull/771): Add new `Rails/IgnoredColumnsAssignment` cop. ([@fsateler][], [@kkitadate][])
6+
* [#790](https://github.com/rubocop/rubocop-rails/issues/790): Make `Style/HashExcept` aware of TargetRubyVersion: 2.x because Rails has `Hash#except`. ([@koic][])
7+
8+
### Bug fixes
9+
10+
* [#786](https://github.com/rubocop/rubocop-rails/issues/786): Fix a false negative for `Rails/ActionControllerTestCase` when extending `ActionController::TestCase` and having a method definition. ([@koic][])
11+
* [#792](https://github.com/rubocop/rubocop-rails/issues/792): Fix a false negative for `Rails/RedundantPresenceValidationOnBelongsTo` when belongs_to at least one block and one hash like `belongs_to :company, -> { where(foo: true) }, inverse_of: :employee`. ([@PedroAugustoRamalhoDuarte][])
12+
* [#781](https://github.com/rubocop/rubocop-rails/issues/781): Make `Rails/DynamicFindBy` aware of `find_by_token_for`. ([@koic][])
13+
* [#809](https://github.com/rubocop/rubocop-rails/issues/809): Fix an error for `Rails/FreezeTime` when using `travel_to` without argument. ([@koic][])
14+
* [#794](https://github.com/rubocop/rubocop-rails/issues/794): Fix an error for `Rails/RedundantReceiverInWithOptions` when calling a method with a receiver in `with_options` without block arguments. ([@koic][])
15+
* [#782](https://github.com/rubocop/rubocop-rails/issues/782): Fix an incorrect autocorrect for `Rails/EagerEvaluationLogMessage` when using `Style/MethodCallWithArgsParentheses`'s autocorrection together. ([@koic][])
16+
* [#776](https://github.com/rubocop/rubocop-rails/issues/776): Fix an incorrect autocorrect for `Rails/Presence` when using arithmetic operation in `else` branch. ([@koic][])
17+
* [#813](https://github.com/rubocop/rubocop-rails/pull/813): Fix errors that occur when unrelated `tag` is investigated by `Rails/ContentTag`. ([@r7kamura][])
18+
* [#808](https://github.com/rubocop/rubocop-rails/issues/808): Fix false positive for `Rails/ActionControllerFlashBeforeRender` when `render` call precedes `flash` call. ([@americodls][])
19+
* [#778](https://github.com/rubocop/rubocop-rails/issues/778): Fix a false positive for `Rails/DynamicFindBy` when using `page.find_by_id` as a Capybara testing API. ([@koic][])
20+
* [#816](https://github.com/rubocop/rubocop-rails/pull/816): Fix an incorrect autocorrect for `Rails/Presence` when a right-hand side of the relational operator. ([@ydah][])
21+
22+
### Changes
23+
24+
* [#779](https://github.com/rubocop/rubocop-rails/issues/779): Add `mail` to `AllowedMethods` of `Style/SymbolProc`. ([@koic][])
25+
* [#796](https://github.com/rubocop/rubocop-rails/issues/796): Add several directories to `Exclude` to prevent slow investigation. ([@koic][])
26+
* [#822](https://github.com/rubocop/rubocop-rails/issues/822): Extends `Rails/HttpStatus` cop to check `routes.rb`. ([@anthony-robin][])
27+
* [#787](https://github.com/rubocop/rubocop-rails/issues/787): Make `Rails/Pluck` aware of all keys. ([@koic][])
28+
* [#800](https://github.com/rubocop/rubocop-rails/issues/800): Make `Rails/TimeZone` aware of timezone UTF offset. ([@inkstak][])
29+
30+
[@mollerhoj]: https://github.com/mollerhoj
31+
[@niklas-hasselmeyer]: https://github.com/niklas-hasselmeyer
32+
[@fsateler]: https://github.com/fsateler
33+
[@kkitadate]: https://github.com/kkitadate
34+
[@koic]: https://github.com/koic
35+
[@PedroAugustoRamalhoDuarte]: https://github.com/PedroAugustoRamalhoDuarte
36+
[@r7kamura]: https://github.com/r7kamura
37+
[@americodls]: https://github.com/americodls
38+
[@ydah]: https://github.com/ydah
39+
[@anthony-robin]: https://github.com/anthony-robin
40+
[@inkstak]: https://github.com/inkstak

0 commit comments

Comments
 (0)