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
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.19.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.18.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.18.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.17.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.17.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.16.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.15.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.14.2 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.14.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.14.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.13.2 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.13.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.13.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/mixin/comments_help.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/mixin/comments_help.rb