danger-rubocop 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/danger_plugin.rb +14 -0
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59cd45d4ce8230e467669d6b3a3ffdfe3c1e7f9
|
4
|
+
data.tar.gz: f151f971948bba931f159166bc01cc4ad00d21c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/danger_plugin.rb
CHANGED
@@ -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|
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger
|