Class: Yamlint::Rules::Anchors
- Defined in:
- lib/yamlint/rules/anchors.rb
Defined Under Namespace
Classes: AnchorHandler
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
defaults, desc, #fixable?, inherited, #initialize, rule_id
Constructor Details
This class inherits a constructor from Yamlint::Rules::Base
Instance Method Details
#check(context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yamlint/rules/anchors.rb', line 16 def check(context) handler = AnchorHandler.new parser = Psych::Parser.new(handler) handler.parser = parser begin parser.parse(context.content) rescue Psych::SyntaxError return [] end problems = [] if @config[:'forbid-undeclared-aliases'] handler.undeclared_aliases.each do |alias_info| problems << problem( line: alias_info[:line], column: alias_info[:column], message: "found undefined alias \"#{alias_info[:name]}\"", fixable: false ) end end if @config[:'forbid-duplicated-anchors'] handler.duplicated_anchors.each do |anchor_info| problems << problem( line: anchor_info[:line], column: anchor_info[:column], message: "found duplicate anchor \"#{anchor_info[:name]}\"", fixable: false ) end end if @config[:'forbid-unused-anchors'] handler.unused_anchors.each do |anchor_info| problems << problem( line: anchor_info[:line], column: anchor_info[:column], message: "found undefined anchor \"#{anchor_info[:name]}\"", fixable: false ) end end problems end |