Skip to content

Commit

Permalink
Mark Rails/ApplicationController and similar cops as unsafe autocor…
Browse files Browse the repository at this point in the history
…rect

We have a controller class which inherits `ActionController::Base` directly.
That controller is for health check endpoint.

```ruby
class HealthCheckController < ActionController::Base
  # we want to skip some authentication logics...
  def index
    head :ok
  end
end
```

```ruby
class ApplicationController < ActionController::Base
  # default some authentication logics...
end
```

In such case, automatically modifying the `ActionController :: Base`->` ApplicationController` is not safe .
  • Loading branch information
hoshinotsuyoshi committed Apr 1, 2020
1 parent ad4e97d commit a1aa7d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* [#214](https://github.com/rubocop-hq/rubocop-rails/issues/214): Fix an error for `Rails/UniqueValidationWithoutIndex`when a table has no column definition. ([@koic][])
* [#221](https://github.com/rubocop-hq/rubocop-rails/issues/221): Make `Rails/UniqueValidationWithoutIndex` aware of `add_index` in db/schema.rb. ([@koic][])

### Changes

* [#223](https://github.com/rubocop-hq/rubocop-rails/pull/223): Mark `Rails/ApplicationController`, `Rails/ApplicationJob`, `Rails/ApplicationMailer`, and `Rails/ApplicationRecord` as unsafe autocorrect. ([@hoshinotsuyoshi][])

## 2.5.0 (2020-03-24)

### New features
Expand Down Expand Up @@ -157,3 +161,4 @@
[@joshpencheon]: https://github.com/joshpencheon
[@djudd]: https://github.com/djudd
[@sunny]: https://github.com/sunny
[@hoshinotsuyoshi]: https://github.com/hoshinotsuyoshi
8 changes: 8 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,30 @@ Rails/ActiveSupportAliases:
Rails/ApplicationController:
Description: 'Check that controllers subclass ApplicationController.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '2.4'
VersionChanged: '2.5'

Rails/ApplicationJob:
Description: 'Check that jobs subclass ApplicationJob.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.49'
VersionChanged: '2.5'

Rails/ApplicationMailer:
Description: 'Check that mailers subclass ApplicationMailer.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '2.4'
VersionChanged: '2.5'

Rails/ApplicationRecord:
Description: 'Check that models subclass ApplicationRecord.'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.49'
VersionChanged: '2.5'

Rails/AssertNot:
Description: 'Use `assert_not` instead of `assert !`.'
Expand Down
8 changes: 4 additions & 4 deletions manual/cops_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ are not used.

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 2.4 | -
Enabled | Yes | Yes (Unsafe) | 2.4 | 2.5

This cop checks that controllers subclass ApplicationController.

Expand All @@ -153,7 +153,7 @@ end

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.49 | -
Enabled | Yes | Yes (Unsafe) | 0.49 | 2.5

This cop checks that jobs subclass ApplicationJob with Rails 5.0.

Expand All @@ -175,7 +175,7 @@ end

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 2.4 | -
Enabled | Yes | Yes (Unsafe) | 2.4 | 2.5

This cop checks that mailers subclass ApplicationMailer with Rails 5.0.

Expand All @@ -197,7 +197,7 @@ end

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.49 | -
Enabled | Yes | Yes (Unsafe) | 0.49 | 2.5

This cop checks that models subclass ApplicationRecord with Rails 5.0.

Expand Down

0 comments on commit a1aa7d5

Please sign in to comment.