Class: NeetoCompliance::PackageJsonVerifier

Inherits:
Base
  • Object
show all
Defined in:
lib/neeto_compliance/verifiers/package_json_verifier.rb

Instance Method Summary collapse

Methods inherited from Base

#app_is_exception?, #app_name, #apps_exception_list, #audit, #auto_correct!, #error_message, #print_description, #process, #verifier_name

Instance Method Details

#autofix_commandObject



17
18
19
# File 'lib/neeto_compliance/verifiers/package_json_verifier.rb', line 17

def autofix_command
  "echo '#{updated_package.to_json}' > package.json"
end

#autofix_suggestionObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neeto_compliance/verifiers/package_json_verifier.rb', line 27

def autofix_suggestion
  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.yellow
end

#updated_packageObject



21
22
23
24
25
# File 'lib/neeto_compliance/verifiers/package_json_verifier.rb', line 21

def updated_package
  package = JSON.parse(open("package.json").read)
  KEYS_TO_CHECK.map { |key| package[key] = @common_lint_staged[key] }
  package
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/neeto_compliance/verifiers/package_json_verifier.rb', line 9

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