Class: JsonLint::Linter::KeyOverlapDetector

Inherits:
Oj::Saj
  • Object
show all
Defined in:
lib/jsonlint/linter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyOverlapDetector



50
51
52
53
54
55
56
57
# File 'lib/jsonlint/linter.rb', line 50

def initialize
  @seen_keys = Set.new
  @key_components = []
  @overlapping_keys = Set.new

  @complex_type = []
  @array_positions = []
end

Instance Attribute Details

#overlapping_keysObject (readonly)

Returns the value of attribute overlapping_keys.



48
49
50
# File 'lib/jsonlint/linter.rb', line 48

def overlapping_keys
  @overlapping_keys
end

Instance Method Details

#add_value(value, key) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/jsonlint/linter.rb', line 103

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) ⇒ Object



96
97
98
99
100
101
# File 'lib/jsonlint/linter.rb', line 96

def array_end(key)
  JsonLint.logger.debug { "array_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
  @array_positions.pop
end

#array_start(key) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/jsonlint/linter.rb', line 80

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) ⇒ Object



118
119
120
# File 'lib/jsonlint/linter.rb', line 118

def error(message, line, column)
  JsonLint.logger.debug { "error: #{message.inspect}, #{line.inspect}, #{column.inspect}" }
end

#hash_end(key) ⇒ Object



74
75
76
77
78
# File 'lib/jsonlint/linter.rb', line 74

def hash_end(key)
  JsonLint.logger.debug { "hash_end: #{key.inspect}" }
  @key_components.pop
  @complex_type.pop
end

#hash_start(key) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jsonlint/linter.rb', line 59

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