diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-02 00:10:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-02 00:10:21 +0300 |
commit | 5b8f2c8a24237cc5b2e2ba365b79e6293b93e459 (patch) | |
tree | 6ce5ce8932acbe93832fc0476f323e95bbb7dd8f /rubocop | |
parent | 304e230182b74eb84833c60b50618a5f0d7e2f9a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/migration/complex_indexes_require_name.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/rubocop/cop/migration/complex_indexes_require_name.rb b/rubocop/cop/migration/complex_indexes_require_name.rb index 173b327be12..82deb36716d 100644 --- a/rubocop/cop/migration/complex_indexes_require_name.rb +++ b/rubocop/cop/migration/complex_indexes_require_name.rb @@ -10,8 +10,12 @@ module RuboCop MSG = 'indexes added with custom options must be explicitly named' + def_node_matcher :match_create_table_index_with_options, <<~PATTERN + (send _ {:index } _ (hash $...)) + PATTERN + def_node_matcher :match_add_index_with_options, <<~PATTERN - (send _ {:add_concurrent_index} _ _ (hash $...)) + (send _ {:add_index :add_concurrent_index} _ _ (hash $...)) PATTERN def_node_matcher :name_option?, <<~PATTERN @@ -26,7 +30,7 @@ module RuboCop return unless in_migration?(node) node.each_descendant(:send) do |send_node| - next unless add_index_offense?(send_node) + next unless create_table_with_index_offense?(send_node) || add_index_offense?(send_node) add_offense(send_node, location: :selector) end @@ -34,6 +38,10 @@ module RuboCop private + def create_table_with_index_offense?(send_node) + match_create_table_index_with_options(send_node) { |option_nodes| needs_name_option?(option_nodes) } + end + def add_index_offense?(send_node) match_add_index_with_options(send_node) { |option_nodes| needs_name_option?(option_nodes) } end |