diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 00:14:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 00:14:40 +0300 |
commit | 0c8b3354d966bf689a11736b80460fa5806b4495 (patch) | |
tree | 31259c03d4875aca416f422c912cc9b4d8a291a1 /rubocop | |
parent | ae845b62778b7c82aae1828b5f237e0468993ef8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/graphql/graphql_name_position.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/graphql_name_position.rb b/rubocop/cop/graphql/graphql_name_position.rb new file mode 100644 index 00000000000..f18d65588cc --- /dev/null +++ b/rubocop/cop/graphql/graphql_name_position.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# This cop ensures that if a class uses `graphql_name`, then +# it's the first line of the class +# +# @example +# +# # bad +# class AwfulClass +# field :some_field, GraphQL::Types::JSON +# graphql_name 'AwfulClass' +# end +# +# # good +# class GreatClass +# graphql_name 'AwfulClass' +# field :some_field, GraphQL::Types::String +# end + +module RuboCop + module Cop + module Graphql + class GraphqlNamePosition < RuboCop::Cop::Cop + MSG = '`graphql_name` should be the first line of the class: '\ + 'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#naming-conventions' + + def_node_search :graphql_name?, <<~PATTERN + (send nil? :graphql_name ...) + PATTERN + + def on_class(node) + return unless graphql_name?(node) + return if node.body.single_line? + + add_offense(node, location: :expression) unless graphql_name?(node.body.children.first) + end + end + end + end +end |