Class: Yamlint::Rules::KeyDuplicates::DuplicateKeyHandler
- Inherits:
-
Psych::Handler
- Object
- Psych::Handler
- Yamlint::Rules::KeyDuplicates::DuplicateKeyHandler
- Defined in:
- lib/yamlint/rules/key_duplicates.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
writeonly
Sets the attribute parser.
-
#problems ⇒ Object
readonly
Returns the value of attribute problems.
Instance Method Summary collapse
- #end_mapping ⇒ Object
- #end_sequence ⇒ Object
-
#initialize ⇒ DuplicateKeyHandler
constructor
A new instance of DuplicateKeyHandler.
- #scalar(value, _anchor, _tag, _plain, _quoted, _style) ⇒ Object
- #start_mapping ⇒ Object
- #start_sequence ⇒ Object
Constructor Details
#initialize ⇒ DuplicateKeyHandler
Returns a new instance of DuplicateKeyHandler.
36 37 38 39 40 41 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 36 def initialize super @stack = [] @problems = [] @parser = nil end |
Instance Attribute Details
#parser=(value) ⇒ Object (writeonly)
Sets the attribute parser
43 44 45 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 43 def parser=(value) @parser = value end |
#problems ⇒ Object (readonly)
Returns the value of attribute problems.
34 35 36 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 34 def problems @problems end |
Instance Method Details
#end_mapping ⇒ Object
55 56 57 58 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 55 def end_mapping frame = @stack.pop close_parent_value(frame) end |
#end_sequence ⇒ Object
68 69 70 71 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 68 def end_sequence frame = @stack.pop close_parent_value(frame) end |
#scalar(value, _anchor, _tag, _plain, _quoted, _style) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 73 def scalar(value, _anchor, _tag, _plain, _quoted, _style) frame = @stack.last return unless frame && frame[:type] == :mapping if frame[:expecting_key] current_keys = frame[:keys] mark = @parser&.mark if current_keys.key?(value) @problems << { key: value, line: mark ? mark.line + 1 : 1, column: mark ? mark.column + 1 : 1 } else current_keys[value] = true end frame[:expecting_key] = false else frame[:expecting_key] = true end end |
#start_mapping ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 45 def start_mapping(*) parent = current_mapping_frame @stack << { type: :mapping, keys: {}, expecting_key: true, close_parent: capture_close_parent(parent) } end |
#start_sequence ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/yamlint/rules/key_duplicates.rb', line 60 def start_sequence(*) parent = current_mapping_frame @stack << { type: :sequence, close_parent: capture_close_parent(parent) } end |