Sha256: 9c62968f69d1e56df916c803593be0ba6ec31dd5d7e90e36edebec24c0b7ea63

Contents?: true

Size: 862 Bytes

Versions: 3

Compression:

Stored size: 862 Bytes

Contents

# frozen_string_literal: true

# This class keeps track of checks being turned on and off in ranges.
# We'll use the node position to figure out if the test is disabled or not.
module ThemeCheck
  class DisabledCheck
    attr_reader :name, :ranges
    attr_accessor :first_line

    def initialize(name)
      @name = name
      @ranges = []
      @first_line = false
    end

    def start_index=(index)
      return unless ranges.empty? || !last.end.nil?
      @ranges << (index..)
    end

    def end_index=(index)
      return if ranges.empty? || !last.end.nil?
      @ranges << (@ranges.pop.begin..index)
    end

    def disabled?(index)
      ranges.any? { |range| range.cover?(index) }
    end

    def last
      ranges.last
    end

    def missing_end_index?
      return false if first_line && ranges.size == 1
      last.end.nil?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-0.8.3 lib/theme_check/disabled_check.rb
theme-check-0.8.2 lib/theme_check/disabled_check.rb
theme-check-0.8.1 lib/theme_check/disabled_check.rb