danger-rubocop 0.6.1 → 0.7.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: 541340d181c21fb3a3c0f3ca5274df9a89610380ecf1572453cfbfd480e07f4a
4
- data.tar.gz: 740f0a0e8da3d6c77c62a888984ec5636eddca707806c09674366bcc89aafe24
3
+ metadata.gz: ad658f09ac619e760282d3c744fb30c479711f934919fa337561a890cc810348
4
+ data.tar.gz: f85f21294bdbf3e1878fab539fbc5d0edc8cdc4a6b47880af049b756693b33e4
5
5
  SHA512:
6
- metadata.gz: 2bde76c6fa48ecc75aa06805c5d04ed84504d15def8685e05ffd62cb1e50aa417fb55e536c621cb2cff0af1e93222652436462d7719f5d5aa39a5b2e4e8d32de
7
- data.tar.gz: 909df7927367d9fc75389ffdfef64764ae38165828c82e40500667f167912d408000c03fcf6eb21241ec08c92add6dc4235ccfd4589b88fe1267925d9b335e2e
6
+ metadata.gz: 85c71ea2747fab34cdc91ebf7183ff8d18100416e11338a6207f7fe7a31cce0763fc6e7af63f4aec5e0b687042d208a02e92d88599e71c47c867a0468e55b0cf
7
+ data.tar.gz: 0aec485ea365fd126af04967a0f8267ed268bce85a3ba5ca5fd6513cbe76222d7e76de73ba2fe442855af462966da72aacbc79fbce791a4912ae23184b0869d3
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-rubocop (0.6.0)
4
+ danger-rubocop (0.7.0)
5
5
  danger
6
6
  rubocop
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.5.2)
12
- public_suffix (>= 2.0.2, < 4.0)
13
- ast (2.3.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.0)
14
14
  bacon (1.2.0)
15
- claide (1.0.2)
15
+ claide (1.0.3)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
@@ -21,26 +21,27 @@ GEM
21
21
  colored2 (3.1.2)
22
22
  cork (0.3.0)
23
23
  colored2 (~> 3.1)
24
- danger (5.5.5)
24
+ danger (6.0.9)
25
25
  claide (~> 1.0)
26
26
  claide-plugins (>= 0.9.2)
27
27
  colored2 (~> 3.1)
28
28
  cork (~> 0.1)
29
29
  faraday (~> 0.9)
30
- faraday-http-cache (~> 1.0)
31
- git (~> 1)
32
- kramdown (~> 1.5)
30
+ faraday-http-cache (~> 2.0)
31
+ git (~> 1.5)
32
+ kramdown (~> 2.0)
33
+ kramdown-parser-gfm (~> 1.0)
33
34
  no_proxy_fix
34
35
  octokit (~> 4.7)
35
36
  terminal-table (~> 1)
36
37
  diff-lcs (1.2.5)
37
- faraday (0.13.1)
38
+ faraday (0.15.4)
38
39
  multipart-post (>= 1.2, < 3)
39
- faraday-http-cache (1.3.1)
40
+ faraday-http-cache (2.0.0)
40
41
  faraday (~> 0.8)
41
42
  ffi (1.9.10)
42
43
  formatador (0.2.5)
43
- git (1.3.0)
44
+ git (1.5.0)
44
45
  guard (2.14.0)
45
46
  formatador (>= 0.2.4)
46
47
  listen (>= 2.7, < 4.0)
@@ -55,7 +56,10 @@ GEM
55
56
  guard (~> 2.1)
56
57
  guard-compat (~> 1.1)
57
58
  rspec (>= 2.99.0, < 4.0)
58
- kramdown (1.16.2)
59
+ jaro_winkler (1.5.3)
60
+ kramdown (2.1.0)
61
+ kramdown-parser-gfm (1.1.0)
62
+ kramdown (~> 2.0)
59
63
  listen (3.0.7)
60
64
  rb-fsevent (>= 0.9.3)
61
65
  rb-inotify (>= 0.9.7)
@@ -66,27 +70,26 @@ GEM
66
70
  metaclass (~> 0.0.1)
67
71
  mocha-on-bacon (0.2.2)
68
72
  mocha (>= 0.13.0)
69
- multipart-post (2.0.0)
73
+ multipart-post (2.1.1)
70
74
  nap (1.1.0)
71
75
  nenv (0.3.0)
72
76
  no_proxy_fix (0.1.2)
73
77
  notiffany (0.1.0)
74
78
  nenv (~> 0.1)
75
79
  shellany (~> 0.0)
76
- octokit (4.8.0)
80
+ octokit (4.14.0)
77
81
  sawyer (~> 0.8.0, >= 0.5.3)
78
82
  open4 (1.3.4)
79
- parallel (1.12.1)
80
- parser (2.4.0.2)
81
- ast (~> 2.3)
82
- powerpack (0.1.1)
83
+ parallel (1.17.0)
84
+ parser (2.6.4.1)
85
+ ast (~> 2.4.0)
83
86
  prettybacon (0.0.2)
84
87
  bacon (~> 1.2)
85
88
  pry (0.10.3)
86
89
  coderay (~> 1.1.0)
87
90
  method_source (~> 0.8.1)
88
91
  slop (~> 3.4)
89
- public_suffix (3.0.1)
92
+ public_suffix (4.0.1)
90
93
  rainbow (3.0.0)
91
94
  rake (10.5.0)
92
95
  rb-fsevent (0.9.7)
@@ -105,23 +108,23 @@ GEM
105
108
  diff-lcs (>= 1.2.0, < 2.0)
106
109
  rspec-support (~> 3.4.0)
107
110
  rspec-support (3.4.1)
108
- rubocop (0.52.0)
111
+ rubocop (0.74.0)
112
+ jaro_winkler (~> 1.5.1)
109
113
  parallel (~> 1.10)
110
- parser (>= 2.4.0.2, < 3.0)
111
- powerpack (~> 0.1)
114
+ parser (>= 2.6)
112
115
  rainbow (>= 2.2.2, < 4.0)
113
116
  ruby-progressbar (~> 1.7)
114
- unicode-display_width (~> 1.0, >= 1.0.1)
115
- ruby-progressbar (1.9.0)
116
- sawyer (0.8.1)
117
- addressable (>= 2.3.5, < 2.6)
118
- faraday (~> 0.8, < 1.0)
117
+ unicode-display_width (>= 1.4.0, < 1.7)
118
+ ruby-progressbar (1.10.1)
119
+ sawyer (0.8.2)
120
+ addressable (>= 2.3.5)
121
+ faraday (> 0.8, < 2.0)
119
122
  shellany (0.0.1)
120
123
  slop (3.6.0)
121
124
  terminal-table (1.8.0)
122
125
  unicode-display_width (~> 1.1, >= 1.1.1)
123
126
  thor (0.19.1)
124
- unicode-display_width (1.3.0)
127
+ unicode-display_width (1.6.0)
125
128
  yard (0.9.12)
126
129
 
127
130
  PLATFORMS
@@ -146,4 +149,4 @@ RUBY VERSION
146
149
  ruby 2.3.1p112
147
150
 
148
151
  BUNDLED WITH
149
- 1.15.4
152
+ 1.17.3
data/README.md CHANGED
@@ -47,6 +47,9 @@ The following keys are supported:
47
47
  * `inline_comment`: pass `true` to comment inline of the diffs.
48
48
  * `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
49
49
  * `report_danger`: pass true to report errors to Danger, and break CI.
50
+ * `config`: path to the `.rubocop.yml` file.
51
+ * `only_report_new_offenses`: pass `true` to only report offenses that are in current user's scope.
52
+ Note that this won't mark offenses for _Metrics/XXXLength_ if you add lines to an already existing scope.
50
53
 
51
54
 
52
55
  Passing `files` as only argument is also supported for backward compatibility.
@@ -30,13 +30,14 @@ module Danger
30
30
  config = config.is_a?(Hash) ? config : { files: config }
31
31
  files = config[:files]
32
32
  force_exclusion = config[:force_exclusion] || false
33
-
33
+ config_path = config[:config]
34
34
  report_danger = config[:report_danger] || false
35
+ only_report_new_offenses = config[:only_report_new_offenses] || false
35
36
  inline_comment = config[:inline_comment] || false
36
37
  fail_on_inline_comment = config[:fail_on_inline_comment] || false
37
38
 
38
39
  files_to_lint = fetch_files_to_lint(files)
39
- files_to_report = rubocop(files_to_lint, force_exclusion)
40
+ files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, config_path: config_path)
40
41
 
41
42
  return if files_to_report.empty?
42
43
  return report_failures files_to_report if report_danger
@@ -46,21 +47,50 @@ module Danger
46
47
  else
47
48
  markdown offenses_message(files_to_report)
48
49
  end
49
-
50
50
  end
51
51
 
52
52
  private
53
53
 
54
- def rubocop(files_to_lint, force_exclusion)
55
- base_command = 'rubocop -f json'
56
- base_command << ' --force-exclusion' if force_exclusion
54
+ def rubocop(files_to_lint, force_exclusion, only_report_new_offenses, config_path: nil)
55
+ base_command = ['rubocop', '-f', 'json']
56
+ base_command.concat(['--force-exclusion']) if force_exclusion
57
+ base_command.concat(['--config', config_path.shellescape]) unless config_path.nil?
57
58
 
58
- rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command} #{files_to_lint}`
59
+ rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command.join(' ')} #{files_to_lint}`
59
60
 
60
61
  return [] if rubocop_output.empty?
61
62
 
62
- JSON.parse(rubocop_output)['files']
63
- .select { |f| f['offenses'].any? }
63
+ files = JSON.parse(rubocop_output)['files']
64
+
65
+ filter_out_offenses(files) if only_report_new_offenses
66
+
67
+ files.select { |f| f['offenses'].any? }
68
+ end
69
+
70
+ def filter_out_offenses(files)
71
+ files.each do |file|
72
+ added_lines = added_lines(file['path']).to_set
73
+ file['offenses'].select! do |offense|
74
+ added_lines.include?(offense['location']['line'])
75
+ end
76
+ end
77
+ end
78
+
79
+ def added_lines(path)
80
+ git.diff_for_file(path)
81
+ .patch
82
+ .split("\n@@")
83
+ .tap(&:shift)
84
+ .flat_map do |chunk|
85
+ first_line, *diff = chunk.split("\n")
86
+ # Get start from diff.
87
+ lineno = first_line.match(/\+(\d+),(\d+)/).captures.first.to_i
88
+ diff.each_with_object([]) do |current_line, added_lines|
89
+ lineno += 1 unless current_line.start_with?('-')
90
+ added_lines << lineno if current_line.start_with?('+')
91
+ added_lines
92
+ end
93
+ end
64
94
  end
65
95
 
66
96
  def offenses_message(offending_files)
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.6.1'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require File.expand_path('spec_helper', __dir__)
2
2
 
3
3
  module Danger
4
4
  describe DangerRubocop do
@@ -12,6 +12,82 @@ module Danger
12
12
  @rubocop = testing_dangerfile.rubocop
13
13
  end
14
14
 
15
+ describe "#filter_out_offenses" do
16
+ let(:files_within_pr) do
17
+ [
18
+ {
19
+ 'path' => 'lib/version.rb',
20
+ 'offenses' => [
21
+ {
22
+ 'message' => 'No.',
23
+ 'location' => { 'line' => 42 }
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ end
29
+
30
+ let(:files_outside_pr) do
31
+ [
32
+ {
33
+ 'path' => 'lib/version.rb',
34
+ 'offenses' => [
35
+ {
36
+ 'message' => 'No.',
37
+ 'location' => { 'line' => 20 }
38
+ }
39
+ ]
40
+ }
41
+ ]
42
+ end
43
+ subject { @rubocop }
44
+
45
+ before do
46
+ allow(@rubocop.git).to receive(:diff_for_file).with('lib/version.rb') do
47
+ instance_double('Git::Diff::DiffFile', patch: <<~DIFF)
48
+ diff --git a/lib/version.rb b/lib/version.rb
49
+ index 66d3a986..5e8074a8 100644
50
+ --- a/lib/version.rb
51
+ +++ b/lib/version.rb
52
+ @@ -32,4 +40,3 @@
53
+ line 1
54
+ -removed
55
+ -line 2 old version
56
+ +line 2 with offense
57
+ line 3
58
+ DIFF
59
+ end
60
+ end
61
+
62
+ it 'filters out offenses not in the pr' do
63
+ p described_class
64
+ expect(subject.send(:filter_out_offenses, files_outside_pr)).to eq(
65
+ [
66
+ {
67
+ 'path' => 'lib/version.rb',
68
+ 'offenses' => []
69
+ }
70
+ ]
71
+ )
72
+ end
73
+
74
+ it 'keeps offenses in the pr' do
75
+ expect(subject.send(:filter_out_offenses, files_within_pr.dup)).to eq(
76
+ [
77
+ {
78
+ 'path' => 'lib/version.rb',
79
+ 'offenses' => [
80
+ {
81
+ 'message' => 'No.',
82
+ 'location' => { 'line' => 42 }
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ )
88
+ end
89
+ end
90
+
15
91
  describe :lint_files do
16
92
  let(:response_ruby_file) do
17
93
  {
@@ -47,11 +123,11 @@ module Danger
47
123
 
48
124
  it 'handles a rubocop report for specified files' do
49
125
  allow(@rubocop).to receive(:`)
50
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
126
+ .with('bundle exec rubocop -f json --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
51
127
  .and_return(response_ruby_file)
52
128
 
53
129
  # Do it
54
- @rubocop.lint(files: 'spec/fixtures/ruby*.rb')
130
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml')
55
131
 
56
132
  output = @rubocop.status_report[:markdowns].first.message
57
133
 
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.6.1
4
+ version: 0.7.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: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger