Class: PDK::Validate::Tasks::TasksMetadataLintValidator
Instance Attribute Summary
Attributes inherited from Validator
#context, #options, #prepared
Instance Method Summary
collapse
#before_validation, #invoke, #prepare_invoke!
#allow_empty_targets?, #fnmatch?, #ignore_dotfiles?, #invoke_style, #parse_targets, #pattern_ignore, #prepare_invoke!, #process_invalid, #process_skipped, #spinner, #valid_in_context?
Methods inherited from Validator
#initialize, #invoke, #prepare_invoke!, #spinner, #spinners_enabled?, #start_spinner, #stop_spinner, #valid_in_context?
Instance Method Details
#name ⇒ Object
7
8
9
|
# File 'lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb', line 7
def name
'task-metadata-lint'
end
|
#pattern ⇒ Object
11
12
13
|
# File 'lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb', line 11
def pattern
contextual_pattern('tasks/*.json')
end
|
#spinner_text ⇒ Object
15
16
17
|
# File 'lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb', line 15
def spinner_text
format('Checking task metadata style (%{pattern}).', pattern: pattern.join(' '))
end
|
#validate_target(report, target) ⇒ Object
30
31
32
33
34
35
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
|
# File 'lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb', line 30
def validate_target(report, target)
unless PDK::Util::Filesystem.readable?(target)
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: 'Could not be read.'
)
return 1
end
require 'json-schema'
begin
JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
JSON.generator = JSON::Ext::Generator if defined?(JSON::Ext::Generator)
begin
errors = JSON::Validator.fully_validate(schema_file, PDK::Util::Filesystem.read_file(target)) || []
rescue JSON::Schema::SchemaError => e
raise PDK::CLI::FatalError, format('Unable to validate Task Metadata. %{error}.', error: e.message)
end
if errors.empty?
report.add_event(
file: target,
source: name,
state: :passed,
severity: 'ok'
)
0
else
errors.each do |error|
error = error.split('in schema').first if error.include? 'in schema'
report.add_event(
file: target,
source: name,
state: :failure,
severity: 'error',
message: error
)
end
1
end
end
end
|