diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /rubocop/cop/migration | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'rubocop/cop/migration')
-rw-r--r-- | rubocop/cop/migration/add_concurrent_foreign_key.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/add_concurrent_index.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/add_index.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/add_limit_to_text_columns.rb | 31 | ||||
-rw-r--r-- | rubocop/cop/migration/add_timestamps.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/datetime.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/hash_index.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/remove_column.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/remove_concurrent_index.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/remove_index.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/safer_boolean_column.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/timestamps.rb | 2 | ||||
-rw-r--r-- | rubocop/cop/migration/update_column_in_batches.rb | 2 |
13 files changed, 47 insertions, 8 deletions
diff --git a/rubocop/cop/migration/add_concurrent_foreign_key.rb b/rubocop/cop/migration/add_concurrent_foreign_key.rb index 31cf426b2d4..957bd30af63 100644 --- a/rubocop/cop/migration/add_concurrent_foreign_key.rb +++ b/rubocop/cop/migration/add_concurrent_foreign_key.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/add_concurrent_index.rb b/rubocop/cop/migration/add_concurrent_index.rb index a2e4ac72565..510f98ce373 100644 --- a/rubocop/cop/migration/add_concurrent_index.rb +++ b/rubocop/cop/migration/add_concurrent_index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/add_index.rb b/rubocop/cop/migration/add_index.rb index 4aea3c0cce3..7415880e554 100644 --- a/rubocop/cop/migration/add_index.rb +++ b/rubocop/cop/migration/add_index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/add_limit_to_text_columns.rb b/rubocop/cop/migration/add_limit_to_text_columns.rb index b2e37ad5137..126e4e21f22 100644 --- a/rubocop/cop/migration/add_limit_to_text_columns.rb +++ b/rubocop/cop/migration/add_limit_to_text_columns.rb @@ -20,6 +20,10 @@ module RuboCop (def :down ...) PATTERN + def_node_matcher :set_text_limit?, <<~PATTERN + (send _ :text_limit ...) + PATTERN + def_node_matcher :add_text_limit?, <<~PATTERN (send _ :add_text_limit ...) PATTERN @@ -111,20 +115,31 @@ module RuboCop limit_found = false node.each_descendant(:send) do |send_node| - next unless add_text_limit?(send_node) - - limit_table = send_node.children[2].value - limit_attribute = send_node.children[3].value - - if limit_table == table_name && limit_attribute == attribute_name - limit_found = true - break + if set_text_limit?(send_node) + limit_found = matching_set_text_limit?(send_node, attribute_name) + elsif add_text_limit?(send_node) + limit_found = matching_add_text_limit?(send_node, table_name, attribute_name) end + + break if limit_found end !limit_found end + def matching_set_text_limit?(send_node, attribute_name) + limit_attribute = send_node.children[2].value + + limit_attribute == attribute_name + end + + def matching_add_text_limit?(send_node, table_name, attribute_name) + limit_table = send_node.children[2].value + limit_attribute = send_node.children[3].value + + limit_table == table_name && limit_attribute == attribute_name + end + def encrypted_attribute_name?(attribute_name) attribute_name.to_s.start_with?('encrypted_') end diff --git a/rubocop/cop/migration/add_timestamps.rb b/rubocop/cop/migration/add_timestamps.rb index ba32d6a9960..d16e8b1f45b 100644 --- a/rubocop/cop/migration/add_timestamps.rb +++ b/rubocop/cop/migration/add_timestamps.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/datetime.rb b/rubocop/cop/migration/datetime.rb index 5a6cdc74ca4..51e0c3e5a22 100644 --- a/rubocop/cop/migration/datetime.rb +++ b/rubocop/cop/migration/datetime.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/hash_index.rb b/rubocop/cop/migration/hash_index.rb index 3206b73bd3d..dba202ef0e3 100644 --- a/rubocop/cop/migration/hash_index.rb +++ b/rubocop/cop/migration/hash_index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require_relative '../../migration_helpers' diff --git a/rubocop/cop/migration/remove_column.rb b/rubocop/cop/migration/remove_column.rb index fffb4ab7fab..f63df71467c 100644 --- a/rubocop/cop/migration/remove_column.rb +++ b/rubocop/cop/migration/remove_column.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/remove_concurrent_index.rb b/rubocop/cop/migration/remove_concurrent_index.rb index 2328740cf36..8c2c6fb157e 100644 --- a/rubocop/cop/migration/remove_concurrent_index.rb +++ b/rubocop/cop/migration/remove_concurrent_index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/remove_index.rb b/rubocop/cop/migration/remove_index.rb index 4df3b1ba756..15c2f37b4b0 100644 --- a/rubocop/cop/migration/remove_index.rb +++ b/rubocop/cop/migration/remove_index.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/safer_boolean_column.rb b/rubocop/cop/migration/safer_boolean_column.rb index 22d5d37a83d..06bb24707bd 100644 --- a/rubocop/cop/migration/safer_boolean_column.rb +++ b/rubocop/cop/migration/safer_boolean_column.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/timestamps.rb b/rubocop/cop/migration/timestamps.rb index 6cf5648b996..5584d49ee8c 100644 --- a/rubocop/cop/migration/timestamps.rb +++ b/rubocop/cop/migration/timestamps.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop diff --git a/rubocop/cop/migration/update_column_in_batches.rb b/rubocop/cop/migration/update_column_in_batches.rb index b1c43393f6a..d23e0d28380 100644 --- a/rubocop/cop/migration/update_column_in_batches.rb +++ b/rubocop/cop/migration/update_column_in_batches.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../../migration_helpers' module RuboCop |