From ff18270898308fc3d03daec0d0152b679b1b2e37 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 21 Aug 2023 10:04:29 +1000 Subject: [PATCH] Allow has_and_belongs_to_many to reduce code The Rails/HasAndBelongsToMany rule wants model classes for all many-to-many relationship tables in the database. But our team thinks that it's useful to declare has_and_belongs_to_many relationships which don't require an additional model. --- .rubocop_styleguide.yml | 7 +++++++ .rubocop_todo.yml | 13 ------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml index 11f6917250..a6a2fab4f4 100644 --- a/.rubocop_styleguide.yml +++ b/.rubocop_styleguide.yml @@ -53,6 +53,13 @@ Rails/ApplicationRecord: # Migrations should not contain application code: - "db/migrate/*.rb" +# Allow many-to-many associations without explicit model. +# - It avoids the additional code of a model class. +# - It simplifies the declaration of the association. +# - Rails may know that there are no callbacks associated. +Rails/HasAndBelongsToMany: + Enabled: false + Rails/SkipsModelValidations: AllowedMethods: - "touch" diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a88db9bfe..82ffedee69 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -419,19 +419,6 @@ Rails/ActiveRecordOverride: Exclude: - 'app/models/spree/product.rb' -# Offense count: 8 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/HasAndBelongsToMany: - Exclude: - - 'app/models/enterprise.rb' - - 'app/models/enterprise_group.rb' - - 'app/models/order_cycle.rb' - - 'app/models/spree/role.rb' - - 'app/models/spree/shipping_method.rb' - - 'app/models/spree/user.rb' - - 'app/models/spree/zone.rb' - # Offense count: 47 # Configuration parameters: Include. # Include: app/models/**/*.rb