pdk 2.7.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +10 -50
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +3 -5
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +22 -14
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +11 -7
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +21 -68
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +13 -21
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -38,6 +38,7 @@ module PDK
38
38
  # @see PDK::Validate::Validator.prepare_invoke!
39
39
  def prepare_invoke!
40
40
  return if @prepared
41
+
41
42
  super
42
43
 
43
44
  # Parse the targets
@@ -65,11 +66,11 @@ module PDK
65
66
  validation_result = validate_target(report, target)
66
67
  if validation_result.nil?
67
68
  report.add_event(
68
- file: target,
69
- source: name,
70
- state: :failure,
69
+ file: target,
70
+ source: name,
71
+ state: :failure,
71
72
  severity: 'error',
72
- message: "Validation did not return an exit code for #{target}",
73
+ message: "Validation did not return an exit code for #{target}"
73
74
  )
74
75
  validation_result = 1
75
76
  end
@@ -38,6 +38,7 @@ module PDK
38
38
  # @see PDK::Validate::Validator.prepare_invoke!
39
39
  def prepare_invoke!
40
40
  return if @prepared
41
+
41
42
  super
42
43
 
43
44
  # Register the spinner
@@ -63,6 +64,7 @@ module PDK
63
64
  # targets. For example, using rubocop with no targets, will allow rubocop to determine the
64
65
  # target list using it's .rubocop.yml file
65
66
  return [[], [], []] if requested_targets.empty? && allow_empty_targets?
67
+
66
68
  # If no targets are specified, then we will run validations from the base context directory.
67
69
  targets = requested_targets.empty? ? [context.root_path] : requested_targets
68
70
  targets.map! { |r| r.gsub(File::ALT_SEPARATOR, File::SEPARATOR) } if File::ALT_SEPARATOR
@@ -72,7 +74,7 @@ module PDK
72
74
 
73
75
  skipped = []
74
76
  invalid = []
75
- matched = targets.map { |target|
77
+ matched = targets.filter_map do |target|
76
78
  if pattern.nil?
77
79
  target
78
80
  else
@@ -87,16 +89,14 @@ module PDK
87
89
  target_list = target_list.reject { |file| ignore_list.match(file) }
88
90
 
89
91
  if target_list.flatten.empty?
90
- PDK.logger.info('Validator \'%{validator}\' skipped for \'%{target}\'. No files matching \'%{pattern}\' found to validate.' % { validator: name, target: target, pattern: pattern })
92
+ PDK.logger.info(format('Validator \'%{validator}\' skipped for \'%{target}\'. No files matching \'%{pattern}\' found to validate.', validator: name, target: target, pattern: pattern))
91
93
 
92
94
  skipped << target
93
95
  end
94
96
 
95
97
  target_list
96
98
  elsif PDK::Util::Filesystem.file?(target)
97
- if Array(pattern).include? target
98
- target
99
- elsif Array(pattern).any? { |p| PDK::Util::Filesystem.fnmatch(PDK::Util::Filesystem.expand_path(p), PDK::Util::Filesystem.expand_path(target), File::FNM_DOTMATCH) }
99
+ if (Array(pattern).include? target) || fnmatch?(pattern, target)
100
100
  target
101
101
  else
102
102
  skipped << target
@@ -107,10 +107,17 @@ module PDK
107
107
  next
108
108
  end
109
109
  end
110
- }.compact.flatten.uniq
110
+ end.flatten.uniq
111
111
  [matched, skipped, invalid]
112
112
  end
113
113
 
114
+ # Matches a target against a pattern
115
+ # @param pattern [String, Array[String]] The pattern to match against
116
+ # @return [Boolean]
117
+ def fnmatch?(pattern, target)
118
+ Array(pattern).any? { |p| PDK::Util::Filesystem.fnmatch(PDK::Util::Filesystem.expand_path(p), PDK::Util::Filesystem.expand_path(target), File::FNM_DOTMATCH) }
119
+ end
120
+
114
121
  # Whether the target parsing ignores "dotfiles" (e.g. .gitignore or .pdkignore) which are considered hidden files in POSIX
115
122
  # @return [Boolean]
116
123
  # @abstract
@@ -121,13 +128,14 @@ module PDK
121
128
  # @see PDK::Validate::Validator.spinner_text
122
129
  # @abstract
123
130
  def spinner_text
124
- 'Running %{name} validator ...' % { name: name }
131
+ format('Running %{name} validator ...', name: name)
125
132
  end
126
133
 
127
134
  # @see PDK::Validate::Validator.spinner
128
135
  def spinner
129
136
  return nil unless spinners_enabled?
130
137
  return @spinner unless @spinner.nil?
138
+
131
139
  require 'pdk/cli/util/spinner'
132
140
 
133
141
  @spinner = TTY::Spinner.new("[:spinner] #{spinner_text}", PDK::CLI::Util.spinner_opts_for_platform)
@@ -138,13 +146,13 @@ module PDK
138
146
  # @param skipped [Array[String]] The list of skipped targets
139
147
  def process_skipped(report, skipped = [])
140
148
  skipped.each do |skipped_target|
141
- PDK.logger.debug('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).' % { validator: name, target: skipped_target, pattern: pattern })
149
+ PDK.logger.debug(format('%{validator}: Skipped \'%{target}\'. Target does not contain any files to validate (%{pattern}).', validator: name, target: skipped_target, pattern: pattern))
142
150
  report.add_event(
143
- file: skipped_target,
144
- source: name,
145
- message: 'Target does not contain any files to validate (%{pattern}).' % { pattern: pattern },
151
+ file: skipped_target,
152
+ source: name,
153
+ message: format('Target does not contain any files to validate (%{pattern}).', pattern: pattern),
146
154
  severity: :info,
147
- state: :skipped,
155
+ state: :skipped
148
156
  )
149
157
  end
150
158
  end
@@ -154,13 +162,13 @@ module PDK
154
162
  # @param invalid [Array[String]] The list of invalid targets
155
163
  def process_invalid(report, invalid = [])
156
164
  invalid.each do |invalid_target|
157
- PDK.logger.debug('%{validator}: Skipped \'%{target}\'. Target file not found.' % { validator: name, target: invalid_target })
165
+ PDK.logger.debug(format('%{validator}: Skipped \'%{target}\'. Target file not found.', validator: name, target: invalid_target))
158
166
  report.add_event(
159
- file: invalid_target,
160
- source: name,
161
- message: 'File does not exist.',
167
+ file: invalid_target,
168
+ source: name,
169
+ message: 'File does not exist.',
162
170
  severity: :error,
163
- state: :error,
171
+ state: :error
164
172
  )
165
173
  end
166
174
  end
@@ -187,7 +195,8 @@ module PDK
187
195
  def contextual_pattern(module_pattern)
188
196
  module_pattern = [module_pattern] unless module_pattern.is_a?(Array)
189
197
  return module_pattern unless context.is_a?(PDK::Context::ControlRepo)
190
- context.actualized_module_paths.map { |mod_path| module_pattern.map { |pat_path| mod_path + '/*/' + pat_path } }.flatten
198
+
199
+ context.actualized_module_paths.map { |mod_path| module_pattern.map { |pat_path| "#{mod_path}/*/#{pat_path}" } }.flatten
191
200
  end
192
201
 
193
202
  private
@@ -195,10 +204,11 @@ module PDK
195
204
  # Helper method to collate the default ignored paths
196
205
  # @return [PathSpec] Paths to ignore
197
206
  def ignore_pathspec
198
- ignore_pathspec = if context.is_a?(PDK::Context::Module)
207
+ ignore_pathspec = case context
208
+ when PDK::Context::Module
199
209
  require 'pdk/module'
200
210
  PDK::Module.default_ignored_pathspec(ignore_dotfiles?)
201
- elsif context.is_a?(PDK::Context::ControlRepo)
211
+ when PDK::Context::ControlRepo
202
212
  require 'pdk/control_repo'
203
213
  PDK::ControlRepo.default_ignored_pathspec(ignore_dotfiles?)
204
214
  else
@@ -19,9 +19,7 @@ module PDK
19
19
  end
20
20
 
21
21
  def spinner_text_for_targets(targets)
22
- 'Checking module metadata style (%{targets}).' % {
23
- targets: PDK::Util.targets_relative_to_pwd(targets.flatten).join(' '),
24
- }
22
+ format('Checking module metadata style (%{targets}).', targets: PDK::Util.targets_relative_to_pwd(targets.flatten).join(' '))
25
23
  end
26
24
 
27
25
  def pattern
@@ -54,27 +52,27 @@ module PDK
54
52
 
55
53
  if json_data.empty?
56
54
  report.add_event(
57
- file: targets.first,
58
- source: name,
59
- state: :passed,
60
- severity: :ok,
55
+ file: targets.first,
56
+ source: name,
57
+ state: :passed,
58
+ severity: :ok
61
59
  )
62
60
  else
63
61
  json_data.delete('result')
64
- json_data.keys.each do |type|
62
+ json_data.each_key do |type|
65
63
  json_data[type].each do |offense|
66
64
  # metadata-json-lint groups the offenses by type, so the type ends
67
65
  # up being `warnings` or `errors`. We want to convert that to the
68
66
  # singular noun for the event.
69
- event_type = type[%r{\A(.+?)s?\Z}, 1]
67
+ event_type = type[/\A(.+?)s?\Z/, 1]
70
68
 
71
69
  report.add_event(
72
- file: targets.first,
73
- source: name,
74
- message: offense['msg'],
75
- test: offense['check'],
70
+ file: targets.first,
71
+ source: name,
72
+ message: offense['msg'],
73
+ test: offense['check'],
76
74
  severity: event_type,
77
- state: :failure,
75
+ state: :failure
78
76
  )
79
77
  end
80
78
  end
@@ -13,9 +13,7 @@ module PDK
13
13
  end
14
14
 
15
15
  def spinner_text
16
- 'Checking metadata syntax (%{patterns}).' % {
17
- patterns: pattern.join(' '),
18
- }
16
+ format('Checking metadata syntax (%{patterns}).', patterns: pattern.join(' '))
19
17
  end
20
18
 
21
19
  def invoke(report)
@@ -40,7 +38,7 @@ module PDK
40
38
  source: name,
41
39
  state: :failure,
42
40
  severity: 'error',
43
- message: 'Could not be read.',
41
+ message: 'Could not be read.'
44
42
  )
45
43
  return 1
46
44
  end
@@ -49,27 +47,27 @@ module PDK
49
47
  JSON.parse(PDK::Util::Filesystem.read_file(target))
50
48
 
51
49
  report.add_event(
52
- file: target,
53
- source: name,
54
- state: :passed,
55
- severity: 'ok',
50
+ file: target,
51
+ source: name,
52
+ state: :passed,
53
+ severity: 'ok'
56
54
  )
57
- return 0
55
+ 0
58
56
  rescue JSON::ParserError => e
59
57
  # Because the message contains a raw segment of the file, we use
60
58
  # String#dump here to unescape any escape characters like newlines.
61
59
  # We then strip out the surrounding quotes and the exclaimation
62
60
  # point that json_pure likes to put in exception messages.
63
- sane_message = e.message.dump[%r{\A"(.+?)!?"\Z}, 1]
61
+ sane_message = e.message.dump[/\A"(.+?)!?"\Z/, 1]
64
62
 
65
63
  report.add_event(
66
- file: target,
67
- source: name,
68
- state: :failure,
64
+ file: target,
65
+ source: name,
66
+ state: :failure,
69
67
  severity: 'error',
70
- message: sane_message,
68
+ message: sane_message
71
69
  )
72
- return 1
70
+ 1
73
71
  end
74
72
  end
75
73
  end
@@ -11,7 +11,7 @@ module PDK
11
11
  def validators
12
12
  [
13
13
  MetadataSyntaxValidator,
14
- MetadataJSONLintValidator,
14
+ MetadataJSONLintValidator
15
15
  ].freeze
16
16
  end
17
17
  end
@@ -5,16 +5,16 @@ module PDK
5
5
  module Puppet
6
6
  class PuppetEPPValidator < ExternalCommandValidator
7
7
  # In Puppet >= 5.3.4, the error context formatting was changed to facilitate localization
8
- ERROR_CONTEXT = %r{(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))}
8
+ ERROR_CONTEXT = /(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))/.freeze
9
9
  # In Puppet < 5.3.3, the error context was formatted in these variations:
10
10
  # - "at file_path:line_num:col_num"
11
11
  # - "at file_path:line_num"
12
12
  # - "at line line_num"
13
13
  # - "in file_path"
14
- ERROR_CONTEXT_LEGACY = %r{(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))}
14
+ ERROR_CONTEXT_LEGACY = /(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))/.freeze
15
15
 
16
- PUPPET_LOGGER_PREFIX = %r{^(debug|info|notice|warning|error|alert|critical):\s.+?$}i
17
- PUPPET_SYNTAX_PATTERN = %r{^
16
+ PUPPET_LOGGER_PREFIX = /^(debug|info|notice|warning|error|alert|critical):\s.+?$/i.freeze
17
+ PUPPET_SYNTAX_PATTERN = /^
18
18
  (?<severity>.+?):\s
19
19
  (?<message>.+?)
20
20
  (?:
@@ -22,7 +22,7 @@ module PDK
22
22
  \s#{ERROR_CONTEXT_LEGACY}| # attempt to match the old " at file:line:column" location
23
23
  $ # handle cases where the output has no location
24
24
  )
25
- $}x
25
+ $/x.freeze
26
26
 
27
27
  def name
28
28
  'puppet-epp'
@@ -37,7 +37,7 @@ module PDK
37
37
  end
38
38
 
39
39
  def spinner_text_for_targets(_targets)
40
- 'Checking Puppet EPP syntax (%{pattern}).' % { pattern: pattern.join(' ') }
40
+ format('Checking Puppet EPP syntax (%{pattern}).', pattern: pattern.join(' '))
41
41
  end
42
42
 
43
43
  def parse_options(targets)
@@ -76,7 +76,7 @@ module PDK
76
76
  def parse_output(report, result, targets)
77
77
  # Due to PUP-7504, we will have to programmatically construct the json
78
78
  # object from the text output for now.
79
- output = result[:stderr].split(%r{\r?\n}).reject { |entry| entry.empty? }
79
+ output = result[:stderr].split(/\r?\n/).reject(&:empty?)
80
80
 
81
81
  results_data = []
82
82
  output.each do |offense|
@@ -87,12 +87,12 @@ module PDK
87
87
  # puppet parser validate does not include files without problems in its
88
88
  # output, so we need to go through the list of targets and add passing
89
89
  # events to the report for any target not listed in the output.
90
- targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
90
+ targets.reject { |target| results_data.any? { |j| j[:file] =~ /#{target}/ } }.each do |target|
91
91
  report.add_event(
92
- file: target,
93
- source: name,
92
+ file: target,
93
+ source: name,
94
94
  severity: :ok,
95
- state: :passed,
95
+ state: :passed
96
96
  )
97
97
  end
98
98
 
@@ -105,17 +105,15 @@ module PDK
105
105
  sanitize_console_output(offense)
106
106
 
107
107
  offense_data = {
108
- source: name,
109
- state: :failure,
108
+ source: name,
109
+ state: :failure
110
110
  }
111
111
 
112
112
  if offense.match(PUPPET_LOGGER_PREFIX)
113
113
  attributes = offense.match(PUPPET_SYNTAX_PATTERN)
114
114
 
115
- unless attributes.nil?
116
- attributes.names.each do |name|
117
- offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
118
- end
115
+ attributes&.names&.each do |name|
116
+ offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
119
117
  end
120
118
  else
121
119
  offense_data[:message] = offense
@@ -125,7 +123,7 @@ module PDK
125
123
  end
126
124
 
127
125
  def sanitize_console_output(line)
128
- line.gsub!(%r{\e\[([;\d]+)?m}, '')
126
+ line.gsub!(/\e\[([;\d]+)?m/, '')
129
127
  end
130
128
  end
131
129
  end
@@ -17,7 +17,7 @@ module PDK
17
17
  end
18
18
 
19
19
  def spinner_text_for_targets(_targets)
20
- 'Checking Puppet manifest style (%{pattern}).' % { pattern: pattern.join(' ') }
20
+ format('Checking Puppet manifest style (%{pattern}).', pattern: pattern.join(' '))
21
21
  end
22
22
 
23
23
  def parse_options(targets)
@@ -40,24 +40,24 @@ module PDK
40
40
  # events to the report for any target not listed in the JSON output.
41
41
  targets.reject { |target| json_data.any? { |j| j['path'] == target } }.each do |target|
42
42
  report.add_event(
43
- file: target,
44
- source: name,
43
+ file: target,
44
+ source: name,
45
45
  severity: 'ok',
46
- state: :passed,
46
+ state: :passed
47
47
  )
48
48
  end
49
49
 
50
50
  json_data.each do |offense|
51
- report.add_event(
52
- file: offense['path'],
53
- source: name,
54
- line: offense['line'],
55
- column: offense['column'],
56
- message: offense['message'],
57
- test: offense['check'],
58
- severity: (offense['kind'] == 'fixed') ? 'corrected' : offense['kind'],
59
- state: :failure,
60
- )
51
+ report.add_event({
52
+ file: offense['path'],
53
+ source: name,
54
+ line: offense['line'],
55
+ column: offense['column'],
56
+ message: offense['message'],
57
+ test: offense['check'],
58
+ severity: offense['kind'] == 'fixed' ? 'corrected' : offense['kind'],
59
+ state: :failure
60
+ })
61
61
  end
62
62
  end
63
63
  end
@@ -15,7 +15,7 @@ module PDK
15
15
  def pattern_ignore; end
16
16
 
17
17
  def spinner_text_for_targets(_targets)
18
- 'Checking Puppet plan syntax (%{pattern}).' % { pattern: pattern.join(' ') }
18
+ format('Checking Puppet plan syntax (%{pattern}).', pattern: pattern.join(' '))
19
19
  end
20
20
 
21
21
  def parse_options(targets)
@@ -5,16 +5,16 @@ module PDK
5
5
  module Puppet
6
6
  class PuppetSyntaxValidator < ExternalCommandValidator
7
7
  # In Puppet >= 5.3.4, the error context formatting was changed to facilitate localization
8
- ERROR_CONTEXT = %r{(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))}
8
+ ERROR_CONTEXT = /(?:file:\s(?<file>.+?)|line:\s(?<line>.+?)|column:\s(?<column>.+?))/.freeze
9
9
  # In Puppet < 5.3.3, the error context was formatted in these variations:
10
10
  # - "at file_path:line_num:col_num"
11
11
  # - "at file_path:line_num"
12
12
  # - "at line line_num"
13
13
  # - "in file_path"
14
- ERROR_CONTEXT_LEGACY = %r{(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))}
14
+ ERROR_CONTEXT_LEGACY = /(?:at\sline\s(?<line>\d+)|at\s(?<file>.+?):(?<line>\d+):(?<column>\d+)|at\s(?<file>.+?):(?<line>\d+)|in\s(?<file>.+?))/.freeze
15
15
 
16
- PUPPET_LOGGER_PREFIX = %r{^(debug|info|notice|warning|error|alert|critical):\s.+?$}i
17
- PUPPET_SYNTAX_PATTERN = %r{^
16
+ PUPPET_LOGGER_PREFIX = /^(debug|info|notice|warning|error|alert|critical):\s.+?$/i.freeze
17
+ PUPPET_SYNTAX_PATTERN = /^
18
18
  (?<severity>.+?):\s
19
19
  (?<message>.+?)
20
20
  (?:
@@ -22,7 +22,7 @@ module PDK
22
22
  \s#{ERROR_CONTEXT_LEGACY}| # attempt to match the old " at file:line:column" location
23
23
  $ # handle cases where the output has no location
24
24
  )
25
- $}x
25
+ $/x.freeze
26
26
 
27
27
  def name
28
28
  'puppet-syntax'
@@ -41,7 +41,7 @@ module PDK
41
41
  end
42
42
 
43
43
  def spinner_text_for_targets(_targets)
44
- 'Checking Puppet manifest syntax (%{pattern}).' % { pattern: pattern.join(' ') }
44
+ format('Checking Puppet manifest syntax (%{pattern}).', pattern: pattern.join(' '))
45
45
  end
46
46
 
47
47
  def parse_options(targets)
@@ -80,7 +80,7 @@ module PDK
80
80
  def parse_output(report, result, targets)
81
81
  # Due to PUP-7504, we will have to programmatically construct the json
82
82
  # object from the text output for now.
83
- output = result[:stderr].split(%r{\r?\n}).reject { |entry| entry.empty? }
83
+ output = result[:stderr].split(/\r?\n/).reject(&:empty?)
84
84
 
85
85
  results_data = []
86
86
  output.each do |offense|
@@ -91,12 +91,12 @@ module PDK
91
91
  # puppet parser validate does not include files without problems in its
92
92
  # output, so we need to go through the list of targets and add passing
93
93
  # events to the report for any target not listed in the output.
94
- targets.reject { |target| results_data.any? { |j| j[:file] =~ %r{#{target}} } }.each do |target|
94
+ targets.reject { |target| results_data.any? { |j| j[:file] =~ /#{target}/ } }.each do |target|
95
95
  report.add_event(
96
- file: target,
97
- source: name,
96
+ file: target,
97
+ source: name,
98
98
  severity: :ok,
99
- state: :passed,
99
+ state: :passed
100
100
  )
101
101
  end
102
102
 
@@ -109,17 +109,15 @@ module PDK
109
109
  sanitize_console_output(offense)
110
110
 
111
111
  offense_data = {
112
- source: name,
113
- state: :failure,
112
+ source: name,
113
+ state: :failure
114
114
  }
115
115
 
116
116
  if offense.match(PUPPET_LOGGER_PREFIX)
117
117
  attributes = offense.match(PUPPET_SYNTAX_PATTERN)
118
118
 
119
- unless attributes.nil?
120
- attributes.names.each do |name|
121
- offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
122
- end
119
+ attributes&.names&.each do |name|
120
+ offense_data[name.to_sym] = attributes[name] unless attributes[name].nil?
123
121
  end
124
122
  else
125
123
  offense_data[:message] = offense
@@ -129,7 +127,7 @@ module PDK
129
127
  end
130
128
 
131
129
  def sanitize_console_output(line)
132
- line.gsub!(%r{\e\[([;\d]+)?m}, '')
130
+ line.gsub!(/\e\[([;\d]+)?m/, '')
133
131
  end
134
132
  end
135
133
  end
@@ -13,7 +13,7 @@ module PDK
13
13
  PuppetSyntaxValidator,
14
14
  PuppetPlanSyntaxValidator,
15
15
  PuppetLintValidator,
16
- PuppetEPPValidator,
16
+ PuppetEPPValidator
17
17
  ].freeze
18
18
  end
19
19
  end
@@ -25,15 +25,13 @@ module PDK
25
25
  end
26
26
 
27
27
  def spinner_text_for_targets(_targets)
28
- 'Checking Ruby code style (%{pattern}).' % { pattern: pattern }
28
+ format('Checking Ruby code style (%{pattern}).', pattern: pattern)
29
29
  end
30
30
 
31
31
  def parse_options(targets)
32
32
  cmd_options = ['--format', 'json']
33
33
 
34
- if options[:auto_correct]
35
- cmd_options << '--auto-correct'
36
- end
34
+ cmd_options << '--auto-correct' if options[:auto_correct]
37
35
 
38
36
  cmd_options.concat(targets)
39
37
  end
@@ -51,9 +49,10 @@ module PDK
51
49
 
52
50
  json_data['files'].each do |file_info|
53
51
  next unless file_info.key?('offenses')
52
+
54
53
  result = {
55
54
  file: file_info['path'],
56
- source: 'rubocop',
55
+ source: 'rubocop'
57
56
  }
58
57
 
59
58
  if file_info['offenses'].empty?
@@ -62,13 +61,13 @@ module PDK
62
61
  file_info['offenses'].each do |offense|
63
62
  report.add_event(
64
63
  result.merge(
65
- line: offense['location']['line'],
66
- column: offense['location']['column'],
67
- message: offense['message'],
64
+ line: offense['location']['line'],
65
+ column: offense['location']['column'],
66
+ message: offense['message'],
68
67
  severity: offense['corrected'] ? 'corrected' : offense['severity'],
69
- test: offense['cop_name'],
70
- state: :failure,
71
- ),
68
+ test: offense['cop_name'],
69
+ state: :failure
70
+ )
72
71
  )
73
72
  end
74
73
  end
@@ -10,7 +10,7 @@ module PDK
10
10
 
11
11
  def validators
12
12
  [
13
- RubyRubocopValidator,
13
+ RubyRubocopValidator
14
14
  ].freeze
15
15
  end
16
16
  end