Class: RuboCop::Cop::GraphQL::UnnecessaryFieldAlias
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::GraphQL::UnnecessaryFieldAlias
- Extended by:
- AutoCorrector
- Includes:
- GraphQL::NodePattern
- Defined in:
- lib/rubocop/cop/graphql/unnecessary_field_alias.rb
Overview
This cop prevents defining an unnecessary alias, method, or resolver_method.
Constant Summary collapse
- MSG =
"Unnecessary :%<kwarg>s configured"
- RESTRICT_ON_SEND =
%i[field].freeze
Instance Method Summary collapse
Methods included from GraphQL::NodePattern
#argument?, #field?, #field_definition?, #field_definition_with_body?
Instance Method Details
#on_send(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cop/graphql/unnecessary_field_alias.rb', line 30 def on_send(node) return unless field_definition?(node) field = RuboCop::GraphQL::Field.new(node) if (unnecessary_kwarg = validate_kwargs(field)) = format(self.class::MSG, kwarg: unnecessary_kwarg) add_offense(node, message: ) do |corrector| kwarg_node = node.last_argument.pairs.find do |pair| pair.key.value == unnecessary_kwarg.to_sym end corrector.remove_preceding(kwarg_node, 2) corrector.remove(kwarg_node) end end end |