Sha256: dc5c742be96778dd8b506bb83a098a99ef54412f5b479a56273646737e7c288f

Contents?: true

Size: 1.03 KB

Versions: 188

Compression:

Stored size: 1.03 KB

Contents

# 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

Version data entries

188 entries across 182 versions & 24 rubygems

Version Path
rubocop-ast-1.41.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.40.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.39.0 lib/rubocop/ast/node_pattern/comment.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.38.1/lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.38.1 lib/rubocop/ast/node_pattern/comment.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-ast-1.38.0/lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.38.0 lib/rubocop/ast/node_pattern/comment.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.31.3/lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.37.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.36.2 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.36.1 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.36.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.35.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.34.1 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.34.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.33.1 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.33.0 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.32.3 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.32.2 lib/rubocop/ast/node_pattern/comment.rb
rubocop-ast-1.32.1 lib/rubocop/ast/node_pattern/comment.rb