danger-rubocop 0.10.0 → 0.11.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
  SHA256:
3
- metadata.gz: e91901b79a6155f5d70feebbbd301fad023ea8a8fd4a37e8f04fe413d3859326
4
- data.tar.gz: 469efcdadad9b126197d88d0d0aeaa51497a3542f1e6bb0d66977d8d195facde
3
+ metadata.gz: 7a25805f10b9265549f39e7efb812f9b940d317727b031a8546aaa34e87a6f57
4
+ data.tar.gz: 553e742ad2d0780f441a0bb443bcc24b18afd2d26a78fec7cb92b9f7b5abafe1
5
5
  SHA512:
6
- metadata.gz: d40eb3980c2456134e43cd12c0bb2dc7c0c2fce9739e8585a489c6db364f1c38a08e1576b16359a1da71e628ffe308b70b98ae58e5a2fbff38e2f679fff53cc5
7
- data.tar.gz: a4d1dd07e6fa2f08498675ae3d1bef2faca730506cdbeb895b3c2586e8f28fb638bff4af95b2816faff68d7086a8f9da08abaebf743302588480e2e6ec9f881f
6
+ metadata.gz: df8c319c5b617f7ee5e2698e0db2d2610eeac3007dc3b5d183261295608aaba1805ae496f3b70897a7570bc79f222ed8be6f1af6859d3a0b5d2f6090377a297c
7
+ data.tar.gz: 8611653f86ad51b236dd4f4b7104e4776c8748d30cfdbc47f70bad2e82580aff9e46b8b8726ccfd1261f48e719ac3459b123871864ca0ddda5ff87e86d5a06d2
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)
@@ -99,7 +99,7 @@ GEM
99
99
  pry (0.14.1)
100
100
  coderay (~> 1.1)
101
101
  method_source (~> 1.0)
102
- public_suffix (4.0.6)
102
+ public_suffix (5.0.0)
103
103
  rainbow (3.0.0)
104
104
  rake (13.0.3)
105
105
  rb-fsevent (0.10.4)
data/README.md CHANGED
@@ -58,6 +58,7 @@ 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.
62
63
  * `config`: path to the `.rubocop.yml` file.
63
64
  * `only_report_new_offenses`: pass `true` to only report offenses that are in current user's 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
 
@@ -45,7 +46,7 @@ module Danger
45
46
  return report_failures files_to_report 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
@@ -124,7 +125,7 @@ module Danger
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
131
  offense_message = offense['message']
@@ -135,6 +136,8 @@ module Danger
135
136
  }
136
137
  if fail_on_inline_comment
137
138
  fail(offense_message, **kargs)
139
+ elsif report_severity && %w[error fatal].include?(offense['severity'])
140
+ fail(offense_message, **kargs)
138
141
  else
139
142
  warn(offense_message, **kargs)
140
143
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.10.0'.freeze
2
+ VERSION = '0.11.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
  ]
@@ -313,6 +315,44 @@ EOS
313
315
  end
314
316
  end
315
317
 
318
+ context 'with report_severity option' do
319
+ context 'file with error' do
320
+ it 'reports violations by rubocop severity' do
321
+ allow(@rubocop.git).to receive(:added_files).and_return([])
322
+ allow(@rubocop.git).to receive(:modified_files)
323
+ .and_return(["spec/fixtures/another_ruby_file.rb"])
324
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
325
+
326
+ allow(@rubocop).to receive(:`)
327
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/another_ruby_file.rb')
328
+ .and_return(response_another_ruby_file)
329
+
330
+ @rubocop.lint(report_severity: true, inline_comment: true)
331
+
332
+ expect(@rubocop.violation_report[:errors].first.to_s)
333
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/another_ruby_file.rb, line: 23, type: error }")
334
+ end
335
+ end
336
+
337
+ context 'file with warning' do
338
+ it 'reports violations by rubocop severity' do
339
+ allow(@rubocop.git).to receive(:added_files).and_return([])
340
+ allow(@rubocop.git).to receive(:modified_files)
341
+ .and_return(["spec/fixtures/ruby_file.rb"])
342
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
343
+
344
+ allow(@rubocop).to receive(:`)
345
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
346
+ .and_return(response_ruby_file)
347
+
348
+ @rubocop.lint(report_severity: true, inline_comment: true)
349
+
350
+ expect(@rubocop.violation_report[:warnings].first.to_s)
351
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: warning }")
352
+ end
353
+ end
354
+ end
355
+
316
356
  context 'using standardrb cmd' do
317
357
  it 'executes using the standardrb cmd' do
318
358
  allow(@rubocop).to receive(:`)
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.11.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-05-16 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.3.13
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: A Danger plugin for running Ruby files through Rubocop.