Sha256: 5e039c218985c9b8835515fe83509a79cae3af2604e9c1f170135ad6d3f7e3bb

Contents?: true

Size: 971 Bytes

Versions: 70

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Help methods for working with nodes containing comments.
      module CommentsHelp
        include FinalEndLocation

        def source_range_with_comment(node)
          begin_pos = begin_pos_with_comment(node).begin_pos
          end_pos = end_line_position(node).end_pos

          Parser::Source::Range.new(buffer, begin_pos, end_pos)
        end

        def begin_pos_with_comment(node)
          first_comment = processed_source.ast_with_comments[node].first

          start_line_position(first_comment || node)
        end

        def start_line_position(node)
          buffer.line_range(node.loc.line)
        end

        def end_line_position(node)
          end_line = buffer.line_for_position(final_end_location(node).end_pos)
          buffer.line_range(end_line)
        end

        def buffer
          processed_source.buffer
        end
      end
    end
  end
end

Version data entries

70 entries across 64 versions & 7 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/mixin/comments_help.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/mixin/comments_help.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/mixin/comments_help.rb