Class: PreCommit::Checks::Yaml

Inherits:
Plugin
  • Object
show all
Defined in:
lib/plugins/pre_commit/checks/yaml.rb

Overview

The Yaml check will read and parse YAML files to ensure they have valid syntax.

Instance Attribute Summary

Attributes inherited from Plugin

#config, #pluginator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#initialize, #name

Constructor Details

This class inherits a constructor from PreCommit::Checks::Plugin

Class Method Details

.descriptionObject



13
14
15
# File 'lib/plugins/pre_commit/checks/yaml.rb', line 13

def self.description
  'Runs yaml to detect errors.'
end

Instance Method Details

#call(staged_files) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/plugins/pre_commit/checks/yaml.rb', line 17

def call(staged_files)
  staged_files = staged_files.grep(/\.(yml|yaml)$/)
  return if staged_files.empty?

  errors = staged_files.map {|file| load_file(file)}.compact

  errors.join("\n") + "\n" unless errors.empty?
end