danger-rubocop 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 123e71c280e842bce2f03b4b6057a4e838a5337b
4
- data.tar.gz: 896db4ec175e20179a7b4b23d6be8b2d01426953
3
+ metadata.gz: c59cd45d4ce8230e467669d6b3a3ffdfe3c1e7f9
4
+ data.tar.gz: f151f971948bba931f159166bc01cc4ad00d21c6
5
5
  SHA512:
6
- metadata.gz: 3ee6a09ae722401c210e4cbf2c3d5ba825bfbcd16bcf533ab8c596d752d983ae9ffe2067cb04605fcaf361b7d3576563b60880cb8d09844b4fb87fe34999fa7f
7
- data.tar.gz: 8248e12f7f623e3382807fd69210f14833f0e9878196fca099101c21dc93fb63d4f074f47c579090626d70add350a24d10d08149f740303786b0ee4c3fc33268
6
+ metadata.gz: e10b05bfaf61a28f2d36208ca1bd1136fcad1106b8114586fc8cfc6e5a2282782fe9a30a07e962a12df3856791bdab2eb340a818e5689b1a372fedc468c35b5e
7
+ data.tar.gz: f742ec5a40f95ad439a01d9026216ca14643fd3ffec8b2f836c792f7e83da7939fbf3c10e0aca42f83cf08f46a8622b4041b493815066d0293752db21c5c1feb
data/README.md CHANGED
@@ -43,6 +43,7 @@ The following keys are supported:
43
43
  * `files`: array of file names or glob patterns to determine files to lint
44
44
  * `force_exclusion`: pass `true` to pass `--force-exclusion` argument to Rubocop.
45
45
  * `inline_comment`: pass `true` to comment inline of the diffs.
46
+ * `report_danger`: pass true to report errors to Danger, and break CI.
46
47
 
47
48
  (this option will instruct rubocop to ignore the files that your rubocop config ignores,
48
49
  despite the plugin providing the list of files explicitely)
@@ -30,18 +30,22 @@ module Danger
30
30
  config = config.is_a?(Hash) ? config : { files: config }
31
31
  files = config[:files]
32
32
  force_exclusion = config[:force_exclusion] || false
33
+
34
+ report_danger = config[:report_danger] || false
33
35
  inline_comment = config[:inline_comment] || false
34
36
 
35
37
  files_to_lint = fetch_files_to_lint(files)
36
38
  files_to_report = rubocop(files_to_lint, force_exclusion)
37
39
 
38
40
  return if files_to_report.empty?
41
+ return report_failures files_to_report if report_danger
39
42
 
40
43
  if inline_comment
41
44
  warn_each_line(files_to_report)
42
45
  else
43
46
  markdown offenses_message(files_to_report)
44
47
  end
48
+
45
49
  end
46
50
 
47
51
  private
@@ -52,6 +56,8 @@ module Danger
52
56
 
53
57
  rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command} #{files_to_lint}`
54
58
 
59
+ return [] if rubocop_output.empty?
60
+
55
61
  JSON.parse(rubocop_output)['files']
56
62
  .select { |f| f['offenses'].any? }
57
63
  end
@@ -72,6 +78,14 @@ module Danger
72
78
  message + table.split("\n")[1..-2].join("\n")
73
79
  end
74
80
 
81
+ def report_failures(offending_files)
82
+ offending_files.each do |file|
83
+ file['offenses'].each do |offense|
84
+ fail "#{file['path']} | #{offense['location']['line']} | #{offense['message']}"
85
+ end
86
+ end
87
+ end
88
+
75
89
  def warn_each_line(offending_files)
76
90
  offending_files.flat_map do |file|
77
91
  file['offenses'].map do |offense|
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -127,6 +127,7 @@ module Danger
127
127
  | spec/fixtures/ruby_file.rb | 13 | Don't do that! |
128
128
  EOS
129
129
  expect(@rubocop.status_report[:markdowns].first.message).to eq(formatted_table.chomp)
130
+ expect(@rubocop).not_to receive(:fail)
130
131
  end
131
132
 
132
133
  it 'is reported as line by line' do
@@ -157,6 +158,21 @@ EOS
157
158
  expect { @rubocop.lint }.not_to raise_error
158
159
  end
159
160
  end
161
+
162
+ describe 'report to danger' do
163
+ let(:fail_msg) { %{spec/fixtures/ruby_file.rb | 13 | Don't do that!} }
164
+ it 'reports to danger' do
165
+ allow(@rubocop.git).to receive(:modified_files)
166
+ .and_return(['spec/fixtures/ruby_file.rb'])
167
+ allow(@rubocop.git).to receive(:added_files).and_return([])
168
+ allow(@rubocop).to receive(:`)
169
+ .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
170
+ .and_return(response_ruby_file)
171
+
172
+ expect(@rubocop).to receive(:fail).with(fail_msg)
173
+ @rubocop.lint(report_danger: true)
174
+ end
175
+ end
160
176
  end
161
177
  end
162
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger