Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow object description to be a constant. #52

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rubocop/graphql/description_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module DescriptionMethod
extend RuboCop::NodePattern::Macros

def_node_matcher :description_kwarg?, <<~PATTERN
(send nil? :description {({str|dstr} ...)|(send ({str|dstr} ...) _)})
(send nil? :description
{({str|dstr|const} ...)|(send const ...)|(send ({str|dstr} ...) _)})
PATTERN

def find_description_method(nodes)
Expand Down
162 changes: 162 additions & 0 deletions spec/rubocop/cop/graphql/object_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ class Types::UserType < Types::BaseObject
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::UserType < Types::BaseObject
description USER_TYPE_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::UserType < Types::BaseObject
description DESCRIPTION[:user_type]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -95,6 +115,26 @@ class Mutations::User::Create < Mutations::BaseMutation
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Mutations::User::Create < Mutations::BaseMutation
description USER_CREATE_MUTATION_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Mutations::User::Create < Mutations::BaseMutation
description DESCRIPTION[:user_create_mutation]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -140,6 +180,26 @@ class Subscriptions::MessageWasPosted < Subscriptions::BaseSubscription
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Subscriptions::MessageWasPosted < Subscriptions::BaseSubscription
description MESSAGE_WAS_POSTED_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Subscriptions::MessageWasPosted < Subscriptions::BaseSubscription
description DESCRIPTION[:message_was_posted]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -185,6 +245,26 @@ class Resolvers::User < Resolvers::Base
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Resolvers::User < Resolvers::Base
description USER_RESOLVER_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Resolvers::User < Resolvers::Base
description DESCRIPTION[:user_resolver]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -230,6 +310,26 @@ class Types::User::CreateInput < Types::BaseInputObject
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::User::CreateInput < Types::BaseInputObject
description USER_CREATE_INPUT_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::User::CreateInput < Types::BaseInputObject
description DESCRIPTION[:user_create_input]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -278,6 +378,28 @@ module Types::NodeInterface
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
module Types::NodeInterface
include Types::BaseInterface
description NODE_INTERFACE_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
module Types::NodeInterface
include Types::BaseInterface
description DESCRIPTION[:base_interface]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -324,6 +446,26 @@ class Types::Money < Types::BaseScalar
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::Money < Types::BaseScalar
description MONEY_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::Money < Types::BaseScalar
description DESCRIPTION[:money]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down Expand Up @@ -369,6 +511,26 @@ class Types::Money < Types::BaseScalar
RUBY
end
end

context "when description is a constant" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::CommentSubject < Types::BaseUnion
description COMMENT_SUBJECT_DESCRIPTION
end
RUBY
end
end

context "when description is a constant hash" do
it "does not register an offense" do
expect_no_offenses(<<~RUBY)
class Types::CommentSubject < Types::BaseUnion
description DESCRIPTION[:comment_subject]
end
RUBY
end
end
end

context "when description is not filled" do
Expand Down