Skip to content

Commit

Permalink
Integrate Rubocop into Danger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Jul 3, 2016
1 parent 93cf3fd commit d9314d1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
AllCops:
DisplayCopNames: true

Metrics/LineLength:
Max: 120

Expand Down
21 changes: 20 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,28 @@ end

# Warn about un-updated tests
if has_app_changes && !has_test_changes
warn "Tests were not updated"
warn 'Tests were not updated'
end

if github.pr_body.length < 5
fail 'Please provide a summary in the Pull Request description'
end

# TODO: This could be a danger plugin
files_to_lint = (modified_files + added_files).select { |f| f.end_with? 'rb' }
rubocop_results = files_to_lint.map { |f| JSON.parse(`bundle exec rubocop -f json #{f}`)['files'] }.flatten
offending_files = rubocop_results.select { |f| f['offenses'].count > 0 }

unless offending_files.empty?
message = '### Rubocop violations'
message << 'File | Line | Reason |\n'
message << '| --- | ----- | ----- |\n'

offending_files.each do |f|
f['offenses'].each do |o|
message << "#{f['path']} | #{o['location']['line']} | #{o['message']} \n"
end
end

markdown message
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ group :test do
gem 'rspec-mocks'

gem 'danger'
gem 'rspec_junit_formatter'
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GEM
specs:
addressable (2.4.0)
ast (2.3.0)
builder (3.2.2)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -100,6 +101,9 @@ GEM
rspec-sinatra (0.1.2)
templater (>= 1.0.0)
rspec-support (3.5.0)
rspec_junit_formatter (0.2.3)
builder (< 4)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.41.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
Expand Down Expand Up @@ -142,6 +146,7 @@ DEPENDENCIES
rspec
rspec-mocks
rspec-sinatra
rspec_junit_formatter
rubocop
sinatra

Expand Down
1 change: 0 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
test:
override:
- bundle exec rspec
- bundle exec rubocop
- bundle exec danger
1 change: 1 addition & 0 deletions rubocop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"metadata":{"rubocop_version":"0.41.1","ruby_engine":"ruby","ruby_version":"2.2.5","ruby_patchlevel":"319","ruby_platform":"x86_64-darwin15"},"files":[{"path":"config.ru","offenses":[]},{"path":"Gemfile","offenses":[]},{"path":"Guardfile","offenses":[]},{"path":"lib/api.rb","offenses":[]},{"path":"lib/ping_checker.rb","offenses":[{"severity":"convention","message":"Extra empty line detected at class body beginning.","cop_name":"Style/EmptyLinesAroundClassBody","corrected":false,"location":{"line":2,"column":1,"length":1}},{"severity":"convention","message":"Space inside square brackets detected.","cop_name":"Style/SpaceInsideBrackets","corrected":false,"location":{"line":4,"column":10,"length":1}}]},{"path":"lib/server.rb","offenses":[]},{"path":"lib/signature_verifier.rb","offenses":[]},{"path":"spec/api_spec.rb","offenses":[]},{"path":"spec/ping_checker_spec.rb","offenses":[]},{"path":"spec/server_spec.rb","offenses":[]},{"path":"spec/signature_verifier_spec.rb","offenses":[]},{"path":"spec/spec_helper.rb","offenses":[]}],"summary":{"offense_count":2,"target_file_count":12,"inspected_file_count":12}}

0 comments on commit d9314d1

Please sign in to comment.