-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
5e0fe57
commit 3a32a9d
Showing
14 changed files
with
311 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Inquisition | ||
module Outputter | ||
class Doc | ||
module TPL | ||
class Quality | ||
class Rubocop | ||
def self.call(issues) | ||
new( | ||
Security::Collector.new(issues, ::Inquisition::Rubocop::Runner).call | ||
) | ||
end | ||
|
||
EXTENSIONS = %w[rubocop-rspec rubocop-rails rubocop-performance rubocop-rake rubocop-md].freeze | ||
attr_reader :collection | ||
|
||
def initialize(collection) | ||
@collection = collection | ||
end | ||
|
||
def extensions | ||
EXTENSIONS.each do |gem| | ||
next if locked_gems.key?(gem) | ||
|
||
extension = TPL::Stack::Collector.new([gem]).call.first | ||
yield(extension&.name || gem, extension&.homepage) | ||
end | ||
end | ||
|
||
def produce | ||
binding | ||
end | ||
|
||
def autocorrect_issues | ||
collection.group_by(&:context).fetch(:corrected, []) | ||
end | ||
|
||
def inspect_files | ||
collection&.first&.runner&.modified_runner&.target_files || [] | ||
end | ||
|
||
def contains_rubocop | ||
locked_gems.key?('rubocop') ? 'present' : 'absent' | ||
end | ||
|
||
def link | ||
@link ||= Stack::Collector.new(['rubocop']).call.first.homepage | ||
end | ||
|
||
private | ||
|
||
def locked_gems | ||
@locked_gems ||= ::Bundler.locked_gems.dependencies | ||
end | ||
end | ||
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
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,10 @@ | ||
module Inquisition | ||
module Rubocop | ||
class Offense < ::RuboCop::Cop::Team | ||
def offenses(processed_source) | ||
autocorrect_cops, other_cops = cops.partition(&:autocorrect?) | ||
investigate(autocorrect_cops, processed_source).offenses + investigate(other_cops, processed_source).offenses | ||
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
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
149 changes: 149 additions & 0 deletions
149
spec/inquisition/outputter/doc/tpl/quality/rubocop_spec.rb
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,149 @@ | ||
RSpec.describe Inquisition::Outputter::Doc::TPL::Quality::Rubocop do | ||
include_examples 'produceable' do | ||
subject(:tpl) { described_class.new([]) } | ||
end | ||
|
||
let(:issue) do | ||
Inquisition::Issue.new( | ||
category: Inquisition::Category::SECURITY, | ||
path: 'app/controllers/users_controller.rb', | ||
line: 42, | ||
severity: Inquisition::Severity::LOW, | ||
message: 'Metrics/LineLength: Line is too long. [132/125]', | ||
context: :unsupported, | ||
runner: Inquisition::Rubocop::Runner.new | ||
) | ||
end | ||
|
||
describe '.call' do | ||
let(:issue) { instance_double(Inquisition::Issue) } | ||
let(:collector) { instance_double(Inquisition::Outputter::Doc::TPL::Security::Collector) } | ||
|
||
before do | ||
allow(Inquisition::Outputter::Doc::TPL::Security::Collector).to receive(:new).and_return(collector) | ||
allow(collector).to receive(:call).and_return([issue]) | ||
allow(described_class).to receive(:new) | ||
|
||
described_class.call([issue]) | ||
end | ||
|
||
it do | ||
expect(Inquisition::Outputter::Doc::TPL::Security::Collector).to have_received(:new) | ||
.with([issue], ::Inquisition::Rubocop::Runner) | ||
end | ||
|
||
it { expect(described_class).to have_received(:new) } | ||
end | ||
|
||
describe 'link' do | ||
subject(:link) { described_class.new([]).link } | ||
|
||
let(:stack) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) } | ||
let(:struct) { double(OpenStruct, homepage: 'https://github.com/rubocop-hq/rubocop') } | ||
|
||
before do | ||
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new).with(['rubocop']).and_return(stack) | ||
allow(stack).to receive(:call).and_return([struct]) | ||
end | ||
|
||
it do | ||
expect(link).to eq(struct.homepage) | ||
end | ||
end | ||
|
||
describe '#extensions' do | ||
subject(:rubocop) { described_class.new([]) } | ||
|
||
let(:bundler_gems) { instance_double(Bundler::LockfileParser, dependencies: dependency) } | ||
let(:dependency) do | ||
{ 'rubocop-rspec' => '', 'rubocop-performance' => '', 'rubocop-rake' => '', 'rubocop-md' => '' } | ||
end | ||
let(:absent_gem) { 'rubocop-rails' } | ||
let(:stack_collector) { instance_double(Inquisition::Outputter::Doc::TPL::Stack::Collector) } | ||
let(:struct) { double(OpenStruct, name: absent_gem, homepage: 'https://github.com/rubocop-hq/rubocop-rails') } | ||
|
||
before do | ||
allow(Bundler).to receive(:locked_gems).and_return(bundler_gems) | ||
allow(Inquisition::Outputter::Doc::TPL::Stack::Collector).to receive(:new) | ||
.with([absent_gem]).and_return(stack_collector) | ||
allow(stack_collector).to receive(:call).and_return([struct]) | ||
end | ||
|
||
it do | ||
expect do |block| | ||
rubocop.extensions(&block) | ||
end.to yield_with_args(absent_gem, struct.homepage) | ||
end | ||
end | ||
|
||
describe '#inspect_files' do | ||
subject(:inspect_files) { described_class.new(issues).inspect_files } | ||
|
||
let(:instance_modified_runner) do | ||
instance_double(Inquisition::Rubocop::RubocopModifiedRunner, | ||
target_files: ['app/controllers/application_controller.rb']) | ||
end | ||
|
||
context 'when collection exists' do | ||
let(:issues) { [issue] } | ||
|
||
before { allow(issue.runner).to receive(:modified_runner).and_return(instance_modified_runner) } | ||
|
||
it { expect(inspect_files).to eq(instance_modified_runner.target_files) } | ||
end | ||
|
||
context 'when collection not exists' do | ||
let(:issues) { [] } | ||
|
||
it { expect(inspect_files).to eq([]) } | ||
end | ||
end | ||
|
||
describe '#contains_rubocop' do | ||
subject(:contains_rubocop) { described_class.new([]).contains_rubocop } | ||
|
||
let(:bundler_gems) { instance_double(Bundler::LockfileParser, dependencies: dependency) } | ||
|
||
before { allow(Bundler).to receive(:locked_gems).and_return(bundler_gems) } | ||
|
||
context 'when gem present' do | ||
let(:dependency) { { 'rubocop' => '' } } | ||
|
||
it { expect(contains_rubocop).to eq('present') } | ||
end | ||
|
||
context 'when gem absent' do | ||
let(:dependency) { {} } | ||
|
||
it { expect(contains_rubocop).to eq('absent') } | ||
end | ||
end | ||
|
||
describe '#autocorrect_issues' do | ||
subject(:autocorrect_issues) { described_class.new(issues).autocorrect_issues } | ||
|
||
context 'when collection exists' do | ||
let(:issues) { [issue, issue_autocorrect] } | ||
|
||
let(:issue_autocorrect) do | ||
Inquisition::Issue.new( | ||
category: Inquisition::Category::SECURITY, | ||
path: 'app/controllers/users_controller.rb', | ||
line: 42, | ||
severity: Inquisition::Severity::LOW, | ||
message: 'Metrics/LineLength: Line is too long. [132/125]', | ||
context: :corrected, | ||
runner: Inquisition::Rubocop::Runner.new | ||
) | ||
end | ||
|
||
it { expect(autocorrect_issues).to eq([issue_autocorrect]) } | ||
end | ||
|
||
context 'when collection not exists' do | ||
let(:issues) { [] } | ||
|
||
it { expect(autocorrect_issues).to eq([]) } | ||
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
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,19 @@ | ||
RSpec.describe Inquisition::Rubocop::Offense do | ||
let(:offense) { described_class.new(registry, config, {}).offenses(processed_source) } | ||
|
||
let(:config) { instance_double(RuboCop::Config) } | ||
let(:registry) { instance_double(RuboCop::Cop::Registry) } | ||
let(:processed_source) { instance_double(RuboCop::ProcessedSource) } | ||
|
||
it { expect(described_class).to be < RuboCop::Cop::Team } | ||
|
||
describe '#offenses' do | ||
before { allow(registry).to receive(:enabled).and_return([]) } | ||
|
||
context 'when valid_syntax? for processed_source returns true' do | ||
it 'returns offenses' do | ||
expect(offense).to be_empty | ||
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
Oops, something went wrong.