danger-rubocop 0.9.5 → 0.11.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: 14d031b9e478c7bff00e541dd0637352a01888939c18ddf48a738525f0954b08
4
- data.tar.gz: 4894183f30dbfc5a1b615d93e6361a7ed1f3b828a86a67e0f47abfd2e1dd8f6f
3
+ metadata.gz: 7a25805f10b9265549f39e7efb812f9b940d317727b031a8546aaa34e87a6f57
4
+ data.tar.gz: 553e742ad2d0780f441a0bb443bcc24b18afd2d26a78fec7cb92b9f7b5abafe1
5
5
  SHA512:
6
- metadata.gz: 01a34d01243770479c10ce9442655cd00b53ad8cceb3b832afd6ff081de84bb817a0996a083098909da41089de3b63af11eeaba51b6ab81ff075ed5a86fb7afd
7
- data.tar.gz: c7e02e4b2389c7d35c33f93b9175a30d9a4ab05a7636e4bf80cd4851e164e039130af6abbd360778ff35ce638492a88cb5742c9ccb0b8cce47ec36e115f5a5e2
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,22 +125,21 @@ 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']
131
132
  offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
132
- arguments = [
133
- offense_message,
134
- {
135
- file: file['path'],
136
- line: offense['location']['line']
137
- }
138
- ]
133
+ kargs = {
134
+ file: file['path'],
135
+ line: offense['location']['line']
136
+ }
139
137
  if fail_on_inline_comment
140
- fail(*arguments)
138
+ fail(offense_message, **kargs)
139
+ elsif report_severity && %w[error fatal].include?(offense['severity'])
140
+ fail(offense_message, **kargs)
141
141
  else
142
- warn(*arguments)
142
+ warn(offense_message, **kargs)
143
143
  end
144
144
  end
145
145
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.9.5'.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.9.5
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: 2021-06-04 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.0.2
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.