danger-rubocop 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/README.md +2 -1
- data/lib/danger_plugin.rb +39 -4
- data/lib/version.rb +1 -1
- data/spec/danger_plugin_spec.rb +103 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 228bd1f2c8294e6ade21c5a33424af6ddfa0ceb08613f62ca22db33bdfecd212
|
4
|
+
data.tar.gz: cafedd57a18b594548ef05c3287fd96acbf9a5692306e291ad85f7cf3456e6ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e30f4a47b31ce14a58e263da6a7d0cd80a81c016b989be786487393d60f45a131bbabf76f4dbbb08b22058331d1878ff30ddd917cceb3db1e34b5f3cb85fd039
|
7
|
+
data.tar.gz: 705e56f918fe479ee9633f513aaa9ce3396616456112be2d4fa2b1f9358b9c58c620f367ba8cedbb6159e5463d2bad2168e3fd1a949ff3477e6696b4fd24acc4
|
data/Gemfile.lock
CHANGED
@@ -108,7 +108,8 @@ GEM
|
|
108
108
|
ffi (~> 1.0)
|
109
109
|
rchardet (1.8.0)
|
110
110
|
regexp_parser (2.1.1)
|
111
|
-
rexml (3.2.
|
111
|
+
rexml (3.2.8)
|
112
|
+
strscan (>= 3.0.9)
|
112
113
|
rspec (3.10.0)
|
113
114
|
rspec-core (~> 3.10.0)
|
114
115
|
rspec-expectations (~> 3.10.0)
|
@@ -139,11 +140,12 @@ GEM
|
|
139
140
|
addressable (>= 2.3.5)
|
140
141
|
faraday (> 0.8, < 2.0)
|
141
142
|
shellany (0.0.1)
|
143
|
+
strscan (3.1.0)
|
142
144
|
terminal-table (3.0.1)
|
143
145
|
unicode-display_width (>= 1.1.1, < 3)
|
144
146
|
thor (1.1.0)
|
145
147
|
unicode-display_width (2.0.0)
|
146
|
-
yard (0.9.
|
148
|
+
yard (0.9.36)
|
147
149
|
|
148
150
|
PLATFORMS
|
149
151
|
ruby
|
data/README.md
CHANGED
@@ -57,6 +57,7 @@ The following keys are supported:
|
|
57
57
|
(this option will instruct rubocop to ignore the files that your rubocop config ignores,
|
58
58
|
despite the plugin providing the list of files explicitly)
|
59
59
|
* `inline_comment`: pass `true` to comment inline of the diffs.
|
60
|
+
* `group_inline_comments`: pass `true` to group inline comments to be a single comment on each line with all issues for that line.
|
60
61
|
* `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
|
61
62
|
* `report_severity`: pass `true` to use `fail` or `warn` based on Rubocop severity.
|
62
63
|
* `report_danger`: pass true to report errors to Danger, and break CI.
|
@@ -66,7 +67,7 @@ The following keys are supported:
|
|
66
67
|
Note that this won't mark offenses for _Metrics/XXXLength_ if you add lines to an already existing scope.
|
67
68
|
* `include_cop_names`: Prepends cop names to the output messages. Example: "Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end."
|
68
69
|
* `rubocop_cmd`: Allows you to change the rubocop executable that's invoked. This is used to support rubocop wrappers like [Standard](https://github.com/testdouble/standard/) by passing `standardrb` as the value.
|
69
|
-
|
70
|
+
* `skip_bundle_exec`: When there is a `Gemfile` in the project, Rubocop will be executed using [Bundler](https://bundler.io). When `true`, this flag will force Rubocop to run without `bundle exec`.
|
70
71
|
|
71
72
|
Passing `files` as only argument is also supported for backward compatibility.
|
72
73
|
|
data/lib/danger_plugin.rb
CHANGED
@@ -34,18 +34,22 @@ module Danger
|
|
34
34
|
report_danger = config[:report_danger] || false
|
35
35
|
only_report_new_offenses = config[:only_report_new_offenses] || false
|
36
36
|
inline_comment = config[:inline_comment] || false
|
37
|
+
group_inline_comments = config[:group_inline_comments] || false
|
37
38
|
fail_on_inline_comment = config[:fail_on_inline_comment] || false
|
38
39
|
report_severity = config[:report_severity] || false
|
39
40
|
include_cop_names = config[:include_cop_names] || false
|
40
41
|
rubocop_cmd = config[:rubocop_cmd] || 'rubocop'
|
42
|
+
skip_bundle_exec = config[:skip_bundle_exec] || false
|
41
43
|
|
42
44
|
files_to_lint = fetch_files_to_lint(files)
|
43
|
-
files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: rubocop_cmd, config_path: config_path)
|
45
|
+
files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: rubocop_cmd, config_path: config_path, skip_bundle_exec: skip_bundle_exec)
|
44
46
|
|
45
47
|
return if files_to_report.empty?
|
46
48
|
return report_failures(files_to_report, include_cop_names: include_cop_names) if report_danger
|
47
49
|
|
48
|
-
if inline_comment
|
50
|
+
if inline_comment && group_inline_comments
|
51
|
+
add_grouped_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
|
52
|
+
elsif inline_comment
|
49
53
|
add_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
|
50
54
|
else
|
51
55
|
markdown offenses_message(files_to_report, include_cop_names: include_cop_names)
|
@@ -54,12 +58,12 @@ module Danger
|
|
54
58
|
|
55
59
|
private
|
56
60
|
|
57
|
-
def rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: 'rubocop', config_path: nil)
|
61
|
+
def rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: 'rubocop', config_path: nil, skip_bundle_exec: false)
|
58
62
|
base_command = [cmd, '-f', 'json', '--only-recognized-file-types']
|
59
63
|
base_command.concat(['--force-exclusion']) if force_exclusion
|
60
64
|
base_command.concat(['--config', config_path.shellescape]) unless config_path.nil?
|
61
65
|
|
62
|
-
rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command.join(' ')} #{files_to_lint}`
|
66
|
+
rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile') && !skip_bundle_exec}#{base_command.join(' ')} #{files_to_lint}`
|
63
67
|
|
64
68
|
return [] if rubocop_output.empty?
|
65
69
|
|
@@ -144,6 +148,37 @@ module Danger
|
|
144
148
|
end
|
145
149
|
end
|
146
150
|
|
151
|
+
def add_grouped_violation_for_each_line(offending_files, fail_on_inline_comment, report_severity, include_cop_names: false)
|
152
|
+
grouped_offense_messages = Hash.new { |h, k| h[k] = [] }
|
153
|
+
offending_files.flat_map do |file|
|
154
|
+
file['offenses'].map do |offense|
|
155
|
+
offense_message = offense_message(offense, include_cop_names: include_cop_names)
|
156
|
+
kargs = {
|
157
|
+
file: file['path'],
|
158
|
+
line: offense['location']['line']
|
159
|
+
}
|
160
|
+
grouped_offense_messages[kargs] << offense_message
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
grouped_offense_messages.each do |kargs, offense_messages|
|
165
|
+
grouped_offense_message = if offense_messages.length > 1
|
166
|
+
"\n" + offense_messages.map do |offense_message|
|
167
|
+
"* #{offense_message}"
|
168
|
+
end.join("\n")
|
169
|
+
else
|
170
|
+
offense_messages[0]
|
171
|
+
end
|
172
|
+
if fail_on_inline_comment
|
173
|
+
fail(grouped_offense_message, **kargs)
|
174
|
+
elsif report_severity && %w[error fatal].include?(offense['severity'])
|
175
|
+
fail(grouped_offense_message, **kargs)
|
176
|
+
else
|
177
|
+
warn(grouped_offense_message, **kargs)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
147
182
|
def fetch_files_to_lint(files = nil)
|
148
183
|
to_lint = if files.nil?
|
149
184
|
# when files are renamed, git.modified_files contains the old name not the new one, so we need to do the convertion
|
data/lib/version.rb
CHANGED
data/spec/danger_plugin_spec.rb
CHANGED
@@ -323,6 +323,81 @@ EOS
|
|
323
323
|
.to eq("Violation Syntax/WhetherYouShouldDoThat: Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
|
324
324
|
end
|
325
325
|
end
|
326
|
+
|
327
|
+
context 'with group_inline_comments' do
|
328
|
+
context 'with multiple violations on the same line' do
|
329
|
+
let(:response_ruby_file) do
|
330
|
+
{
|
331
|
+
'files' => [
|
332
|
+
{
|
333
|
+
'path' => 'spec/fixtures/ruby_file.rb',
|
334
|
+
'offenses' => [
|
335
|
+
{
|
336
|
+
'cop_name' => 'Syntax/WhetherYouShouldDoThat',
|
337
|
+
'message' => "Don't do that!",
|
338
|
+
'severity' => 'warning',
|
339
|
+
'location' => { 'line' => 13 }
|
340
|
+
},
|
341
|
+
{
|
342
|
+
'cop_name' => 'Syntax/WhetherYouShouldDoThat',
|
343
|
+
'message' => "Also don't do that!",
|
344
|
+
'severity' => 'warning',
|
345
|
+
'location' => { 'line' => 13 }
|
346
|
+
}
|
347
|
+
]
|
348
|
+
}
|
349
|
+
]
|
350
|
+
}.to_json
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'reports multiple violations grouped by line in a bulleted list' do
|
354
|
+
allow(@rubocop.git).to receive(:modified_files)
|
355
|
+
.and_return(['spec/fixtures/ruby_file.rb'])
|
356
|
+
allow(@rubocop.git).to receive(:added_files).and_return([])
|
357
|
+
allow(@rubocop.git).to receive(:renamed_files).and_return([])
|
358
|
+
allow(@rubocop).to receive(:`)
|
359
|
+
.with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
|
360
|
+
.and_return(response_ruby_file)
|
361
|
+
|
362
|
+
@rubocop.lint(inline_comment: true, group_inline_comments: true)
|
363
|
+
|
364
|
+
warning = @rubocop.violation_report[:warnings].first
|
365
|
+
expect(warning.file)
|
366
|
+
.to eq("spec/fixtures/ruby_file.rb")
|
367
|
+
expect(warning.line)
|
368
|
+
.to eq(13)
|
369
|
+
expect(warning.message)
|
370
|
+
.to eq(
|
371
|
+
<<~HEREDOC
|
372
|
+
|
373
|
+
* Don't do that!
|
374
|
+
* Also don't do that!
|
375
|
+
HEREDOC
|
376
|
+
.chomp
|
377
|
+
)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'reports single violations grouped by line as normal line by line warnings' do
|
382
|
+
allow(@rubocop.git).to receive(:modified_files)
|
383
|
+
.and_return(['spec/fixtures/ruby_file.rb'])
|
384
|
+
allow(@rubocop.git).to receive(:added_files).and_return([])
|
385
|
+
allow(@rubocop.git).to receive(:renamed_files).and_return([])
|
386
|
+
allow(@rubocop).to receive(:`)
|
387
|
+
.with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
|
388
|
+
.and_return(response_ruby_file)
|
389
|
+
|
390
|
+
@rubocop.lint(inline_comment: true, group_inline_comments: true)
|
391
|
+
|
392
|
+
warning = @rubocop.violation_report[:warnings].first
|
393
|
+
expect(warning.file)
|
394
|
+
.to eq("spec/fixtures/ruby_file.rb")
|
395
|
+
expect(warning.line)
|
396
|
+
.to eq(13)
|
397
|
+
expect(warning.message)
|
398
|
+
.to eq("Don't do that!")
|
399
|
+
end
|
400
|
+
end
|
326
401
|
end
|
327
402
|
|
328
403
|
context 'with report_severity option' do
|
@@ -374,6 +449,34 @@ EOS
|
|
374
449
|
end
|
375
450
|
end
|
376
451
|
|
452
|
+
context 'using Bundler' do
|
453
|
+
it 'uses `bundle exec` when there is a Gemfile' do
|
454
|
+
allow(@rubocop).to receive(:`)
|
455
|
+
.with('bundle exec rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
|
456
|
+
.and_return(response_ruby_file)
|
457
|
+
|
458
|
+
@rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml')
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'doesn\'t use `bundle exec` when there is no Gemfile' do
|
462
|
+
allow(File).to receive(:exist?).with('Gemfile').and_return(false)
|
463
|
+
|
464
|
+
allow(@rubocop).to receive(:`)
|
465
|
+
.with('rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
|
466
|
+
.and_return(response_ruby_file)
|
467
|
+
|
468
|
+
@rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml')
|
469
|
+
end
|
470
|
+
|
471
|
+
it 'doesn\'t use `bundle exec` when there is a Gemfile but skip_bundle_exec is true' do
|
472
|
+
allow(@rubocop).to receive(:`)
|
473
|
+
.with('rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
|
474
|
+
.and_return(response_ruby_file)
|
475
|
+
|
476
|
+
@rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml', skip_bundle_exec: true)
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
377
480
|
describe 'a filename with special characters' do
|
378
481
|
it 'is shell escaped' do
|
379
482
|
modified_files = [
|
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.13.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:
|
11
|
+
date: 2024-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger
|