Sha256: eed794376968711204960ec70e3784a23f82db98d5035c1fb388586bab70da1b

Contents?: true

Size: 450 Bytes

Versions: 3

Compression:

Stored size: 450 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::PreCommit
  # Checks the syntax of any modified JSON files.
  class JsonSyntax < Base
    def run
      messages = []

      applicable_files.each do |file|
        JSON.parse(IO.read(file))
      rescue JSON::ParserError => e
        error = "#{e.message} parsing #{file}"
        messages << Overcommit::Hook::Message.new(:error, file, nil, error)
      end

      messages
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
overcommit-0.64.1 lib/overcommit/hook/pre_commit/json_syntax.rb
overcommit-0.64.0 lib/overcommit/hook/pre_commit/json_syntax.rb
overcommit-0.63.0 lib/overcommit/hook/pre_commit/json_syntax.rb