danger-rubocop 0.10.0 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e91901b79a6155f5d70feebbbd301fad023ea8a8fd4a37e8f04fe413d3859326
4
- data.tar.gz: 469efcdadad9b126197d88d0d0aeaa51497a3542f1e6bb0d66977d8d195facde
3
+ metadata.gz: e62c69c270c52a9db56563f52892f3e3f04ac0f154a70144f20ef66f2a5db517
4
+ data.tar.gz: 7db336caf7afd0d8574a66096ee0276b9e92f725d914e57e5720bfe6a83fc27a
5
5
  SHA512:
6
- metadata.gz: d40eb3980c2456134e43cd12c0bb2dc7c0c2fce9739e8585a489c6db364f1c38a08e1576b16359a1da71e628ffe308b70b98ae58e5a2fbff38e2f679fff53cc5
7
- data.tar.gz: a4d1dd07e6fa2f08498675ae3d1bef2faca730506cdbeb895b3c2586e8f28fb638bff4af95b2816faff68d7086a8f9da08abaebf743302588480e2e6ec9f881f
6
+ metadata.gz: e88de395cb97400f569e38461f45dfd978483bbaf42f048865b4e3f33fefb86632c5ca55f63796cb45a5f5947065200cb6e2bc35fcaa3f42c932c565de7d2cb8
7
+ data.tar.gz: c192a3cf0f8b3b199d2e6526c3df8f73c96cffed6cb683f7216dfd00ff9a2c92c83cac77bca63b28eabc215f26bae67c003737977ea112c62d2b73dcb4939c8f
data/Gemfile.lock CHANGED
@@ -8,8 +8,8 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
13
  ast (2.4.2)
14
14
  bacon (1.2.0)
15
15
  claide (1.0.3)
@@ -52,7 +52,8 @@ GEM
52
52
  faraday-net_http_persistent (1.1.0)
53
53
  ffi (1.15.0)
54
54
  formatador (0.2.5)
55
- git (1.8.1)
55
+ git (1.13.1)
56
+ addressable (~> 2.8)
56
57
  rchardet (~> 1.8)
57
58
  guard (2.16.2)
58
59
  formatador (>= 0.2.4)
@@ -99,7 +100,7 @@ GEM
99
100
  pry (0.14.1)
100
101
  coderay (~> 1.1)
101
102
  method_source (~> 1.0)
102
- public_suffix (4.0.6)
103
+ public_suffix (5.0.0)
103
104
  rainbow (3.0.0)
104
105
  rake (13.0.3)
105
106
  rb-fsevent (0.10.4)
data/README.md CHANGED
@@ -58,7 +58,9 @@ The following keys are supported:
58
58
  despite the plugin providing the list of files explicitly)
59
59
  * `inline_comment`: pass `true` to comment inline of the diffs.
60
60
  * `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
61
+ * `report_severity`: pass `true` to use `fail` or `warn` based on Rubocop severity.
61
62
  * `report_danger`: pass true to report errors to Danger, and break CI.
63
+ * `include_cop_names`: pass true to include cop names when reporting errors with `report_danger`.
62
64
  * `config`: path to the `.rubocop.yml` file.
63
65
  * `only_report_new_offenses`: pass `true` to only report offenses that are in current user's scope.
64
66
  Note that this won't mark offenses for _Metrics/XXXLength_ if you add lines to an already existing scope.
data/lib/danger_plugin.rb CHANGED
@@ -35,6 +35,7 @@ module Danger
35
35
  only_report_new_offenses = config[:only_report_new_offenses] || false
36
36
  inline_comment = config[:inline_comment] || false
37
37
  fail_on_inline_comment = config[:fail_on_inline_comment] || false
38
+ report_severity = config[:report_severity] || false
38
39
  include_cop_names = config[:include_cop_names] || false
39
40
  rubocop_cmd = config[:rubocop_cmd] || 'rubocop'
40
41
 
@@ -42,10 +43,10 @@ module Danger
42
43
  files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: rubocop_cmd, config_path: config_path)
43
44
 
44
45
  return if files_to_report.empty?
45
- return report_failures files_to_report if report_danger
46
+ return report_failures(files_to_report, include_cop_names: include_cop_names) if report_danger
46
47
 
47
48
  if inline_comment
48
- add_violation_for_each_line(files_to_report, fail_on_inline_comment, include_cop_names: include_cop_names)
49
+ add_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
49
50
  else
50
51
  markdown offenses_message(files_to_report, include_cop_names: include_cop_names)
51
52
  end
@@ -107,8 +108,7 @@ module Danger
107
108
  style: { border_i: '|' },
108
109
  rows: offending_files.flat_map do |file|
109
110
  file['offenses'].map do |offense|
110
- offense_message = offense['message']
111
- offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
111
+ offense_message = offense_message(offense, include_cop_names: include_cop_names)
112
112
  [file['path'], offense['location']['line'], offense_message]
113
113
  end
114
114
  end
@@ -116,25 +116,27 @@ module Danger
116
116
  message + table.split("\n")[1..-2].join("\n")
117
117
  end
118
118
 
119
- def report_failures(offending_files)
119
+ def report_failures(offending_files, include_cop_names: false)
120
120
  offending_files.each do |file|
121
121
  file['offenses'].each do |offense|
122
- fail "#{file['path']} | #{offense['location']['line']} | #{offense['message']}"
122
+ offense_message = offense_message(offense, include_cop_names: include_cop_names)
123
+ fail "#{file['path']} | #{offense['location']['line']} | #{offense_message}"
123
124
  end
124
125
  end
125
126
  end
126
127
 
127
- def add_violation_for_each_line(offending_files, fail_on_inline_comment, include_cop_names: false)
128
+ def add_violation_for_each_line(offending_files, fail_on_inline_comment, report_severity, include_cop_names: false)
128
129
  offending_files.flat_map do |file|
129
130
  file['offenses'].map do |offense|
130
- offense_message = offense['message']
131
- offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
131
+ offense_message = offense_message(offense, include_cop_names: include_cop_names)
132
132
  kargs = {
133
133
  file: file['path'],
134
134
  line: offense['location']['line']
135
135
  }
136
136
  if fail_on_inline_comment
137
137
  fail(offense_message, **kargs)
138
+ elsif report_severity && %w[error fatal].include?(offense['severity'])
139
+ fail(offense_message, **kargs)
138
140
  else
139
141
  warn(offense_message, **kargs)
140
142
  end
@@ -152,5 +154,11 @@ module Danger
152
154
  end
153
155
  Shellwords.join(to_lint)
154
156
  end
157
+
158
+ def offense_message(offense, include_cop_names: false)
159
+ return offense['message'] unless include_cop_names
160
+
161
+ "#{offense['cop_name']}: #{offense['message']}"
162
+ end
155
163
  end
156
164
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.10.0'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
@@ -149,6 +149,7 @@ module Danger
149
149
  {
150
150
  'cop_name' => 'Syntax/WhetherYouShouldDoThat',
151
151
  'message' => "Don't do that!",
152
+ 'severity' => 'warning',
152
153
  'location' => { 'line' => 13 }
153
154
  }
154
155
  ]
@@ -166,6 +167,7 @@ module Danger
166
167
  {
167
168
  'cop_name' => 'Syntax/WhetherYouShouldDoThat',
168
169
  'message' => "Don't do that!",
170
+ 'severity' => 'error',
169
171
  'location' => { 'line' => 23 }
170
172
  }
171
173
  ]
@@ -297,7 +299,7 @@ EOS
297
299
  end
298
300
 
299
301
  context 'with fail_on_inline_comment option' do
300
- it 'reports violations as line by line failures' do
302
+ before do
301
303
  allow(@rubocop.git).to receive(:modified_files)
302
304
  .and_return(['spec/fixtures/ruby_file.rb'])
303
305
  allow(@rubocop.git).to receive(:added_files).and_return([])
@@ -305,26 +307,73 @@ EOS
305
307
  allow(@rubocop).to receive(:`)
306
308
  .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
307
309
  .and_return(response_ruby_file)
310
+ end
308
311
 
312
+ it 'reports violations as line by line failures' do
309
313
  @rubocop.lint(fail_on_inline_comment: true, inline_comment: true)
310
314
 
311
315
  expect(@rubocop.violation_report[:errors].first.to_s)
312
316
  .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
313
317
  end
318
+
319
+ it 'includes cop names when include_cop_names is set' do
320
+ @rubocop.lint(fail_on_inline_comment: true, inline_comment: true, include_cop_names: true)
321
+
322
+ expect(@rubocop.violation_report[:errors].first.to_s)
323
+ .to eq("Violation Syntax/WhetherYouShouldDoThat: Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
324
+ end
314
325
  end
326
+ end
327
+
328
+ context 'with report_severity option' do
329
+ context 'file with error' do
330
+ it 'reports violations by rubocop severity' do
331
+ allow(@rubocop.git).to receive(:added_files).and_return([])
332
+ allow(@rubocop.git).to receive(:modified_files)
333
+ .and_return(["spec/fixtures/another_ruby_file.rb"])
334
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
315
335
 
316
- context 'using standardrb cmd' do
317
- it 'executes using the standardrb cmd' do
318
336
  allow(@rubocop).to receive(:`)
319
- .with('bundle exec standardrb -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
320
- .and_return(response_ruby_file)
337
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/another_ruby_file.rb')
338
+ .and_return(response_another_ruby_file)
339
+
340
+ @rubocop.lint(report_severity: true, inline_comment: true)
321
341
 
322
- # Do it
323
- @rubocop.lint(files: 'spec/fixtures/ruby*.rb', rubocop_cmd: 'standardrb', config: 'path/to/rubocop.yml')
342
+ expect(@rubocop.violation_report[:errors].first.to_s)
343
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/another_ruby_file.rb, line: 23, type: error }")
324
344
  end
325
345
  end
326
346
  end
327
347
 
348
+ context 'file with warning' do
349
+ it 'reports violations by rubocop severity' do
350
+ allow(@rubocop.git).to receive(:added_files).and_return([])
351
+ allow(@rubocop.git).to receive(:modified_files)
352
+ .and_return(["spec/fixtures/ruby_file.rb"])
353
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
354
+
355
+ allow(@rubocop).to receive(:`)
356
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
357
+ .and_return(response_ruby_file)
358
+
359
+ @rubocop.lint(report_severity: true, inline_comment: true)
360
+
361
+ expect(@rubocop.violation_report[:warnings].first.to_s)
362
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: warning }")
363
+ end
364
+ end
365
+
366
+ context 'using standardrb cmd' do
367
+ it 'executes using the standardrb cmd' do
368
+ allow(@rubocop).to receive(:`)
369
+ .with('bundle exec standardrb -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
370
+ .and_return(response_ruby_file)
371
+
372
+ # Do it
373
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb', rubocop_cmd: 'standardrb', config: 'path/to/rubocop.yml')
374
+ end
375
+ end
376
+
328
377
  describe 'a filename with special characters' do
329
378
  it 'is shell escaped' do
330
379
  modified_files = [
@@ -342,8 +391,7 @@ EOS
342
391
  end
343
392
 
344
393
  describe 'report to danger' do
345
- let(:fail_msg) { %{spec/fixtures/ruby_file.rb | 13 | Don't do that!} }
346
- it 'reports to danger' do
394
+ before do
347
395
  allow(@rubocop.git).to receive(:modified_files)
348
396
  .and_return(['spec/fixtures/ruby_file.rb'])
349
397
  allow(@rubocop.git).to receive(:added_files).and_return([])
@@ -351,10 +399,20 @@ EOS
351
399
  allow(@rubocop).to receive(:`)
352
400
  .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
353
401
  .and_return(response_ruby_file)
402
+ end
354
403
 
404
+ it 'reports to danger' do
405
+ fail_msg = %{spec/fixtures/ruby_file.rb | 13 | Don't do that!}
355
406
  expect(@rubocop).to receive(:fail).with(fail_msg)
356
407
  @rubocop.lint(report_danger: true)
357
408
  end
409
+
410
+ it 'includes cop names when include_cop_names is set' do
411
+ fail_msg = %{spec/fixtures/ruby_file.rb | 13 | Syntax/WhetherYouShouldDoThat: Don't do that!}
412
+
413
+ expect(@rubocop).to receive(:fail).with(fail_msg)
414
+ @rubocop.lint(report_danger: true, include_cop_names: true)
415
+ end
358
416
  end
359
417
  end
360
418
  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.10.0
4
+ version: 0.12.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: 2022-03-08 00:00:00.000000000 Z
11
+ date: 2023-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubygems_version: 3.2.1
195
+ rubygems_version: 3.4.10
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: A Danger plugin for running Ruby files through Rubocop.