summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /rubocop
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/graphql/authorize_types.rb5
-rw-r--r--rubocop/cop/graphql/descriptions.rb52
-rw-r--r--rubocop/cop/migration/add_columns_to_wide_tables.rb4
-rw-r--r--rubocop/cop/migration/with_lock_retries_disallowed_method.rb1
-rw-r--r--rubocop/rubocop-migrations.yml1
-rw-r--r--rubocop/rubocop-usage-data.yml2
6 files changed, 48 insertions, 17 deletions
diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb
index 1dba719cdff..9bfd93aa3db 100644
--- a/rubocop/cop/graphql/authorize_types.rb
+++ b/rubocop/cop/graphql/authorize_types.rb
@@ -9,7 +9,7 @@ module RuboCop
# We want to exclude our own basetypes and scalars
ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
- QueryType GraphQL::Schema BaseUnion].freeze
+ QueryType GraphQL::Schema BaseUnion BaseInputObject].freeze
def_node_search :authorize?, <<~PATTERN
(send nil? :authorize ...)
@@ -29,8 +29,9 @@ module RuboCop
return false unless class_const
return true if class_const.end_with?('Enum')
+ return true if class_const.end_with?('InputType')
- ALLOWED_TYPES.any? { |allowed| class_node.const_name.include?(allowed) }
+ ALLOWED_TYPES.any? { |allowed| class_const.include?(allowed) }
end
def class_constant(node)
diff --git a/rubocop/cop/graphql/descriptions.rb b/rubocop/cop/graphql/descriptions.rb
index 1585e5c9788..ec233c65874 100644
--- a/rubocop/cop/graphql/descriptions.rb
+++ b/rubocop/cop/graphql/descriptions.rb
@@ -1,26 +1,31 @@
# frozen_string_literal: true
-# This cop checks for missing GraphQL field descriptions.
+# This cop checks for missing GraphQL descriptions and enforces the description style guide:
+# https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#description-style-guide
#
-# @example
+# @examples
#
# # bad
-# class AwfulClass
+# class AwfulType
# field :some_field, GraphQL::STRING_TYPE
# end
#
-# class TerribleClass
+# class TerribleType
# argument :some_argument, GraphQL::STRING_TYPE
# end
#
-# class UngoodClass
+# class UngoodType
# field :some_argument,
# GraphQL::STRING_TYPE,
# description: "A description that does not end in a period"
# end
#
+# class BadEnum
+# value "some_value"
+# end
+#
# # good
-# class GreatClass
+# class GreatType
# argument :some_field,
# GraphQL::STRING_TYPE,
# description: "Well described - a superb description."
@@ -29,6 +34,10 @@
# GraphQL::STRING_TYPE,
# description: "A thorough and compelling description."
# end
+#
+# class GoodEnum
+# value "some_value", "Good description."
+# end
module RuboCop
module Cop
@@ -37,19 +46,26 @@ module RuboCop
MSG_NO_DESCRIPTION = 'Please add a `description` property.'
MSG_NO_PERIOD = '`description` strings must end with a `.`.'
- # ability_field and permission_field set a default description.
- def_node_matcher :field_or_argument?, <<~PATTERN
- (send nil? {:field :argument} ...)
+ def_node_matcher :graphql_describable?, <<~PATTERN
+ (send nil? {:field :argument :value} ...)
+ PATTERN
+
+ def_node_matcher :enum?, <<~PATTERN
+ (send nil? :value ...)
PATTERN
- def_node_matcher :description, <<~PATTERN
+ def_node_matcher :description_kwarg, <<~PATTERN
(... (hash <(pair (sym :description) $_) ...>))
PATTERN
+ def_node_matcher :enum_style_description, <<~PATTERN
+ (send nil? :value _ $str ...)
+ PATTERN
+
def on_send(node)
- return unless field_or_argument?(node)
+ return unless graphql_describable?(node)
- description = description(node)
+ description = locate_description(node)
return add_offense(node, location: :expression, message: MSG_NO_DESCRIPTION) unless description
@@ -59,7 +75,7 @@ module RuboCop
# Autocorrect missing periods at end of description.
def autocorrect(node)
lambda do |corrector|
- description = description(node)
+ description = locate_description(node)
next unless description
corrector.insert_after(before_end_quote(description), '.')
@@ -68,6 +84,16 @@ module RuboCop
private
+ # Fields and arguments define descriptions using a `description` keyword argument.
+ # Enums may define descriptions this way, or as a second `String` param.
+ def locate_description(node)
+ description = description_kwarg(node)
+
+ return description unless description.nil? && enum?(node)
+
+ enum_style_description(node)
+ end
+
def no_period?(description)
# Test that the description node is a `:str` (as opposed to
# a `#copy_field_description` call) before checking.
diff --git a/rubocop/cop/migration/add_columns_to_wide_tables.rb b/rubocop/cop/migration/add_columns_to_wide_tables.rb
index 2880783dc3e..41056379515 100644
--- a/rubocop/cop/migration/add_columns_to_wide_tables.rb
+++ b/rubocop/cop/migration/add_columns_to_wide_tables.rb
@@ -9,8 +9,8 @@ module RuboCop
class AddColumnsToWideTables < RuboCop::Cop::Cop
include MigrationHelpers
- MSG = '`%s` is a wide table with several columns, addig more should be avoided unless absolutely necessary.' \
- ' Consider storing the column in a different table or creating a new one.'.freeze
+ MSG = '`%s` is a wide table with several columns, adding more should be avoided unless absolutely necessary.' \
+ ' Consider storing the column in a different table or creating a new one.'
BLACKLISTED_METHODS = %i[
add_column
diff --git a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
index aef19517a9d..f423bde8343 100644
--- a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
+++ b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
@@ -21,6 +21,7 @@ module RuboCop
change_column_null
remove_foreign_key_if_exists
remove_foreign_key_without_error
+ rename_index
table_exists?
index_exists_by_name?
foreign_key_exists?
diff --git a/rubocop/rubocop-migrations.yml b/rubocop/rubocop-migrations.yml
index 45f8270b34d..c1ad3cc8abb 100644
--- a/rubocop/rubocop-migrations.yml
+++ b/rubocop/rubocop-migrations.yml
@@ -27,6 +27,7 @@ Migration/UpdateLargeTable:
- :project_ci_cd_settings
- :project_settings
- :project_features
+ - :protected_branches
- :push_event_payloads
- :resource_label_events
- :routes
diff --git a/rubocop/rubocop-usage-data.yml b/rubocop/rubocop-usage-data.yml
index bbc4d590ddc..a03f21e491a 100644
--- a/rubocop/rubocop-usage-data.yml
+++ b/rubocop/rubocop-usage-data.yml
@@ -30,9 +30,11 @@ UsageData/LargeTable:
- :Settings
- :CE_MEMOIZED_VALUES
- :EE_MEMOIZED_VALUES
+ - :Ohai::System
CountMethods:
- :count
- :distinct_count
+ - :histogram
AllowedMethods:
- :arel_table
- :minimum