Sha256: ac33392960fb8963ae5af3f6388c28b9f73a73a109df0044905a7971a16f1a90

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Danger
  # This is your plugin class. Any attributes or methods you expose here will
  # be available from within your Dangerfile.
  #
  # To be published on the Danger plugins site, you will need to have
  # the public interface documented. Danger uses [YARD](http://yardoc.org/)
  # for generating documentation from your plugin source, and you can verify
  # by running `danger plugins lint` or `bundle exec rake spec`.
  #
  # You should replace these comments with a public description of your library.
  #
  # @example Ensure people are well warned about merging on Mondays
  #
  #          my_plugin.warn_on_mondays
  #
  # @see  Stanislav Katkov/danger-yamlint
  # @tags monday, weekends, time, rattata
  #
  class DangerYamlint < Plugin
    def lint
      broken_yaml = {}

      changed_files.each do |file|
        next unless File.readable?(file)
        next unless (file.end_with?('.yaml') || file.end_with?('.yml'))

        begin
          YAML.load_file file
        rescue StandardError => e
          broken_yaml.merge!({ "#{file}" => e.message })
        end
      end

      unless broken_yaml.empty?
        fail("YAML formatting is not valid for these files:
              #{broken_yaml.map { |file, msg| "**#{file}**: #{msg}" }.join('<br/>')}
             ")
      end
    end

    private

    def changed_files
      (git.modified_files + git.added_files)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-yamlint-0.0.1 lib/yamlint/plugin.rb