Module: RuboCop::YAMLDuplicationChecker Private

Defined in:
lib/rubocop/yaml_duplication_checker.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Find duplicated keys from YAML.

Class Method Summary collapse

Class Method Details

.check(yaml_string, filename, &on_duplicated) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/yaml_duplication_checker.rb', line 7

def self.check(yaml_string, filename, &on_duplicated)
  # Ruby 2.6+
  tree = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
           # Specify filename to display helpful message when it raises
           # an error.
           YAML.parse(yaml_string, filename: filename)
         else
           YAML.parse(yaml_string, filename)
         end
  return unless tree

  traverse(tree, &on_duplicated)
end