danger-rubocop 0.4.0 → 0.4.1

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
  SHA1:
3
- metadata.gz: 0344fb238b0dd6aeb32bf763745f599e46dd5176
4
- data.tar.gz: 2653083d32aa0f8a7d1452fa5a81b674981ea479
3
+ metadata.gz: 2a006c7c8dafc7fa51b8fe5aff38764b20502b4c
4
+ data.tar.gz: be9b290a729911dc21cc8a947ac75f22c739f800
5
5
  SHA512:
6
- metadata.gz: 4fdb6286385ef2fc18a1cc37c3330d2719022d598e823be29ce35506a1d8307fb9fb02d2c3a55c6ee381e642880ba4d78193e5660b279d4a203d139d3aeafd78
7
- data.tar.gz: 73e00649f3542c68ca1116f569b3fd996954428df566ced153394a3b70cd96d5349abfe14658c5844ae4f543faead71cf4ee51f0c79dbd88db2082f915279576
6
+ metadata.gz: cba8556356a8f29cf276cd88a0ce8e4ddd31870b0a6056bab8e0295a84a922e174b40fb636c2bd7381baf742f6111e46fc5cb2f7d4821d38dceff8db5bc6756c
7
+ data.tar.gz: 2e691ab029fa2145137dd7bdde399595ae8a2f6c7fde332f1d028cc1ad71c4b24cb84409e2d378a2401e30fced437c803dbb9fcecfaeba61f2963e16f848c510
data/README.md CHANGED
@@ -19,15 +19,16 @@ Results are passed out as a table in markdown.
19
19
 
20
20
 
21
21
  > Specifying custom config file.
22
- > ```ruby
22
+ ```ruby
23
23
  rubocop.lint
24
- > ```
24
+ ```
25
25
 
26
26
  > Lint specific files in a folder, when they change
27
- > ```ruby
28
- public_files = (modified_files + added_files).select { |path| path.include?("/public/") }
27
+
28
+ ```ruby
29
+ public_files = (git.modified_files + git.added_files).select { |path| path.include?("/public/") }
29
30
  rubocop.lint public_files
30
- > ```
31
+ ```
31
32
 
32
33
 
33
34
  #### Methods
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/ashfurrow/danger-rubocop'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
+ spec.files = `git ls-files`.split($/)
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
data/lib/danger_plugin.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module Danger
2
4
  # Run Ruby files through Rubocop.
3
5
  # Results are passed out as a table in markdown.
@@ -24,23 +26,26 @@ module Danger
24
26
  # from the diff will be used.
25
27
  # @return [void]
26
28
  #
27
- def lint(files = nil)
29
+ def lint(config = nil)
30
+ config = config.is_a?(Hash) ? config : { files: config }
31
+ files = config[:files]
32
+ force_exclusion = config[:force_exclusion] || false
33
+
28
34
  files_to_lint = fetch_files_to_lint(files)
35
+ files_to_report = rubocop(files_to_lint, force_exclusion)
29
36
 
30
- return if offending_files.empty?
37
+ return if files_to_report.empty?
31
38
 
32
- markdown offenses_message(offending_files)
33
- end
34
-
35
- def offending_files(files = nil)
36
- files_to_lint = fetch_files_to_lint(files)
37
- rubocop(files_to_lint)
39
+ markdown offenses_message(files_to_report)
38
40
  end
39
41
 
40
42
  private
41
43
 
42
- def rubocop(files_to_lint)
43
- rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}rubocop -f json #{files_to_lint.join(' ')}`
44
+ def rubocop(files_to_lint, force_exclusion)
45
+ base_command = 'rubocop -f json'
46
+ base_command << ' --force-exclusion' if force_exclusion
47
+
48
+ rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command} #{files_to_lint}`
44
49
 
45
50
  JSON.parse(rubocop_output)['files']
46
51
  .select { |f| f['offenses'].any? }
@@ -61,9 +66,10 @@ module Danger
61
66
  ).to_s
62
67
  message + table.split("\n")[1..-2].join("\n")
63
68
  end
64
-
69
+
65
70
  def fetch_files_to_lint(files = nil)
66
- @files_to_lint ||= (files ? Dir.glob(files) : (git.modified_files + git.added_files))
71
+ to_lint = (files ? Dir.glob(files) : (git.modified_files + git.added_files))
72
+ Shellwords.join(to_lint)
67
73
  end
68
74
  end
69
75
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -50,6 +50,22 @@ module Danger
50
50
  .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
51
51
  .and_return(response_ruby_file)
52
52
 
53
+ # Do it
54
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb')
55
+
56
+ output = @rubocop.status_report[:markdowns].first.message
57
+
58
+ # A title
59
+ expect(output).to include('Rubocop violations')
60
+ # A warning
61
+ expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!")
62
+ end
63
+
64
+ it 'handles a rubocop report for specified files (legacy)' do
65
+ allow(@rubocop).to receive(:`)
66
+ .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
67
+ .and_return(response_ruby_file)
68
+
53
69
  # Do it
54
70
  @rubocop.lint('spec/fixtures/ruby*.rb')
55
71
 
@@ -61,6 +77,22 @@ module Danger
61
77
  expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!")
62
78
  end
63
79
 
80
+ it 'appends --force-exclusion argument when force_exclusion is set' do
81
+ allow(@rubocop).to receive(:`)
82
+ .with('bundle exec rubocop -f json --force-exclusion spec/fixtures/ruby_file.rb')
83
+ .and_return(response_ruby_file)
84
+
85
+ # Do it
86
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb', force_exclusion: true)
87
+
88
+ output = @rubocop.status_report[:markdowns].first.message
89
+
90
+ # A title
91
+ expect(output).to include('Rubocop violations')
92
+ # A warning
93
+ expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!")
94
+ end
95
+
64
96
  it 'handles a rubocop report for files changed in the PR' do
65
97
  allow(@rubocop.git).to receive(:added_files).and_return([])
66
98
  allow(@rubocop.git).to receive(:modified_files)
@@ -96,6 +128,21 @@ module Danger
96
128
  EOS
97
129
  expect(@rubocop.status_report[:markdowns].first.message).to eq(formatted_table.chomp)
98
130
  end
131
+
132
+ describe 'a filename with special characters' do
133
+ it 'is shell escaped' do
134
+ modified_files = [
135
+ 'spec/fixtures/shellescape/ruby_file_with_parens_(abc).rb',
136
+ 'spec/fixtures/shellescape/ruby_file with spaces.rb',
137
+ 'spec/fixtures/shellescape/ruby_file\'with_quotes.rb'
138
+ ]
139
+ allow(@rubocop.git).to receive(:modified_files)
140
+ .and_return(modified_files)
141
+ allow(@rubocop.git).to receive(:added_files).and_return([])
142
+
143
+ expect { @rubocop.lint }.not_to raise_error
144
+ end
145
+ end
99
146
  end
100
147
  end
101
148
  end
@@ -0,0 +1 @@
1
+ # This file intentional left blank-ish.
@@ -0,0 +1 @@
1
+ # This file intentional left blank-ish.
@@ -0,0 +1 @@
1
+ # This file intentional left blank-ish.
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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash Furrow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -169,6 +169,9 @@ files:
169
169
  - lib/version.rb
170
170
  - spec/danger_plugin_spec.rb
171
171
  - spec/fixtures/ruby_file.rb
172
+ - spec/fixtures/shellescape/ruby_file with spaces.rb
173
+ - spec/fixtures/shellescape/ruby_file'with_quotes.rb
174
+ - spec/fixtures/shellescape/ruby_file_with_parens_(abc).rb
172
175
  - spec/spec_helper.rb
173
176
  homepage: https://github.com/ashfurrow/danger-rubocop
174
177
  licenses:
@@ -190,11 +193,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
193
  version: '0'
191
194
  requirements: []
192
195
  rubyforge_project:
193
- rubygems_version: 2.5.1
196
+ rubygems_version: 2.6.11
194
197
  signing_key:
195
198
  specification_version: 4
196
199
  summary: A Danger plugin for running Ruby files through Rubocop.
197
200
  test_files:
198
201
  - spec/danger_plugin_spec.rb
199
202
  - spec/fixtures/ruby_file.rb
203
+ - spec/fixtures/shellescape/ruby_file with spaces.rb
204
+ - spec/fixtures/shellescape/ruby_file'with_quotes.rb
205
+ - spec/fixtures/shellescape/ruby_file_with_parens_(abc).rb
200
206
  - spec/spec_helper.rb