From ff0759314dcb41009b96919d45ed12217a8d63ca Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 3 Sep 2024 19:05:58 +0300 Subject: [PATCH] Change `Rails/ApplicationRecord` to ignore migrations --- changelog/change_application_record_to_ignore_migrations.md | 1 + config/default.yml | 4 +++- lib/rubocop/cop/rails/application_record.rb | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/change_application_record_to_ignore_migrations.md diff --git a/changelog/change_application_record_to_ignore_migrations.md b/changelog/change_application_record_to_ignore_migrations.md new file mode 100644 index 0000000000..59f8e2259d --- /dev/null +++ b/changelog/change_application_record_to_ignore_migrations.md @@ -0,0 +1 @@ +* [#1342](https://github.com/rubocop/rubocop-rails/issues/1342): Change `Rails/ApplicationRecord` to ignore migrations. ([@fatkodima][]) diff --git a/config/default.yml b/config/default.yml index 97b01498b0..74a0251182 100644 --- a/config/default.yml +++ b/config/default.yml @@ -212,7 +212,9 @@ Rails/ApplicationRecord: Enabled: true SafeAutoCorrect: false VersionAdded: '0.49' - VersionChanged: '2.5' + VersionChanged: '<>' + Exclude: + - db/**/*.rb Rails/ArelStar: Description: 'Enforces `Arel.star` instead of `"*"` for expanded columns.' diff --git a/lib/rubocop/cop/rails/application_record.rb b/lib/rubocop/cop/rails/application_record.rb index 91ee5e2aaf..f5f40bcdc2 100644 --- a/lib/rubocop/cop/rails/application_record.rb +++ b/lib/rubocop/cop/rails/application_record.rb @@ -5,6 +5,10 @@ module Cop module Rails # Checks that models subclass `ApplicationRecord` with Rails 5.0. # + # It is a common practice to define models inside migrations in order to retain forward + # compatibility by avoiding loading any application code. And so migration files are excluded + # by default for this cop. + # # @safety # This cop's autocorrection is unsafe because it may let the logic from `ApplicationRecord` # sneak into an Active Record model that is not purposed to inherit logic common among other