# 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