Sha256: 10c085f54be3c95352455ae7a2bea933c7a71245f0c439fc1aa11b8e43376a5d

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

require "json"

KEYS_TO_CHECK = %w[engines lint-staged].freeze

module NeetoCompliance
  class PackageJsonVerifier < Base
    def valid?
      @common_lint_staged = JSON.parse(open(common_packages_latest_file).read)
      project_lint_staged = JSON.parse(open("package.json").read)

      @results = KEYS_TO_CHECK.map { |key| @common_lint_staged[key].to_json === project_lint_staged[key].to_json }
      @results.all?
    end

    def auto_correct!
    end

    def autofix_command
      return "" if @results.all?

      command = ""
      KEYS_TO_CHECK.each_with_index do |key, index|
        next if @results[index]

        command += "Replace the value of \"#{key}\" in package.json with:\n\n#{JSON.pretty_generate(@common_lint_staged[key])}\n\n"
      end

      command
    end

    private

      def common_packages_latest_file
        NeetoCompliance::NeetoCommons.path.join "common_files/package-common.json"
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neetob-0.1.2 neeto_compliance/lib/neeto_compliance/verifiers/package_json_verifier.rb
neetob-0.1.1 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/package_json_verifier.rb
neetob-0.1.0 /Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/package_json_verifier.rb