File: comment.rb

package info (click to toggle)
ruby-rubocop-ast 1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,256 kB
  • sloc: ruby: 15,071; yacc: 90; makefile: 9
file content (45 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module RuboCop
  module AST
    class NodePattern
      # A NodePattern comment, simplified version of ::Parser::Source::Comment
      class Comment
        attr_reader :location
        alias loc location

        ##
        # @param [Parser::Source::Range] range
        #
        def initialize(range)
          @location = ::Parser::Source::Map.new(range)
          freeze
        end

        # @return [String]
        def text
          loc.expression.source.freeze
        end

        ##
        # Compares comments. Two comments are equal if they
        # correspond to the same source range.
        #
        # @param [Object] other
        # @return [Boolean]
        #
        def ==(other)
          other.is_a?(Comment) &&
            @location == other.location
        end

        ##
        # @return [String] a human-readable representation of this comment
        #
        def inspect
          "#<NodePattern::Comment #{@location.expression} #{text.inspect}>"
        end
      end
    end
  end
end