From bf2712fda6d32576a1b48a12276bd5972f31eb23 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 20 Aug 2021 20:01:57 +0900 Subject: [PATCH] Use `RESTRICT_ON_SEND` Follow https://github.com/rubocop-hq/rubocop/pull/8365 This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only. --- lib/rubocop/cop/sequel/column_default.rb | 1 + lib/rubocop/cop/sequel/concurrent_index.rb | 1 + lib/rubocop/cop/sequel/json_column.rb | 1 + lib/rubocop/cop/sequel/partial_constraint.rb | 1 + lib/rubocop/cop/sequel/save_changes.rb | 1 + 5 files changed, 5 insertions(+) diff --git a/lib/rubocop/cop/sequel/column_default.rb b/lib/rubocop/cop/sequel/column_default.rb index bd066ad..e2b9246 100644 --- a/lib/rubocop/cop/sequel/column_default.rb +++ b/lib/rubocop/cop/sequel/column_default.rb @@ -6,6 +6,7 @@ module Sequel # ColumnDefault looks for column creation with a default value. class ColumnDefault < Base MSG = "Don't create new column with default values" + RESTRICT_ON_SEND = %i[add_column].freeze def_node_matcher :add_column_default?, <<-MATCHER (send _ :add_column ... (hash (pair (sym :default) _))) diff --git a/lib/rubocop/cop/sequel/concurrent_index.rb b/lib/rubocop/cop/sequel/concurrent_index.rb index 68d5816..20ecf34 100644 --- a/lib/rubocop/cop/sequel/concurrent_index.rb +++ b/lib/rubocop/cop/sequel/concurrent_index.rb @@ -6,6 +6,7 @@ module Sequel # ConcurrentIndex looks for non-concurrent index creation. class ConcurrentIndex < Base MSG = 'Prefer creating or dropping new index concurrently' + RESTRICT_ON_SEND = %i[add_index drop_index].freeze def_node_matcher :indexes?, <<-MATCHER (send _ {:add_index :drop_index} $...) diff --git a/lib/rubocop/cop/sequel/json_column.rb b/lib/rubocop/cop/sequel/json_column.rb index 2f3b279..2e98b38 100644 --- a/lib/rubocop/cop/sequel/json_column.rb +++ b/lib/rubocop/cop/sequel/json_column.rb @@ -6,6 +6,7 @@ module Sequel # JSONColumn looks for non-JSONB columns. class JSONColumn < Base MSG = 'Use JSONB rather than JSON or hstore' + RESTRICT_ON_SEND = %i[add_column].freeze def_node_matcher :json_or_hstore?, <<-MATCHER (send _ :add_column ... (sym {:json :hstore})) diff --git a/lib/rubocop/cop/sequel/partial_constraint.rb b/lib/rubocop/cop/sequel/partial_constraint.rb index 0a0215d..baf3ab4 100644 --- a/lib/rubocop/cop/sequel/partial_constraint.rb +++ b/lib/rubocop/cop/sequel/partial_constraint.rb @@ -6,6 +6,7 @@ module Sequel # PartialConstraint looks for missed usage of partial indexes. class PartialConstraint < Base MSG = "Constraint can't be partial, use where argument with index" + RESTRICT_ON_SEND = %i[add_unique_constraint].freeze def_node_matcher :add_partial_constraint?, <<-MATCHER (send _ :add_unique_constraint ... (hash (pair (sym :where) _))) diff --git a/lib/rubocop/cop/sequel/save_changes.rb b/lib/rubocop/cop/sequel/save_changes.rb index 153ae43..fb8ff2e 100644 --- a/lib/rubocop/cop/sequel/save_changes.rb +++ b/lib/rubocop/cop/sequel/save_changes.rb @@ -9,6 +9,7 @@ class SaveChanges < Base MSG = 'Use `Sequel::Model#save_changes` instead of '\ '`Sequel::Model#save`.' + RESTRICT_ON_SEND = %i[save].freeze def_node_matcher :model_save?, <<-MATCHER (send _ :save)