Sha256: 78856c6f515fc7a9ba047d043cfc0ef205c718996e2b5fd8baadc68df3962267

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# typed: strict
# frozen_string_literal: true

module Spoom
  module Deadcode
    class Location
      extend T::Sig

      include Comparable

      class LocationError < Spoom::Error; end

      class << self
        extend T::Sig

        sig { params(file: String, location: SyntaxTree::Location).returns(Location) }
        def from_syntax_tree(file, location)
          new(file, location.start_line, location.start_column, location.end_line, location.end_column)
        end
      end

      sig { returns(String) }
      attr_reader :file

      sig { returns(Integer) }
      attr_reader :start_line, :start_column, :end_line, :end_column

      sig do
        params(
          file: String,
          start_line: Integer,
          start_column: Integer,
          end_line: Integer,
          end_column: Integer,
        ).void
      end
      def initialize(file, start_line, start_column, end_line, end_column)
        @file = file
        @start_line = start_line
        @start_column = start_column
        @end_line = end_line
        @end_column = end_column
      end

      sig { override.params(other: BasicObject).returns(T.nilable(Integer)) }
      def <=>(other)
        return nil unless Location === other

        to_s <=> other.to_s
      end

      sig { returns(String) }
      def to_s
        "#{@file}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spoom-1.2.2 lib/spoom/deadcode/location.rb