Skip to content

Commit 7cdce81

Browse files
bquorningkoic
authored andcommitted
Revert "In Rails >= 5, use optional: true, not required: false (#6596)"
This reverts commit a5105d8.
1 parent c394abf commit 7cdce81

File tree

4 files changed

+0
-187
lines changed

4 files changed

+0
-187
lines changed

lib/rubocop/cop/rails/belongs_to.rb

Lines changed: 0 additions & 101 deletions
This file was deleted.

lib/rubocop/cop/rails_cops.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Cop
1414
require_relative 'rails/application_job'
1515
require_relative 'rails/application_record'
1616
require_relative 'rails/assert_not'
17-
require_relative 'rails/belongs_to'
1817
require_relative 'rails/blank'
1918
require_relative 'rails/bulk_change_table'
2019
require_relative 'rails/create_table_with_timestamps'

manual/cops_rails.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -162,49 +162,6 @@ Name | Default value | Configurable values
162162
--- | --- | ---
163163
Include | `**/test/**/*` | Array
164164

165-
## Rails/BelongsTo
166-
167-
Enabled by default | Supports autocorrection
168-
--- | ---
169-
Enabled | Yes
170-
171-
This cop looks for belongs_to associations where we control whether the
172-
association is required via the deprecated `required` option instead.
173-
174-
Since Rails 5, belongs_to associations are required by default and this
175-
can be controlled through the use of `optional: true`.
176-
177-
From the release notes:
178-
179-
belongs_to will now trigger a validation error by default if the
180-
association is not present. You can turn this off on a
181-
per-association basis with optional: true. Also deprecate required
182-
option in favor of optional for belongs_to. (Pull Request)
183-
184-
In the case that the developer is doing `required: false`, we
185-
definitely want to autocorrect to `optional: true`.
186-
187-
However, without knowing whether they've set overriden the default
188-
value of `config.active_record.belongs_to_required_by_default`, we
189-
can't say whether it's safe to remove `required: true` or replace it
190-
with `optional: false` (or, similarly, remove a superfluous `optional:
191-
false`). Therefore, in the cases we're using `required: true`, we'll
192-
highlight that `required` is deprecated but otherwise do nothing.
193-
194-
### Examples
195-
196-
```ruby
197-
# bad
198-
class Post < ApplicationRecord
199-
belongs_to :blog, required: false
200-
end
201-
202-
# good
203-
class Post < ApplicationRecord
204-
belongs_to :blog, optional: true
205-
end
206-
```
207-
208165
## Rails/Blank
209166

210167
Enabled by default | Supports autocorrection

spec/rubocop/cop/rails/belongs_to_spec.rb

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)