Skip to content

Commit

Permalink
Use RESTRICT_ON_SEND
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.52/development.html#implementation

`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90, so it bumps the required lowest runtime
RuboCop dependency from 0.87 to 0.90. No runtime Ruby version incompatibilities between 0.87 and 0.90:
https://docs.rubocop.org/rubocop/1.52/compatibility.html
  • Loading branch information
koic committed Jun 22, 2023
1 parent 238fcb5 commit e9fc652
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rspec.yml
Expand Up @@ -20,8 +20,7 @@ jobs:
matrix:
ruby: ["3.0", 3.1, 3.2]
gemfile: [
"gemfiles/rubocop_0.87.0.gemfile",
"gemfiles/rubocop_0.89.0.gemfile",
"gemfiles/rubocop_0.90.0.gemfile",
"gemfiles/rubocop_1.0.gemfile",
"gemfiles/rubocop_edge.gemfile"
]
Expand Down
5 changes: 0 additions & 5 deletions gemfiles/rubocop_0.89.0.gemfile

This file was deleted.

@@ -1,5 +1,5 @@
source "https://rubygems.org"

gem "rubocop", "0.87.0"
gem "rubocop", "0.90.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/argument_description.rb
Expand Up @@ -22,6 +22,7 @@ class ArgumentDescription < Base
include RuboCop::GraphQL::NodePattern

MSG = "Missing argument description"
RESTRICT_ON_SEND = %i[argument].freeze

def on_send(node)
return unless argument?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/argument_name.rb
Expand Up @@ -20,6 +20,7 @@ module GraphQL
#
class ArgumentName < Base
include RuboCop::GraphQL::NodePattern
RESTRICT_ON_SEND = %i[argument].freeze

using RuboCop::GraphQL::Ext::SnakeCase

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/graphql/field_definitions.rb
Expand Up @@ -52,6 +52,8 @@ class FieldDefinitions < Base # rubocop:disable Metrics/ClassLength
include RuboCop::GraphQL::Sorbet
include RuboCop::GraphQL::Heredoc

RESTRICT_ON_SEND = %i[field].freeze

# @!method field_kwargs(node)
def_node_matcher :field_kwargs, <<~PATTERN
(send nil? :field
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/field_description.rb
Expand Up @@ -22,6 +22,7 @@ class FieldDescription < Base
include RuboCop::GraphQL::NodePattern

MSG = "Missing field description"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/field_hash_key.rb
Expand Up @@ -41,6 +41,7 @@ class FieldHashKey < Base
PATTERN

MSG = "Use hash_key: %<hash_key>p"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/field_method.rb
Expand Up @@ -40,6 +40,7 @@ class FieldMethod < Base
PATTERN

MSG = "Use method: :%<method_name>s"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/field_name.rb
Expand Up @@ -29,6 +29,7 @@ class FieldName < Base
using RuboCop::GraphQL::Ext::SnakeCase

MSG = "Use snake_case for field names"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/legacy_dsl.rb
Expand Up @@ -32,6 +32,7 @@ class LegacyDsl < Base

MSG = "Avoid using legacy based type-based definitions. " \
"Use class-based definitions instead."
RESTRICT_ON_SEND = %i[define].freeze

def on_send(node)
return unless node.parent.block_type?
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/graphql/multiple_field_definitions.rb
Expand Up @@ -32,6 +32,8 @@ class MultipleFieldDefinitions < Base
include RuboCop::Cop::RangeHelp
include RuboCop::GraphQL::Heredoc

RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field?(node)

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/unnecessary_argument_camelize.rb
Expand Up @@ -44,6 +44,7 @@ class UnnecessaryArgumentCamelize < Base
include RuboCop::GraphQL::NodePattern

MSG = "Unnecessary argument camelize"
RESTRICT_ON_SEND = %i[argument].freeze

def on_send(node)
return unless argument?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/unnecessary_field_alias.rb
Expand Up @@ -25,6 +25,7 @@ class UnnecessaryFieldAlias < Base
include RuboCop::GraphQL::NodePattern

MSG = "Unnecessary :%<kwarg>s configured"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/graphql/unnecessary_field_camelize.rb
Expand Up @@ -22,6 +22,7 @@ class UnnecessaryFieldCamelize < Base
include RuboCop::GraphQL::NodePattern

MSG = "Unnecessary field camelize"
RESTRICT_ON_SEND = %i[field].freeze

def on_send(node)
return unless field_definition?(node)
Expand Down
2 changes: 1 addition & 1 deletion rubocop-graphql.gemspec
Expand Up @@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.9"

spec.add_runtime_dependency "rubocop", ">= 0.87", "< 2"
spec.add_runtime_dependency "rubocop", ">= 0.90", "< 2"
end

0 comments on commit e9fc652

Please sign in to comment.