danger-rubocop 0.11.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 +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +1 -0
- data/lib/danger_plugin.rb +12 -7
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +57 -39
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62c69c270c52a9db56563f52892f3e3f04ac0f154a70144f20ef66f2a5db517
|
4
|
+
data.tar.gz: 7db336caf7afd0d8574a66096ee0276b9e92f725d914e57e5720bfe6a83fc27a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e88de395cb97400f569e38461f45dfd978483bbaf42f048865b4e3f33fefb86632c5ca55f63796cb45a5f5947065200cb6e2bc35fcaa3f42c932c565de7d2cb8
|
7
|
+
data.tar.gz: c192a3cf0f8b3b199d2e6526c3df8f73c96cffed6cb683f7216dfd00ff9a2c92c83cac77bca63b28eabc215f26bae67c003737977ea112c62d2b73dcb4939c8f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,7 @@ The following keys are supported:
|
|
60
60
|
* `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
|
61
61
|
* `report_severity`: pass `true` to use `fail` or `warn` based on Rubocop severity.
|
62
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`.
|
63
64
|
* `config`: path to the `.rubocop.yml` file.
|
64
65
|
* `only_report_new_offenses`: pass `true` to only report offenses that are in current user's scope.
|
65
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
@@ -43,7 +43,7 @@ module Danger
|
|
43
43
|
files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: rubocop_cmd, config_path: config_path)
|
44
44
|
|
45
45
|
return if files_to_report.empty?
|
46
|
-
return report_failures
|
46
|
+
return report_failures(files_to_report, include_cop_names: include_cop_names) if report_danger
|
47
47
|
|
48
48
|
if inline_comment
|
49
49
|
add_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
|
@@ -108,8 +108,7 @@ module Danger
|
|
108
108
|
style: { border_i: '|' },
|
109
109
|
rows: offending_files.flat_map do |file|
|
110
110
|
file['offenses'].map do |offense|
|
111
|
-
offense_message = offense
|
112
|
-
offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
|
111
|
+
offense_message = offense_message(offense, include_cop_names: include_cop_names)
|
113
112
|
[file['path'], offense['location']['line'], offense_message]
|
114
113
|
end
|
115
114
|
end
|
@@ -117,10 +116,11 @@ module Danger
|
|
117
116
|
message + table.split("\n")[1..-2].join("\n")
|
118
117
|
end
|
119
118
|
|
120
|
-
def report_failures(offending_files)
|
119
|
+
def report_failures(offending_files, include_cop_names: false)
|
121
120
|
offending_files.each do |file|
|
122
121
|
file['offenses'].each do |offense|
|
123
|
-
|
122
|
+
offense_message = offense_message(offense, include_cop_names: include_cop_names)
|
123
|
+
fail "#{file['path']} | #{offense['location']['line']} | #{offense_message}"
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -128,8 +128,7 @@ module Danger
|
|
128
128
|
def add_violation_for_each_line(offending_files, fail_on_inline_comment, report_severity, include_cop_names: false)
|
129
129
|
offending_files.flat_map do |file|
|
130
130
|
file['offenses'].map do |offense|
|
131
|
-
offense_message = offense
|
132
|
-
offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
|
131
|
+
offense_message = offense_message(offense, include_cop_names: include_cop_names)
|
133
132
|
kargs = {
|
134
133
|
file: file['path'],
|
135
134
|
line: offense['location']['line']
|
@@ -155,5 +154,11 @@ module Danger
|
|
155
154
|
end
|
156
155
|
Shellwords.join(to_lint)
|
157
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
|
158
163
|
end
|
159
164
|
end
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -299,7 +299,7 @@ EOS
|
|
299
299
|
end
|
300
300
|
|
301
301
|
context 'with fail_on_inline_comment option' do
|
302
|
-
|
302
|
+
before do
|
303
303
|
allow(@rubocop.git).to receive(:modified_files)
|
304
304
|
.and_return(['spec/fixtures/ruby_file.rb'])
|
305
305
|
allow(@rubocop.git).to receive(:added_files).and_return([])
|
@@ -307,61 +307,70 @@ EOS
|
|
307
307
|
allow(@rubocop).to receive(:`)
|
308
308
|
.with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
|
309
309
|
.and_return(response_ruby_file)
|
310
|
+
end
|
310
311
|
|
312
|
+
it 'reports violations as line by line failures' do
|
311
313
|
@rubocop.lint(fail_on_inline_comment: true, inline_comment: true)
|
312
314
|
|
313
315
|
expect(@rubocop.violation_report[:errors].first.to_s)
|
314
316
|
.to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
|
315
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
|
316
325
|
end
|
326
|
+
end
|
317
327
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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([])
|
325
335
|
|
326
|
-
|
327
|
-
|
328
|
-
|
336
|
+
allow(@rubocop).to receive(:`)
|
337
|
+
.with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/another_ruby_file.rb')
|
338
|
+
.and_return(response_another_ruby_file)
|
329
339
|
|
330
|
-
|
340
|
+
@rubocop.lint(report_severity: true, inline_comment: true)
|
331
341
|
|
332
|
-
|
333
|
-
|
334
|
-
end
|
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 }")
|
335
344
|
end
|
345
|
+
end
|
346
|
+
end
|
336
347
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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([])
|
343
354
|
|
344
|
-
|
345
|
-
|
346
|
-
|
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)
|
347
358
|
|
348
|
-
|
359
|
+
@rubocop.lint(report_severity: true, inline_comment: true)
|
349
360
|
|
350
|
-
|
351
|
-
|
352
|
-
end
|
353
|
-
end
|
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 }")
|
354
363
|
end
|
364
|
+
end
|
355
365
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
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)
|
361
371
|
|
362
|
-
|
363
|
-
|
364
|
-
end
|
372
|
+
# Do it
|
373
|
+
@rubocop.lint(files: 'spec/fixtures/ruby*.rb', rubocop_cmd: 'standardrb', config: 'path/to/rubocop.yml')
|
365
374
|
end
|
366
375
|
end
|
367
376
|
|
@@ -382,8 +391,7 @@ EOS
|
|
382
391
|
end
|
383
392
|
|
384
393
|
describe 'report to danger' do
|
385
|
-
|
386
|
-
it 'reports to danger' do
|
394
|
+
before do
|
387
395
|
allow(@rubocop.git).to receive(:modified_files)
|
388
396
|
.and_return(['spec/fixtures/ruby_file.rb'])
|
389
397
|
allow(@rubocop.git).to receive(:added_files).and_return([])
|
@@ -391,10 +399,20 @@ EOS
|
|
391
399
|
allow(@rubocop).to receive(:`)
|
392
400
|
.with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
|
393
401
|
.and_return(response_ruby_file)
|
402
|
+
end
|
394
403
|
|
404
|
+
it 'reports to danger' do
|
405
|
+
fail_msg = %{spec/fixtures/ruby_file.rb | 13 | Don't do that!}
|
395
406
|
expect(@rubocop).to receive(:fail).with(fail_msg)
|
396
407
|
@rubocop.lint(report_danger: true)
|
397
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
|
398
416
|
end
|
399
417
|
end
|
400
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.
|
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: 2023-
|
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.
|
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.
|