Sha256: 87a59c766e1f665910dcc2c577e44ec1bb0b6f97e5d2105b1d757ef0b39dd33b

Contents?: true

Size: 1.28 KB

Versions: 90

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true
require "rubocop"

module GraphQL
  module Rubocop
    module GraphQL
      class BaseCop < RuboCop::Cop::Base
        extend RuboCop::Cop::AutoCorrector

        # Return the source of `send_node`, but without the keyword argument represented by `pair_node`
        def source_without_keyword_argument(send_node, pair_node)
          # work back to the preceeding comma
          first_pos = pair_node.location.expression.begin_pos
          end_pos = pair_node.location.expression.end_pos
          node_source = send_node.source_range.source
          node_first_pos = send_node.location.expression.begin_pos

          relative_first_pos = first_pos - node_first_pos
          relative_last_pos = end_pos - node_first_pos

          begin_removal_pos = relative_first_pos
          while node_source[begin_removal_pos] != ","
            begin_removal_pos -= 1
            if begin_removal_pos < 1
              raise "Invariant: somehow backtracked to beginning of node looking for a comma (node source: #{node_source.inspect})"
            end
          end

          end_removal_pos = relative_last_pos
          cleaned_node_source = node_source[0...begin_removal_pos] + node_source[end_removal_pos..-1]
          cleaned_node_source
        end
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 2 rubygems

Version Path
graphql-2.0.28 lib/graphql/rubocop/graphql/base_cop.rb
graphql-1.13.21 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.5 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.4 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.3 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.10 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.2 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.9 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.1 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.2.0 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.8 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.7 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.6 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.5 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.4 lib/graphql/rubocop/graphql/base_cop.rb
graphql-1.13.20 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.3 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.2 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.1 lib/graphql/rubocop/graphql/base_cop.rb
graphql-2.1.0 lib/graphql/rubocop/graphql/base_cop.rb