File: range.rb

package info (click to toggle)
ruby-rubocop-ast 0.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 892 kB
  • sloc: ruby: 10,886; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module RuboCop
  module AST
    module Ext
      # Extensions to Parser::AST::Range
      module Range
        # @return [Range] the range of line numbers for the node
        # If `exclude_end` is `true`, then the range will be exclusive.
        #
        # Assume that `node` corresponds to the following array literal:
        #
        #   [
        #     :foo,
        #     :bar
        #   ]
        #
        #   node.loc.begin.line_span                         # => 1..1
        #   node.loc.expression.line_span(exclude_end: true) # => 1...4
        def line_span(exclude_end: false)
          ::Range.new(first_line, last_line, exclude_end)
        end
      end
    end
  end
end

::Parser::Source::Range.include ::RuboCop::AST::Ext::Range