-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'base_report' | ||
|
||
module Reek | ||
module Report | ||
# | ||
# Displays smells as GitHub Workflow commands. | ||
# | ||
# @public | ||
# | ||
class GithubReport < BaseReport | ||
def show(out = $stdout) | ||
out.print(workflow_commands.join) | ||
end | ||
|
||
private | ||
|
||
def workflow_commands | ||
smells.map do |smell| | ||
WorkflowCommand.new(smell) | ||
end | ||
end | ||
|
||
# Represents a smell as a GitHub Workflow command. | ||
class WorkflowCommand | ||
def initialize(smell) | ||
@smell = smell | ||
end | ||
|
||
def to_s | ||
format( | ||
"::warning file=%<file>s,line=%<line>d::%<message>s\n", | ||
file: file, | ||
line: line, | ||
message: message) | ||
end | ||
|
||
private | ||
|
||
def file | ||
@smell.source | ||
end | ||
|
||
def line | ||
@smell.lines.first | ||
end | ||
|
||
def message | ||
@smell.base_message.gsub('%', '%25').gsub("\r", '%0D').gsub("\n", '%0A') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative '../../spec_helper' | ||
require_lib 'reek/examiner' | ||
require_lib 'reek/report/json_report' | ||
|
||
RSpec.describe Reek::Report::GithubReport do | ||
let(:instance) do | ||
described_class.new | ||
end | ||
|
||
let(:examiner) do | ||
Reek::Examiner.new(source) | ||
end | ||
|
||
context 'with empty source' do | ||
let(:source) do | ||
'' | ||
end | ||
|
||
it 'prints empty string' do | ||
instance.add_examiner(examiner) | ||
expect { instance.show }.not_to output.to_stdout | ||
end | ||
end | ||
|
||
context 'with smelly source' do | ||
let(:source) do | ||
<<~RUBY | ||
def simple(a) | ||
a[3] | ||
end | ||
RUBY | ||
end | ||
|
||
it 'prints smells as GitHub Workflow commands' do | ||
instance.add_examiner(examiner) | ||
expect { instance.show }.to output( | ||
<<~TEXT | ||
::warning file=string,line=1::UncommunicativeParameterName: simple has the parameter name 'a' | ||
::warning file=string,line=1::UtilityFunction: simple doesn't depend on instance state (maybe move it to another class?) | ||
TEXT | ||
).to_stdout | ||
end | ||
end | ||
end |