Sha256: d2414371141e2cd6186dd9f8e886e9af3286cd218ca55e265133abc5104dee70

Contents?: true

Size: 675 Bytes

Versions: 1

Compression:

Stored size: 675 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'yaml'
require 'pre-commit/checks/plugin'

module PreCommit
  module Checks
    # Checks YAML to make sure it's parsable.
    class Yaml < Plugin
      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') unless errors.empty?
      end

      def load_file(file)
        YAML.load_file(file)
        nil
      rescue ArgumentError => e
        "#{e.message} parsing #{file}"
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gazelle_styleguide-0.0.1 lib/plugins/pre_commit/checks/yaml.rb