Class: PDK::Validate::Metadata::MetadataJSONLintValidator
Instance Attribute Summary
#commands
Attributes inherited from Validator
#context, #options, #prepared
Instance Method Summary
collapse
#alternate_bin_paths, #cmd_path, #invoke, #prepare_invoke!, #spinner
#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #parse_targets, #pattern_ignore, #prepare_invoke!, #process_invalid, #process_skipped, #spinner, #spinner_text, #valid_in_context?
Methods inherited from Validator
#initialize, #invoke, #prepare_invoke!, #spinner, #spinner_text, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?
Instance Method Details
#cmd ⇒ Object
17
18
19
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 17
def cmd
'metadata-json-lint'
end
|
#invoke_style ⇒ Object
Validate each metadata file separately, as metadata-json-lint does not support multiple targets.
9
10
11
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 9
def invoke_style
:per_target
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 13
def name
'metadata-json-lint'
end
|
#parse_options(targets) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 29
def parse_options(targets)
cmd_options = ['--format', 'json']
cmd_options << '--strict-dependencies'
cmd_options.concat(targets)
end
|
#parse_output(report, result, targets) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 36
def parse_output(report, result, targets)
raise ArgumentError, 'More than 1 target provided to PDK::Validate::MetadataJSONLintValidator.' if targets.count > 1
if result[:stdout].strip.empty?
json_data = {}
else
begin
json_data = JSON.parse(result[:stdout])
rescue JSON::ParserError
raise PDK::Validate::ParseOutputError, result[:stdout]
end
end
if json_data.empty?
report.add_event(
file: targets.first,
source: name,
state: :passed,
severity: :ok
)
else
json_data.delete('result')
json_data.each_key do |type|
json_data[type].each do |offense|
event_type = type[/\A(.+?)s?\Z/, 1]
report.add_event(
file: targets.first,
source: name,
message: offense['msg'],
test: offense['check'],
severity: event_type,
state: :failure
)
end
end
end
end
|
#pattern ⇒ Object
25
26
27
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 25
def pattern
contextual_pattern('metadata.json')
end
|
#spinner_text_for_targets(targets) ⇒ Object
21
22
23
|
# File 'lib/pdk/validate/metadata/metadata_json_lint_validator.rb', line 21
def spinner_text_for_targets(targets)
format('Checking module metadata style (%{targets}).', targets: PDK::Util.targets_relative_to_pwd(targets.flatten).join(' '))
end
|