Skip to content

Commit

Permalink
Merge branch 'rubocop:master' into generator-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaier committed Apr 12, 2023
2 parents cc07f6a + 73fd423 commit 54dce62
Show file tree
Hide file tree
Showing 27 changed files with 206 additions and 2,903 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@

## master (unreleased)

## 2.19.0 (2023-04-07)

### New features

* [#337](https://github.com/rubocop/rubocop-rails/issues/337): Add new `Rails/ThreeStateBooleanColumn` cop. ([@fatkodima][])
* [#45](https://github.com/rubocop/rubocop-rails/issues/45): Make `Rails/Delegate` aware of `self`. ([@koic][])

### Bug fixes

* [#934](https://github.com/rubocop/rubocop-rails/issues/934): Fix a false negative for `Rails/Output` when print methods without arguments. ([@koic][])
* [#99](https://github.com/rubocop/rubocop-rails/issues/99): Fix a false positive for `Rails/HttpPositionalArguments` when using `include Rack::Test::Methods`. ([@koic][])
* [#501](https://github.com/rubocop/rubocop-rails/issues/501): Fix a false positive for `Rails/OutputSafety` when using `html_safe` for `I18n` methods. ([@koic][])
* [#860](https://github.com/rubocop/rubocop-rails/issues/860): Fix a false positive for `Rails/Pluck` when using regexp literal key for `String#[]`. ([@koic][])
* [#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][])
* [#941](https://github.com/rubocop/rubocop-rails/issues/941): Remove redundant config for `Style/InverseMethods`. ([@koic][])

### Changes

* [#299](https://github.com/rubocop/rubocop-rails/pull/299): Add autocorrection for `Rails/ReflectionClassName`. ([@tejasbubane][])
* [#34](https://github.com/rubocop/rubocop-rails/issues/34): Allow `CreateTableWithTimestamps` when using `id: false` and not include `timestamps`. ([@koic][])
* [#694](https://github.com/rubocop/rubocop-rails/issues/694): Mark `Rails/FindEach` as unsafe. ([@koic][])
* [#940](https://github.com/rubocop/rubocop-rails/issues/940): Mark `Rails/ResponseParsedBody` as unsafe. ([@koic][])

## 2.18.0 (2023-02-25)

### New features
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem 'bump', require: false
gem 'rake'
gem 'rspec'
gem 'rubocop', github: 'rubocop/rubocop'
gem 'rubocop-performance', '~> 1.15.0'
gem 'rubocop-performance', '~> 1.17.0'
gem 'rubocop-rspec', '~> 2.18.0'
gem 'simplecov'
gem 'test-queue'
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/change_mark_rails_find_each_as_unsafe.md

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/fix_a_false_negative_for_rails_output.md

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/fix_a_false_positive_for_rails_pluck.md

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/new_add_three_state_boolean_column_cop.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/new_make_rails_delegate_aware_of_self.md

This file was deleted.

6 changes: 3 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ Rails/FindEach:
Enabled: true
Safe: false
VersionAdded: '0.30'
VersionChanged: '<<next>>'
VersionChanged: '2.19'
Include:
- app/models/**/*.rb
AllowedMethods:
Expand Down Expand Up @@ -845,7 +845,7 @@ Rails/ResponseParsedBody:
Enabled: pending
Safe: false
VersionAdded: '2.18'
VersionChanged: '<<next>>'
VersionChanged: '2.19'
Include:
- spec/controllers/**/*.rb
- spec/requests/**/*.rb
Expand Down Expand Up @@ -1001,7 +1001,7 @@ Rails/ThreeStateBooleanColumn:
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
StyleGuide: 'https://rails.rubystyle.guide/#three-state-boolean'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '2.19'
Include:
- db/**/*.rb

Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railssquishedsqlheredocs[Rails/SquishedSQLHeredocs]
* xref:cops_rails.adoc#railsstripheredoc[Rails/StripHeredoc]
* xref:cops_rails.adoc#railstablenameassignment[Rails/TableNameAssignment]
* xref:cops_rails.adoc#railsthreestatebooleancolumn[Rails/ThreeStateBooleanColumn]
* xref:cops_rails.adoc#railstimezone[Rails/TimeZone]
* xref:cops_rails.adoc#railstimezoneassignment[Rails/TimeZoneAssignment]
* xref:cops_rails.adoc#railstoformatteds[Rails/ToFormattedS]
Expand Down
120 changes: 96 additions & 24 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class HomeController < ApplicationController
end
----

=== References

* https://rails.rubystyle.guide/#flash-before-render
* https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html

== Rails/ActionControllerTestCase

|===
Expand Down Expand Up @@ -1163,10 +1158,12 @@ tag(name, class: 'classname')
| -
|===

Checks the migration for which timestamps are not included
when creating a new table.
Checks the migration for which timestamps are not included when creating a new table.
In many cases, timestamps are useful information and should be added.

NOTE: Allow `timestamps` not written when `id: false` because this emphasizes respecting
user's editing intentions.

=== Examples

[source,ruby]
Expand Down Expand Up @@ -1203,6 +1200,12 @@ create_table :users do |t|
t.datetime :updated_at, default: -> { 'CURRENT_TIMESTAMP' }
end
# good
create_table :users, articles, id: false do |t|
t.integer :user_id
t.integer :article_id
end
----

=== Configurable attributes
Expand Down Expand Up @@ -1386,6 +1389,14 @@ end
# good
delegate :bar, to: :foo
# bad
def bar
self.bar
end
# good
delegate :bar, to: :self
# good
def bar
foo&.bar
Expand Down Expand Up @@ -2088,9 +2099,8 @@ date.all_year
| 2.4
|===

Identifies usages of file path joining process
to use `Rails.root.join` clause. It is used to add uniformity when
joining paths.
Identifies usages of file path joining process to use `Rails.root.join` clause.
It is used to add uniformity when joining paths.

=== Examples

Expand All @@ -2100,11 +2110,16 @@ joining paths.
----
# bad
Rails.root.join('app', 'models', 'goober')
# good
Rails.root.join('app/models/goober')
# bad
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app/models/goober')
Rails.root.join('app/models/goober').to_s
----

==== EnforcedStyle: arguments
Expand All @@ -2113,11 +2128,16 @@ Rails.root.join('app/models/goober')
----
# bad
Rails.root.join('app/models/goober')
# good
Rails.root.join('app', 'models', 'goober')
# bad
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app', 'models', 'goober')
Rails.root.join('app', 'models', 'goober').to_s
----

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

| Enabled
| Yes
| Yes
| No
| Yes (Unsafe)
| 0.30
| 2.9
| 2.19
|===

Identifies usages of `all.each` and
change them to use `all.find_each` instead.
Identifies usages of `all.each` and change them to use `all.find_each` instead.

=== Safety

This cop is unsafe if the receiver object is not an Active Record object.
Also, `all.each` returns an `Array` instance and `all.find_each` returns nil,
so the return values are different.

=== Examples

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

NOTE: It does not detect any cases where `include Rack::Test::Methods` is used
which makes the http methods incompatible behavior.

=== Examples

[source,ruby]
Expand Down Expand Up @@ -4450,7 +4478,7 @@ end

| Enabled
| No
| No
| Yes (Unsafe)
| 0.64
| 2.10
|===
Expand Down Expand Up @@ -4770,19 +4798,19 @@ require_dependency 'some_lib'
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

| Pending
| Yes
| No
| Yes (Unsafe)
| 2.18
| -
| 2.19
|===

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

=== Safety

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

=== Examples

Expand Down Expand Up @@ -5801,6 +5829,50 @@ self.table_name = :some_other_name

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

== Rails/ThreeStateBooleanColumn

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

| Pending
| Yes
| No
| 2.19
| -
|===

Enforces that boolean columns are created with default values (`false` or `true`) and
`NOT NULL` constraint.

=== Examples

[source,ruby]
----
# bad
add_column :users, :active, :boolean
t.column :active, :boolean
t.boolean :active
# good
add_column :users, :active, :boolean, default: true, null: false
t.column :active, :boolean, default: true, null: false
t.boolean :active, default: true, null: false
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `+db/**/*.rb+`
| Array
|===

=== References

* https://rails.rubystyle.guide/#three-state-boolean

== Rails/TimeZone

|===
Expand Down Expand Up @@ -6200,7 +6272,7 @@ customer.favourites.distinct.pluck(:color)
|===

When you define a uniqueness validation in Active Record model,
you also should add a unique index for the column. There are two reasons
you also should add a unique index for the column. There are two reasons.
First, duplicated records may occur even if Active Record's validation
is defined.
Second, it will cause slow queries. The validation executes a `SELECT`
Expand Down
67 changes: 0 additions & 67 deletions legacy-docs/cops.md

This file was deleted.

0 comments on commit 54dce62

Please sign in to comment.