Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show some refactoring examples for PR #79 #83

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/puppet-lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def format_message(message)
puts format % message

puts " #{message[:reason]}" if message[:kind] == :ignored && !message[:reason].nil?
print_context(message)
end

# Internal: Format a problem message and print it to STDOUT so GitHub Actions
Expand Down Expand Up @@ -154,7 +155,8 @@ def get_context(message)
def print_context(message)
return if message[:check] == 'documentation'
return if message[:kind] == :fixed
line = get_context(message)
line = message[:context]
return unless line
offset = line.index(%r{\S}) || 1
puts "\n #{line.strip}"
printf("%#{message[:column] + 2 - offset}s\n\n", '^')
Expand All @@ -168,19 +170,21 @@ def print_context(message)
# Returns array of problem.
def report(problems)
json = []
print_stdout = !(configuration.json || configuration.sarif)

problems.each do |message|
next if message[:kind] == :ignored && !PuppetLint.configuration.show_ignored

message[:KIND] = message[:kind].to_s.upcase

next unless message[:kind] == :fixed || [message[:kind], :all].include?(configuration.error_level)

if configuration.json || configuration.sarif
message['context'] = get_context(message) if configuration.with_context
json << message
else
message[:context] = get_context(message) if configuration.with_context

json << message

if print_stdout
format_message(message)
print_context(message) if configuration.with_context
print_github_annotation(message) if configuration.github_actions
end
end
Expand Down