@@ -124,6 +124,7 @@ def format_message(message)
124124 puts format % message
125125
126126 puts " #{ message [ :reason ] } " if message [ :kind ] == :ignored && !message [ :reason ] . nil?
127+ print_context ( message )
127128 end
128129
129130 # Internal: Format a problem message and print it to STDOUT so GitHub Actions
@@ -154,7 +155,8 @@ def get_context(message)
154155 def print_context ( message )
155156 return if message [ :check ] == 'documentation'
156157 return if message [ :kind ] == :fixed
157- line = get_context ( message )
158+ line = message [ :context ]
159+ return unless line
158160 offset = line . index ( %r{\S } ) || 1
159161 puts "\n #{ line . strip } "
160162 printf ( "%#{ message [ :column ] + 2 - offset } s\n \n " , '^' )
@@ -175,16 +177,16 @@ def report(problems)
175177
176178 next unless message [ :kind ] == :fixed || [ message [ :kind ] , :all ] . include? ( configuration . error_level )
177179
180+ message [ :context ] = get_context ( message ) if configuration . with_context
181+
178182 if configuration . json || configuration . sarif || configuration . codeclimate_report_file
179- message [ 'context' ] = get_context ( message ) if configuration . with_context
180183 json << message
181184 end
182185
183- next if configuration . json || configuration . sarif
184-
185- format_message ( message )
186- print_context ( message ) if configuration . with_context
187- print_github_annotation ( message ) if configuration . github_actions
186+ unless configuration . json || configuration . sarif
187+ format_message ( message )
188+ print_github_annotation ( message ) if configuration . github_actions
189+ end
188190 end
189191 $stderr. puts 'Try running `puppet parser validate <file>`' if problems . any? { |p | p [ :check ] == :syntax }
190192 json
0 commit comments