From a1aa7d5036e4af9986e5eea878d93bfe58d2b17d Mon Sep 17 00:00:00 2001 From: hoshinotsuyoshi Date: Sat, 28 Mar 2020 17:58:34 +0900 Subject: [PATCH] Mark `Rails/ApplicationController` and similar cops as unsafe autocorrect 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 . --- CHANGELOG.md | 5 +++++ config/default.yml | 8 ++++++++ manual/cops_rails.md | 8 ++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5632f2b7d3..60faeb9bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -157,3 +161,4 @@ [@joshpencheon]: https://github.com/joshpencheon [@djudd]: https://github.com/djudd [@sunny]: https://github.com/sunny +[@hoshinotsuyoshi]: https://github.com/hoshinotsuyoshi diff --git a/config/default.yml b/config/default.yml index f6817e69b9..b45f085e19 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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 !`.' diff --git a/manual/cops_rails.md b/manual/cops_rails.md index ede7d1995e..aa30fafc0d 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -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. @@ -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. @@ -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. @@ -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.