class JsonLint::Linter::KeyOverlapDetector

Attributes

overlapping_keys[R]

Public Class Methods

new() click to toggle source
# File lib/jsonlint/linter.rb, line 92
def initialize
  @seen_keys = Set.new
  @key_components = []
  @overlapping_keys = Set.new

  @complex_type = []
  @array_positions = []
end

Public Instance Methods

add_value(value, key) click to toggle source
# File lib/jsonlint/linter.rb, line 145
def add_value(value, key)
  JsonLint.logger.debug { "add_value: #{value.inspect}, #{key.inspect}" }
  case @complex_type.last
  when :hash
    @key_components.push(key)
    check_for_overlap!
    @key_components.pop
  when :array
    @key_components.push(@array_positions.last)
    check_for_overlap!
    @array_positions[-1] += 1
    @key_components.pop
  end
end
array_end(key) click to toggle source
# File lib/jsonlint/linter.rb, line 138
def array_end(key)
  JsonLint.logger.debug { "array_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
  @array_positions.pop
end
array_start(key) click to toggle source
# File lib/jsonlint/linter.rb, line 122
def array_start(key)
  JsonLint.logger.debug { "array_start: #{key.inspect}" }

  case @complex_type.last
  when :hash
    @key_components.push(key)
  when :array
    @key_components.push(@array_positions.last)
    @array_positions[-1] += 1
  end

  @complex_type.push(:array)
  @array_positions.push(0)
  check_for_overlap!
end
error(message, line, column) click to toggle source
# File lib/jsonlint/linter.rb, line 160
def error(message, line, column)
  JsonLint.logger.debug { "error: #{message.inspect}, #{line.inspect}, #{column.inspect}" }
end
hash_end(key) click to toggle source
# File lib/jsonlint/linter.rb, line 116
def hash_end(key)
  JsonLint.logger.debug { "hash_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
end
hash_start(key) click to toggle source
# File lib/jsonlint/linter.rb, line 101
def hash_start(key)
  JsonLint.logger.debug { "hash_start: #{key.inspect}" }

  case @complex_type.last
  when :hash
    @key_components.push(key)
  when :array
    @key_components.push(@array_positions.last)
    @array_positions[-1] += 1
  end

  @complex_type.push(:hash)
  check_for_overlap!
end

Private Instance Methods

check_for_overlap!() click to toggle source
# File lib/jsonlint/linter.rb, line 166
def check_for_overlap!
  full_key = @key_components.dup
  JsonLint.logger.debug { "Checking #{full_key.join('.')} for overlap" }

  return if @seen_keys.add?(full_key)
  JsonLint.logger.debug { "Overlapping key #{full_key.join('.')}" }
  @overlapping_keys << full_key
end