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
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/mixin/comments_help.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/mixin/comments_help.rb