danger-rubocop 0.8.1 → 0.9.4

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: bb5d7eb8397ac2e653dbb40f1d36578709c9167d1c58edcf03755317bae9a1d9
4
- data.tar.gz: 29663b37df5566b315562381f690738a96fde57537be19a3aaa2c6ac9d227519
3
+ metadata.gz: 5363c39a9497dd46bb7268c9c8e1161604c90c5795cb790cd6affcd74a71c8aa
4
+ data.tar.gz: 4c9db849c7b8439aba6a5b7761daf57e7d871e18fd42a02f3a461e5ea23e80ff
5
5
  SHA512:
6
- metadata.gz: 7786b81d1acd3476b3a64c672c9a1164bda1f427c29e1379a84bed948a6d46eb1dfe506d7b1316246d61c4a710508e1c15b5378fbaa51de111fd9aba78b6a0dc
7
- data.tar.gz: e7e7aa14b45ad941d1be7a1e39f070a1f01e124c97e3eb2c099cd8934ca113018a834a5e51fa71b765a82807b3cbda1e6a25f4a7111cc50f89138be17df1048e
6
+ metadata.gz: 02de948e9d1f6049d4b1516152e86b265106d715c48168412b9b2610a338b8f29c5d37d410a055caa5139ea634a2c226f62dc2caf72cc8083306e4d7d8012400
7
+ data.tar.gz: bdf55e66ef3307c0422acd50ff56691d303be15518667059e2bc8d9e0a14aeb060250f6ed878f2deca16594db4b0df6b21e0e7f4937e21f4a93901bc19b50429
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ruby '>= 2.0'
3
+ ruby '>= 2.6.0'
4
4
 
5
5
  gemspec
6
6
 
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-rubocop (0.8.1)
4
+ danger-rubocop (0.9.4)
5
5
  danger
6
- rubocop
6
+ rubocop (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  addressable (2.7.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.1)
13
+ ast (2.4.2)
14
14
  bacon (1.2.0)
15
15
  claide (1.0.3)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
19
19
  open4 (~> 1.3)
20
- coderay (1.1.1)
20
+ coderay (1.1.3)
21
21
  colored2 (3.1.2)
22
22
  cork (0.3.0)
23
23
  colored2 (~> 3.1)
24
- danger (8.0.4)
24
+ danger (8.2.3)
25
25
  claide (~> 1.0)
26
26
  claide-plugins (>= 0.9.2)
27
27
  colored2 (~> 3.1)
@@ -29,112 +29,115 @@ GEM
29
29
  faraday (>= 0.9.0, < 2.0)
30
30
  faraday-http-cache (~> 2.0)
31
31
  git (~> 1.7)
32
- kramdown (~> 2.0)
32
+ kramdown (~> 2.3)
33
33
  kramdown-parser-gfm (~> 1.0)
34
34
  no_proxy_fix
35
35
  octokit (~> 4.7)
36
- terminal-table (~> 1)
37
- diff-lcs (1.2.5)
38
- faraday (1.0.1)
36
+ terminal-table (>= 1, < 4)
37
+ diff-lcs (1.4.4)
38
+ faraday (1.4.1)
39
+ faraday-excon (~> 1.1)
40
+ faraday-net_http (~> 1.0)
41
+ faraday-net_http_persistent (~> 1.1)
39
42
  multipart-post (>= 1.2, < 3)
43
+ ruby2_keywords (>= 0.0.4)
44
+ faraday-excon (1.1.0)
40
45
  faraday-http-cache (2.2.0)
41
46
  faraday (>= 0.8)
42
- ffi (1.9.10)
47
+ faraday-net_http (1.0.1)
48
+ faraday-net_http_persistent (1.1.0)
49
+ ffi (1.15.0)
43
50
  formatador (0.2.5)
44
- git (1.7.0)
51
+ git (1.8.1)
45
52
  rchardet (~> 1.8)
46
- guard (2.14.0)
53
+ guard (2.16.2)
47
54
  formatador (>= 0.2.4)
48
55
  listen (>= 2.7, < 4.0)
49
- lumberjack (~> 1.0)
56
+ lumberjack (>= 1.0.12, < 2.0)
50
57
  nenv (~> 0.1)
51
58
  notiffany (~> 0.0)
52
59
  pry (>= 0.9.12)
53
60
  shellany (~> 0.0)
54
61
  thor (>= 0.18.1)
55
62
  guard-compat (1.2.1)
56
- guard-rspec (4.7.2)
63
+ guard-rspec (4.7.3)
57
64
  guard (~> 2.1)
58
65
  guard-compat (~> 1.1)
59
66
  rspec (>= 2.99.0, < 4.0)
60
- kramdown (2.3.0)
67
+ kramdown (2.3.1)
61
68
  rexml
62
69
  kramdown-parser-gfm (1.1.0)
63
70
  kramdown (~> 2.0)
64
71
  listen (3.0.7)
65
72
  rb-fsevent (>= 0.9.3)
66
73
  rb-inotify (>= 0.9.7)
67
- lumberjack (1.0.10)
68
- metaclass (0.0.4)
69
- method_source (0.8.2)
70
- mocha (1.1.0)
71
- metaclass (~> 0.0.1)
72
- mocha-on-bacon (0.2.2)
74
+ lumberjack (1.2.8)
75
+ method_source (1.0.0)
76
+ mocha (1.12.0)
77
+ mocha-on-bacon (0.2.3)
73
78
  mocha (>= 0.13.0)
74
79
  multipart-post (2.1.1)
75
80
  nap (1.1.0)
76
81
  nenv (0.3.0)
77
82
  no_proxy_fix (0.1.2)
78
- notiffany (0.1.0)
83
+ notiffany (0.1.3)
79
84
  nenv (~> 0.1)
80
85
  shellany (~> 0.0)
81
- octokit (4.18.0)
86
+ octokit (4.21.0)
82
87
  faraday (>= 0.9)
83
88
  sawyer (~> 0.8.0, >= 0.5.3)
84
89
  open4 (1.3.4)
85
- parallel (1.19.2)
86
- parser (2.7.1.4)
90
+ parallel (1.20.1)
91
+ parser (3.0.1.1)
87
92
  ast (~> 2.4.1)
88
93
  prettybacon (0.0.2)
89
94
  bacon (~> 1.2)
90
- pry (0.10.3)
91
- coderay (~> 1.1.0)
92
- method_source (~> 0.8.1)
93
- slop (~> 3.4)
94
- public_suffix (4.0.5)
95
+ pry (0.14.1)
96
+ coderay (~> 1.1)
97
+ method_source (~> 1.0)
98
+ public_suffix (4.0.6)
95
99
  rainbow (3.0.0)
96
- rake (13.0.1)
97
- rb-fsevent (0.9.7)
98
- rb-inotify (0.9.7)
99
- ffi (>= 0.5.0)
100
+ rake (13.0.3)
101
+ rb-fsevent (0.10.4)
102
+ rb-inotify (0.10.1)
103
+ ffi (~> 1.0)
100
104
  rchardet (1.8.0)
101
- regexp_parser (1.7.1)
102
- rexml (3.2.4)
103
- rspec (3.4.0)
104
- rspec-core (~> 3.4.0)
105
- rspec-expectations (~> 3.4.0)
106
- rspec-mocks (~> 3.4.0)
107
- rspec-core (3.4.4)
108
- rspec-support (~> 3.4.0)
109
- rspec-expectations (3.4.0)
105
+ regexp_parser (2.1.1)
106
+ rexml (3.2.5)
107
+ rspec (3.10.0)
108
+ rspec-core (~> 3.10.0)
109
+ rspec-expectations (~> 3.10.0)
110
+ rspec-mocks (~> 3.10.0)
111
+ rspec-core (3.10.1)
112
+ rspec-support (~> 3.10.0)
113
+ rspec-expectations (3.10.1)
110
114
  diff-lcs (>= 1.2.0, < 2.0)
111
- rspec-support (~> 3.4.0)
112
- rspec-mocks (3.4.1)
115
+ rspec-support (~> 3.10.0)
116
+ rspec-mocks (3.10.2)
113
117
  diff-lcs (>= 1.2.0, < 2.0)
114
- rspec-support (~> 3.4.0)
115
- rspec-support (3.4.1)
116
- rubocop (0.89.1)
118
+ rspec-support (~> 3.10.0)
119
+ rspec-support (3.10.2)
120
+ rubocop (1.14.0)
117
121
  parallel (~> 1.10)
118
- parser (>= 2.7.1.1)
122
+ parser (>= 3.0.0.0)
119
123
  rainbow (>= 2.2.2, < 4.0)
120
- regexp_parser (>= 1.7)
124
+ regexp_parser (>= 1.8, < 3.0)
121
125
  rexml
122
- rubocop-ast (>= 0.3.0, < 1.0)
126
+ rubocop-ast (>= 1.5.0, < 2.0)
123
127
  ruby-progressbar (~> 1.7)
124
- unicode-display_width (>= 1.4.0, < 2.0)
125
- rubocop-ast (0.3.0)
126
- parser (>= 2.7.1.4)
127
- ruby-progressbar (1.10.1)
128
+ unicode-display_width (>= 1.4.0, < 3.0)
129
+ rubocop-ast (1.5.0)
130
+ parser (>= 3.0.1.1)
131
+ ruby-progressbar (1.11.0)
132
+ ruby2_keywords (0.0.4)
128
133
  sawyer (0.8.2)
129
134
  addressable (>= 2.3.5)
130
135
  faraday (> 0.8, < 2.0)
131
136
  shellany (0.0.1)
132
- slop (3.6.0)
133
- terminal-table (1.8.0)
134
- unicode-display_width (~> 1.1, >= 1.1.1)
135
- thor (0.19.1)
136
- unicode-display_width (1.7.0)
137
- yard (0.9.20)
137
+ terminal-table (1.6.0)
138
+ thor (1.1.0)
139
+ unicode-display_width (2.0.0)
140
+ yard (0.9.26)
138
141
 
139
142
  PLATFORMS
140
143
  ruby
@@ -155,7 +158,7 @@ DEPENDENCIES
155
158
  yard
156
159
 
157
160
  RUBY VERSION
158
- ruby 2.3.1p112
161
+ ruby 2.6.0p0
159
162
 
160
163
  BUNDLED WITH
161
164
  1.17.3
data/README.md CHANGED
@@ -46,10 +46,10 @@ Runs Ruby files through Rubocop. Generates a `markdown` list of warnings.
46
46
  This method accepts a configuration hash.
47
47
  The following keys are supported:
48
48
 
49
- * `files`: array of file names or glob patterns to determine files to lint
49
+ * `files`: array of file names or glob patterns to determine files to lint. If omitted, this will lint only the files changed in the pull request. To lint all files every time, pass an empty string; this is the equivalent of typing `rubocop` without specifying any files, and will follow the rules in your `.rubocop.yml`.
50
50
  * `force_exclusion`: pass `true` to pass `--force-exclusion` argument to Rubocop.
51
51
  (this option will instruct rubocop to ignore the files that your rubocop config ignores,
52
- despite the plugin providing the list of files explicitely)
52
+ despite the plugin providing the list of files explicitly)
53
53
  * `inline_comment`: pass `true` to comment inline of the diffs.
54
54
  * `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
55
55
  * `report_danger`: pass true to report errors to Danger, and break CI.
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'danger'
21
- spec.add_dependency 'rubocop'
21
+ spec.add_dependency 'rubocop', '~> 1.0'
22
22
 
23
23
  # General ruby development
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
data/lib/danger_plugin.rb CHANGED
@@ -53,7 +53,7 @@ module Danger
53
53
  private
54
54
 
55
55
  def rubocop(files_to_lint, force_exclusion, only_report_new_offenses, config_path: nil)
56
- base_command = ['rubocop', '-f', 'json']
56
+ base_command = ['rubocop', '-f', 'json', '--only-recognized-file-types']
57
57
  base_command.concat(['--force-exclusion']) if force_exclusion
58
58
  base_command.concat(['--config', config_path.shellescape]) unless config_path.nil?
59
59
 
@@ -78,14 +78,17 @@ module Danger
78
78
  end
79
79
 
80
80
  def added_lines(path)
81
- git.diff_for_file(path)
81
+ diff_for_file = git.diff_for_file(path)
82
+ return [] if diff_for_file.nil?
83
+
84
+ diff_for_file
82
85
  .patch
83
86
  .split("\n@@")
84
87
  .tap(&:shift)
85
88
  .flat_map do |chunk|
86
89
  first_line, *diff = chunk.split("\n")
87
90
  # Get start from diff.
88
- lineno = first_line.match(/\+(\d+),(\d+)/).captures.first.to_i
91
+ lineno = first_line.match(/\+(\d+),?(\d?)/).captures.first.to_i
89
92
  diff.each_with_object([]) do |current_line, added_lines|
90
93
  added_lines << lineno if current_line.start_with?('+')
91
94
  lineno += 1 unless current_line.start_with?('-')
@@ -142,7 +145,13 @@ module Danger
142
145
  end
143
146
 
144
147
  def fetch_files_to_lint(files = nil)
145
- to_lint = (files ? Dir.glob(files) : (git.modified_files + git.added_files))
148
+ to_lint = if files.nil?
149
+ # when files are renamed, git.modified_files contains the old name not the new one, so we need to do the convertion
150
+ renaming_map = (git.renamed_files || []).map { |e| [e[:before], e[:after]] }.to_h
151
+ (git.modified_files.map { |f| renaming_map[f] || f }) + git.added_files
152
+ else
153
+ Dir.glob(files)
154
+ end
146
155
  Shellwords.join(to_lint)
147
156
  end
148
157
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.9.4'.freeze
3
3
  end
@@ -107,6 +107,36 @@ module Danger
107
107
  it 'handles git diff' do
108
108
  expect(@rubocop.send(:added_lines, 'SAMPLE')).to eq([1, 2])
109
109
  end
110
+
111
+ context "single line added to a new file" do
112
+ before do
113
+ allow(@rubocop.git).to receive(:diff_for_file).with('SAMPLE') do
114
+ instance_double('Git::Diff::DiffFile', patch: <<~DIFF)
115
+ diff --git a/SAMPLE b/SAMPLE
116
+ new file mode 100644
117
+ index 0000000..7bba8c8
118
+ --- /dev/null
119
+ +++ b/SAMPLE
120
+ @@ -0,0 +1 @@
121
+ +line 1
122
+ DIFF
123
+ end
124
+ end
125
+
126
+ it 'handles git diff' do
127
+ expect(@rubocop.send(:added_lines, 'SAMPLE')).to eq([1])
128
+ end
129
+ end
130
+
131
+ context 'no such file' do
132
+ before do
133
+ allow(@rubocop.git).to receive(:diff_for_file).with('SAMPLE').and_return(nil)
134
+ end
135
+
136
+ it 'return empty array' do
137
+ expect(@rubocop.send(:added_lines, 'SAMPLE')).to eq([])
138
+ end
139
+ end
110
140
  end
111
141
 
112
142
  describe :lint_files do
@@ -146,7 +176,7 @@ module Danger
146
176
 
147
177
  it 'handles a rubocop report for specified files' do
148
178
  allow(@rubocop).to receive(:`)
149
- .with('bundle exec rubocop -f json --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
179
+ .with('bundle exec rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
150
180
  .and_return(response_ruby_file)
151
181
 
152
182
  # Do it
@@ -162,7 +192,7 @@ module Danger
162
192
 
163
193
  it 'includes cop names when include_cop_names is set' do
164
194
  allow(@rubocop).to receive(:`)
165
- .with('bundle exec rubocop -f json --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
195
+ .with('bundle exec rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
166
196
  .and_return(response_ruby_file)
167
197
 
168
198
  # Do it
@@ -178,7 +208,7 @@ module Danger
178
208
 
179
209
  it 'handles a rubocop report for specified files (legacy)' do
180
210
  allow(@rubocop).to receive(:`)
181
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
211
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
182
212
  .and_return(response_ruby_file)
183
213
 
184
214
  # Do it
@@ -194,7 +224,7 @@ module Danger
194
224
 
195
225
  it 'appends --force-exclusion argument when force_exclusion is set' do
196
226
  allow(@rubocop).to receive(:`)
197
- .with('bundle exec rubocop -f json --force-exclusion spec/fixtures/ruby_file.rb')
227
+ .with('bundle exec rubocop -f json --only-recognized-file-types --force-exclusion spec/fixtures/ruby_file.rb')
198
228
  .and_return(response_ruby_file)
199
229
 
200
230
  # Do it
@@ -211,10 +241,12 @@ module Danger
211
241
  it 'handles a rubocop report for files changed in the PR' do
212
242
  allow(@rubocop.git).to receive(:added_files).and_return([])
213
243
  allow(@rubocop.git).to receive(:modified_files)
214
- .and_return(["spec/fixtures/another_ruby_file.rb"])
244
+ .and_return(["spec/fixtures/old_file_name.rb", "spec/fixtures/another_ruby_file.rb"])
245
+ allow(@rubocop.git).to receive(:renamed_files)
246
+ .and_return([{before: "spec/fixtures/old_file_name.rb", after: "spec/fixtures/new_file_name.rb"}])
215
247
 
216
248
  allow(@rubocop).to receive(:`)
217
- .with('bundle exec rubocop -f json spec/fixtures/another_ruby_file.rb')
249
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/new_file_name.rb spec/fixtures/another_ruby_file.rb')
218
250
  .and_return(response_another_ruby_file)
219
251
 
220
252
  @rubocop.lint
@@ -229,8 +261,9 @@ module Danger
229
261
  allow(@rubocop.git).to receive(:modified_files)
230
262
  .and_return(['spec/fixtures/ruby_file.rb'])
231
263
  allow(@rubocop.git).to receive(:added_files).and_return([])
264
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
232
265
  allow(@rubocop).to receive(:`)
233
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
266
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
234
267
  .and_return(response_ruby_file)
235
268
 
236
269
  @rubocop.lint
@@ -251,8 +284,9 @@ EOS
251
284
  allow(@rubocop.git).to receive(:modified_files)
252
285
  .and_return(['spec/fixtures/ruby_file.rb'])
253
286
  allow(@rubocop.git).to receive(:added_files).and_return([])
287
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
254
288
  allow(@rubocop).to receive(:`)
255
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
289
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
256
290
  .and_return(response_ruby_file)
257
291
 
258
292
  @rubocop.lint(inline_comment: true)
@@ -267,8 +301,9 @@ EOS
267
301
  allow(@rubocop.git).to receive(:modified_files)
268
302
  .and_return(['spec/fixtures/ruby_file.rb'])
269
303
  allow(@rubocop.git).to receive(:added_files).and_return([])
304
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
270
305
  allow(@rubocop).to receive(:`)
271
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
306
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
272
307
  .and_return(response_ruby_file)
273
308
 
274
309
  @rubocop.lint(fail_on_inline_comment: true, inline_comment: true)
@@ -289,6 +324,7 @@ EOS
289
324
  allow(@rubocop.git).to receive(:modified_files)
290
325
  .and_return(modified_files)
291
326
  allow(@rubocop.git).to receive(:added_files).and_return([])
327
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
292
328
 
293
329
  expect { @rubocop.lint }.not_to raise_error
294
330
  end
@@ -300,8 +336,9 @@ EOS
300
336
  allow(@rubocop.git).to receive(:modified_files)
301
337
  .and_return(['spec/fixtures/ruby_file.rb'])
302
338
  allow(@rubocop.git).to receive(:added_files).and_return([])
339
+ allow(@rubocop.git).to receive(:renamed_files).and_return([])
303
340
  allow(@rubocop).to receive(:`)
304
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
341
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
305
342
  .and_return(response_ruby_file)
306
343
 
307
344
  expect(@rubocop).to receive(:fail).with(fail_msg)
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.8.1
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -177,7 +177,7 @@ homepage: https://github.com/ashfurrow/danger-rubocop
177
177
  licenses:
178
178
  - MIT
179
179
  metadata: {}
180
- post_install_message:
180
+ post_install_message:
181
181
  rdoc_options: []
182
182
  require_paths:
183
183
  - lib
@@ -192,8 +192,8 @@ 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.8
196
- signing_key:
195
+ rubygems_version: 3.0.2
196
+ signing_key:
197
197
  specification_version: 4
198
198
  summary: A Danger plugin for running Ruby files through Rubocop.
199
199
  test_files: