danger-rubocop 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: 4913ce170fed65fbffcc48b48f612d1ee1c1614a
4
- data.tar.gz: 307c2ba9850cd9e1e4977d19cb7b108e6ab8adb5
3
+ metadata.gz: 1978aa697df5bc21637aa6709902420c4609a3df
4
+ data.tar.gz: 421a0668ca419f70fc5d6be6f1e0b3f03ca84a33
5
5
  SHA512:
6
- metadata.gz: dcde2c3010d6942fd8524fa87e14968ff20538b1cdfe1a3b893a1930e107682eca77d2de052d19e3e22b9a24338423c1d2c396aff02a78734cefef342be41a21
7
- data.tar.gz: 7bc56b94ecd9224783c29ca91462878f083d6ade4aadf179a7f9007443271920baeced5febe784c76c3652ad31814e6d9384fbb459ba84f260116bf64351c3ff
6
+ metadata.gz: 49f783ea67d5843ed21746553d640477fab94fb03819118ae87adf3611ae22297a5eff61581b128e904f72535cd4b7d22296b37df6f130d4557f2763c0d8712d
7
+ data.tar.gz: c079dc452e654c4bcad9e630528e0b4013d641189e9823dd5521ae8cc15226e8a2e6d65c84973c55d1921aed6ae14276ef0931060be5305735a2f7eec8708cc4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-rubocop (0.1.0)
4
+ danger-rubocop (0.2.0)
5
5
  danger
6
6
  rubocop
7
7
 
@@ -12,17 +12,17 @@ GEM
12
12
  ast (2.3.0)
13
13
  bacon (1.2.0)
14
14
  claide (1.0.0)
15
- claide-plugins (0.9.0)
16
- cork (~> 0)
17
- nap (~> 1.0)
15
+ claide-plugins (0.9.1)
16
+ cork
17
+ nap
18
18
  open4 (~> 1.3)
19
19
  coderay (1.1.1)
20
20
  colored (1.2)
21
21
  cork (0.1.0)
22
22
  colored (~> 1.2)
23
- danger (0.10.1)
23
+ danger (2.1.0)
24
24
  claide (~> 1.0)
25
- claide-plugins (~> 0.9)
25
+ claide-plugins (> 0.9.0)
26
26
  colored (~> 1.2)
27
27
  cork (~> 0.1)
28
28
  faraday (~> 0)
@@ -100,7 +100,7 @@ GEM
100
100
  diff-lcs (>= 1.2.0, < 2.0)
101
101
  rspec-support (~> 3.4.0)
102
102
  rspec-support (3.4.1)
103
- rubocop (0.41.2)
103
+ rubocop (0.42.0)
104
104
  parser (>= 2.3.1.1, < 3.0)
105
105
  powerpack (~> 0.1)
106
106
  rainbow (>= 1.99.1, < 3.0)
data/README.md CHANGED
@@ -14,22 +14,30 @@ gem 'danger-rubocop'
14
14
 
15
15
  ## Usage
16
16
 
17
- The easiest way to use is just add this to your Dangerfile:
17
+ Run Ruby files through Rubocop.
18
+ Results are passed out as a table in markdown.
18
19
 
19
- ```rb
20
+
21
+ > Specifying custom config file.
22
+ > ```ruby
20
23
  rubocop.lint
21
- ```
24
+ > ```
22
25
 
23
- That will lint any changed or added Ruby files in the PR.
26
+ > Lint specific files in a folder, when they change
27
+ > ```ruby
28
+ public_files = (modified_files + added_files).select { |path| path.include?("/public/") }
29
+ rubocop.lint public_files
30
+ > ```
24
31
 
25
- You can also provide a list of files manually:
26
32
 
27
- ```rb
28
- # Look through all changed ruby files
29
- rb_files = (modified_files + added_files).select { |f| f.end_with?(".rb") }
33
+ #### Methods
34
+
35
+
36
+ `lint(files: String)`
37
+
38
+ Runs Ruby files through Rubocop. Generates a `markdown` list of warnings.
39
+
30
40
 
31
- rubocop.run rb_files
32
- ```
33
41
 
34
42
  ## License
35
43
 
data/lib/danger_plugin.rb CHANGED
@@ -26,7 +26,6 @@ module Danger
26
26
  #
27
27
  def lint(files = nil)
28
28
  files_to_lint = files ? Dir.glob(files) : (git.modified_files + git.added_files)
29
- files_to_lint.select! { |f| f.end_with? 'rb' }
30
29
 
31
30
  offending_files = rubocop(files_to_lint)
32
31
  return if offending_files.empty?
@@ -37,25 +36,26 @@ module Danger
37
36
  private
38
37
 
39
38
  def rubocop(files_to_lint)
40
- rubocop_results = files_to_lint.flat_map do |f|
41
- prefix = File.exist?('Gemfile') ? 'bundle exec' : ''
42
- JSON.parse(`#{prefix} rubocop -f json #{f}`)['files']
43
- end
44
- rubocop_results.select { |f| f['offenses'].count > 0 }
39
+ rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}rubocop -f json`
40
+
41
+ JSON.parse(rubocop_output)['files']
42
+ .select { |f| files_to_lint.include?(f['path']) && f['offenses'].any? }
45
43
  end
46
44
 
47
45
  def offenses_message(offending_files)
48
46
  require 'terminal-table'
49
47
 
50
48
  message = "### Rubocop violations\n\n"
51
- message + Terminal::Table.new(
49
+ table = Terminal::Table.new(
52
50
  headings: %w(File Line Reason),
51
+ style: { border_i: '|' },
53
52
  rows: offending_files.flat_map do |file|
54
53
  file['offenses'].map do |offense|
55
54
  [file['path'], offense['location']['line'], offense['message']]
56
55
  end
57
56
  end
58
57
  ).to_s
58
+ message + table.split("\n")[1..-2].join("\n")
59
59
  end
60
60
  end
61
61
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -18,26 +18,35 @@ module Danger
18
18
  response = {
19
19
  'files' => [
20
20
  {
21
- 'path' => 'ruby_file.rb',
21
+ 'path' => 'spec/fixtures/ruby_file.rb',
22
22
  'offenses' => [
23
23
  {
24
24
  'message' => "Don't do that!",
25
25
  'location' => { 'line' => 13 }
26
26
  }
27
27
  ]
28
+ },
29
+ {
30
+ 'path' => 'spec/fixtures/another_ruby_file.rb',
31
+ 'offenses' => [
32
+ {
33
+ 'message' => "Don't do that!",
34
+ 'location' => { 'line' => 23 }
35
+ }
36
+ ]
28
37
  }
29
38
  ]
30
39
  }
31
40
  @rubocop_response = response.to_json
32
41
  end
33
42
 
34
- it 'handles a known rubocop report' do
43
+ it 'handles a rubocop report for specified files' do
35
44
  allow(@rubocop).to receive(:`)
36
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
45
+ .with('bundle exec rubocop -f json')
37
46
  .and_return(@rubocop_response)
38
47
 
39
48
  # Do it
40
- @rubocop.lint('spec/fixtures/*.rb')
49
+ @rubocop.lint('spec/fixtures/ruby*.rb')
41
50
 
42
51
  output = @rubocop.status_report[:markdowns].first
43
52
 
@@ -46,20 +55,44 @@ module Danger
46
55
  # A title
47
56
  expect(output).to include('Rubocop violations')
48
57
  # A warning
49
- expect(output).to include("ruby_file.rb | 13 | Don't do that!")
58
+ expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!")
59
+ end
60
+
61
+ it 'handles a rubocop report for files changed in the PR' do
62
+ allow(@rubocop.git).to receive(:added_files).and_return([])
63
+ allow(@rubocop.git).to receive(:modified_files)
64
+ .and_return(["spec/fixtures/another_ruby_file.rb"])
65
+
66
+ allow(@rubocop).to receive(:`)
67
+ .with('bundle exec rubocop -f json')
68
+ .and_return(@rubocop_response)
69
+
70
+ @rubocop.lint
71
+
72
+ output = @rubocop.status_report[:markdowns].first
73
+
74
+ expect(output).to_not be_empty
75
+ expect(output).to include('Rubocop violations')
76
+ expect(output).to include("spec/fixtures/another_ruby_file.rb | 23 | Don't do that!")
50
77
  end
51
78
 
52
- it 'handles no files' do
79
+ it 'is formatted as a markdown table' do
53
80
  allow(@rubocop.git).to receive(:modified_files)
54
81
  .and_return(['spec/fixtures/ruby_file.rb'])
55
82
  allow(@rubocop.git).to receive(:added_files).and_return([])
56
83
  allow(@rubocop).to receive(:`)
57
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
84
+ .with('bundle exec rubocop -f json')
58
85
  .and_return(@rubocop_response)
59
86
 
60
87
  @rubocop.lint
61
88
 
62
- expect(@rubocop.status_report[:markdowns].first).to_not be_empty
89
+ formatted_table = <<-EOS
90
+ ### Rubocop violations\n
91
+ | File | Line | Reason |
92
+ |----------------------------|------|----------------|
93
+ | spec/fixtures/ruby_file.rb | 13 | Don't do that! |
94
+ EOS
95
+ expect(@rubocop.status_report[:markdowns].first).to eq(formatted_table.chomp)
63
96
  end
64
97
  end
65
98
  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.2.0
4
+ version: 0.3.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: 2016-07-23 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  version: '0'
191
191
  requirements: []
192
192
  rubyforge_project:
193
- rubygems_version: 2.4.8
193
+ rubygems_version: 2.0.14.1
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: A Danger plugin for running Ruby files through Rubocop.
@@ -198,3 +198,4 @@ test_files:
198
198
  - spec/danger_plugin_spec.rb
199
199
  - spec/fixtures/ruby_file.rb
200
200
  - spec/spec_helper.rb
201
+ has_rdoc: