danger-rubocop 0.6.0 → 0.8.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
- SHA1:
3
- metadata.gz: c59cd45d4ce8230e467669d6b3a3ffdfe3c1e7f9
4
- data.tar.gz: f151f971948bba931f159166bc01cc4ad00d21c6
2
+ SHA256:
3
+ metadata.gz: 2f4f324de45d03bd83bdfe10a4047a57a478d897894b78405aff02dcadfe62b1
4
+ data.tar.gz: 40dea7d522d011835462370782a4441e231c1f9ed49374e8a606fedf39ce2e54
5
5
  SHA512:
6
- metadata.gz: e10b05bfaf61a28f2d36208ca1bd1136fcad1106b8114586fc8cfc6e5a2282782fe9a30a07e962a12df3856791bdab2eb340a818e5689b1a372fedc468c35b5e
7
- data.tar.gz: f742ec5a40f95ad439a01d9026216ca14643fd3ffec8b2f836c792f7e83da7939fbf3c10e0aca42f83cf08f46a8622b4041b493815066d0293752db21c5c1feb
6
+ metadata.gz: 894b86cde281f23c4f49721b5a059d7257bc6c622e60a2999d0bfef5eeeb1c8d90cd20fd713c37e679f4ef2882d6e5b314b70bd8350102c90b0cdd9d0340fce3
7
+ data.tar.gz: 4a03ca834ad41fc8ecabd91268ceea09af5b2cdf6c622a5f0cbe88b2c62d92562a74e107c0964986111386ad54112d733a2b9ec0837ba29c3dccb6511bcb63d2
@@ -0,0 +1,30 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6
6
+
7
+ working_directory: ~/repo
8
+
9
+ steps:
10
+ - checkout
11
+
12
+ - restore_cache:
13
+ keys:
14
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
15
+ # fallback to using the latest cache if no exact match is found
16
+ - v1-dependencies-
17
+
18
+ - run:
19
+ name: install dependencies
20
+ command: |
21
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
22
+
23
+ - save_cache:
24
+ paths:
25
+ - ./vendor/bundle
26
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
27
+
28
+ - run:
29
+ name: run tests
30
+ command: bundle exec rake spec
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
 
@@ -1,45 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-rubocop (0.3.0)
4
+ danger-rubocop (0.8.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.0)
12
- public_suffix (~> 2.0, >= 2.0.2)
13
- ast (2.3.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.1)
14
14
  bacon (1.2.0)
15
- claide (1.0.1)
15
+ claide (1.0.3)
16
16
  claide-plugins (0.9.2)
17
17
  cork
18
18
  nap
19
19
  open4 (~> 1.3)
20
20
  coderay (1.1.1)
21
- colored (1.2)
22
- cork (0.2.0)
23
- colored (~> 1.2)
24
- danger (4.0.2)
21
+ colored2 (3.1.2)
22
+ cork (0.3.0)
23
+ colored2 (~> 3.1)
24
+ danger (8.0.1)
25
25
  claide (~> 1.0)
26
26
  claide-plugins (>= 0.9.2)
27
- colored (~> 1.2)
27
+ colored2 (~> 3.1)
28
28
  cork (~> 0.1)
29
- faraday (~> 0.9)
30
- faraday-http-cache (~> 1.0)
31
- git (~> 1)
32
- kramdown (~> 1.5)
33
- octokit (~> 4.2)
29
+ faraday (>= 0.9.0, < 2.0)
30
+ faraday-http-cache (~> 2.0)
31
+ git (~> 1.7)
32
+ kramdown (~> 2.0)
33
+ kramdown-parser-gfm (~> 1.0)
34
+ no_proxy_fix
35
+ octokit (~> 4.7)
34
36
  terminal-table (~> 1)
35
37
  diff-lcs (1.2.5)
36
- faraday (0.10.0)
38
+ faraday (1.0.1)
37
39
  multipart-post (>= 1.2, < 3)
38
- faraday-http-cache (1.3.1)
39
- faraday (~> 0.8)
40
+ faraday-http-cache (2.2.0)
41
+ faraday (>= 0.8)
40
42
  ffi (1.9.10)
41
43
  formatador (0.2.5)
42
- git (1.3.0)
44
+ git (1.7.0)
45
+ rchardet (~> 1.8)
43
46
  guard (2.14.0)
44
47
  formatador (>= 0.2.4)
45
48
  listen (>= 2.7, < 4.0)
@@ -54,7 +57,10 @@ GEM
54
57
  guard (~> 2.1)
55
58
  guard-compat (~> 1.1)
56
59
  rspec (>= 2.99.0, < 4.0)
57
- kramdown (1.13.1)
60
+ kramdown (2.2.1)
61
+ rexml
62
+ kramdown-parser-gfm (1.1.0)
63
+ kramdown (~> 2.0)
58
64
  listen (3.0.7)
59
65
  rb-fsevent (>= 0.9.3)
60
66
  rb-inotify (>= 0.9.7)
@@ -65,30 +71,35 @@ GEM
65
71
  metaclass (~> 0.0.1)
66
72
  mocha-on-bacon (0.2.2)
67
73
  mocha (>= 0.13.0)
68
- multipart-post (2.0.0)
74
+ multipart-post (2.1.1)
69
75
  nap (1.1.0)
70
76
  nenv (0.3.0)
77
+ no_proxy_fix (0.1.2)
71
78
  notiffany (0.1.0)
72
79
  nenv (~> 0.1)
73
80
  shellany (~> 0.0)
74
- octokit (4.6.2)
81
+ octokit (4.18.0)
82
+ faraday (>= 0.9)
75
83
  sawyer (~> 0.8.0, >= 0.5.3)
76
84
  open4 (1.3.4)
77
- parser (2.3.3.1)
78
- ast (~> 2.2)
79
- powerpack (0.1.1)
85
+ parallel (1.19.1)
86
+ parser (2.7.1.3)
87
+ ast (~> 2.4.0)
80
88
  prettybacon (0.0.2)
81
89
  bacon (~> 1.2)
82
90
  pry (0.10.3)
83
91
  coderay (~> 1.1.0)
84
92
  method_source (~> 0.8.1)
85
93
  slop (~> 3.4)
86
- public_suffix (2.0.4)
87
- rainbow (2.1.0)
88
- rake (10.5.0)
94
+ public_suffix (4.0.5)
95
+ rainbow (3.0.0)
96
+ rake (13.0.1)
89
97
  rb-fsevent (0.9.7)
90
98
  rb-inotify (0.9.7)
91
99
  ffi (>= 0.5.0)
100
+ rchardet (1.8.0)
101
+ regexp_parser (1.7.1)
102
+ rexml (3.2.4)
92
103
  rspec (3.4.0)
93
104
  rspec-core (~> 3.4.0)
94
105
  rspec-expectations (~> 3.4.0)
@@ -102,23 +113,28 @@ GEM
102
113
  diff-lcs (>= 1.2.0, < 2.0)
103
114
  rspec-support (~> 3.4.0)
104
115
  rspec-support (3.4.1)
105
- rubocop (0.46.0)
106
- parser (>= 2.3.1.1, < 3.0)
107
- powerpack (~> 0.1)
108
- rainbow (>= 1.99.1, < 3.0)
116
+ rubocop (0.85.1)
117
+ parallel (~> 1.10)
118
+ parser (>= 2.7.0.1)
119
+ rainbow (>= 2.2.2, < 4.0)
120
+ regexp_parser (>= 1.7)
121
+ rexml
122
+ rubocop-ast (>= 0.0.3)
109
123
  ruby-progressbar (~> 1.7)
110
- unicode-display_width (~> 1.0, >= 1.0.1)
111
- ruby-progressbar (1.8.1)
112
- sawyer (0.8.1)
113
- addressable (>= 2.3.5, < 2.6)
114
- faraday (~> 0.8, < 1.0)
124
+ unicode-display_width (>= 1.4.0, < 2.0)
125
+ rubocop-ast (0.0.3)
126
+ parser (>= 2.7.0.1)
127
+ ruby-progressbar (1.10.1)
128
+ sawyer (0.8.2)
129
+ addressable (>= 2.3.5)
130
+ faraday (> 0.8, < 2.0)
115
131
  shellany (0.0.1)
116
132
  slop (3.6.0)
117
- terminal-table (1.7.3)
118
- unicode-display_width (~> 1.1.1)
133
+ terminal-table (1.8.0)
134
+ unicode-display_width (~> 1.1, >= 1.1.1)
119
135
  thor (0.19.1)
120
- unicode-display_width (1.1.1)
121
- yard (0.9.5)
136
+ unicode-display_width (1.7.0)
137
+ yard (0.9.20)
122
138
 
123
139
  PLATFORMS
124
140
  ruby
@@ -134,12 +150,12 @@ DEPENDENCIES
134
150
  mocha-on-bacon
135
151
  prettybacon
136
152
  pry
137
- rake (~> 10.0)
153
+ rake (~> 13.0)
138
154
  rspec (~> 3.4)
139
155
  yard
140
156
 
141
157
  RUBY VERSION
142
- ruby 2.3.1p112
158
+ ruby 2.6.0p0
143
159
 
144
160
  BUNDLED WITH
145
- 1.13.6
161
+ 1.17.3
data/README.md CHANGED
@@ -30,6 +30,12 @@ public_files = (git.modified_files + git.added_files).select { |path| path.inclu
30
30
  rubocop.lint public_files
31
31
  ```
32
32
 
33
+ > Submit comments only for changed lines
34
+
35
+ ```ruby
36
+ github.dismiss_out_of_range_messages
37
+ rubocop.lint inline_comment: true
38
+ ```
33
39
 
34
40
  #### Methods
35
41
 
@@ -37,16 +43,21 @@ rubocop.lint public_files
37
43
 
38
44
  Runs Ruby files through Rubocop. Generates a `markdown` list of warnings.
39
45
 
40
- This method accepts configuration hash.
46
+ This method accepts a configuration hash.
41
47
  The following keys are supported:
42
48
 
43
49
  * `files`: array of file names or glob patterns to determine files to lint
44
50
  * `force_exclusion`: pass `true` to pass `--force-exclusion` argument to Rubocop.
45
- * `inline_comment`: pass `true` to comment inline of the diffs.
46
- * `report_danger`: pass true to report errors to Danger, and break CI.
47
-
48
51
  (this option will instruct rubocop to ignore the files that your rubocop config ignores,
49
52
  despite the plugin providing the list of files explicitely)
53
+ * `inline_comment`: pass `true` to comment inline of the diffs.
54
+ * `fail_on_inline_comment`: pass `true` to use `fail` instead of `warn` on inline comment.
55
+ * `report_danger`: pass true to report errors to Danger, and break CI.
56
+ * `config`: path to the `.rubocop.yml` file.
57
+ * `only_report_new_offenses`: pass `true` to only report offenses that are in current user's scope.
58
+ Note that this won't mark offenses for _Metrics/XXXLength_ if you add lines to an already existing scope.
59
+ * `include_cop_names`: Prepends cop names to the output messages. Example: "Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end."
60
+
50
61
 
51
62
  Passing `files` as only argument is also supported for backward compatibility.
52
63
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  # General ruby development
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
25
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
26
 
27
27
  # For validating the plugin lints
28
28
  spec.add_development_dependency 'yard'
@@ -30,39 +30,71 @@ 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
37
+ fail_on_inline_comment = config[:fail_on_inline_comment] || false
38
+ include_cop_names = config[:include_cop_names] || false
36
39
 
37
40
  files_to_lint = fetch_files_to_lint(files)
38
- files_to_report = rubocop(files_to_lint, force_exclusion)
41
+ files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, config_path: config_path)
39
42
 
40
43
  return if files_to_report.empty?
41
44
  return report_failures files_to_report if report_danger
42
45
 
43
46
  if inline_comment
44
- warn_each_line(files_to_report)
47
+ add_violation_for_each_line(files_to_report, fail_on_inline_comment, include_cop_names: include_cop_names)
45
48
  else
46
- markdown offenses_message(files_to_report)
49
+ markdown offenses_message(files_to_report, include_cop_names: include_cop_names)
47
50
  end
48
-
49
51
  end
50
52
 
51
53
  private
52
54
 
53
- def rubocop(files_to_lint, force_exclusion)
54
- base_command = 'rubocop -f json'
55
- base_command << ' --force-exclusion' if force_exclusion
55
+ def rubocop(files_to_lint, force_exclusion, only_report_new_offenses, config_path: nil)
56
+ base_command = ['rubocop', '-f', 'json', '--only-recognized-file-types']
57
+ base_command.concat(['--force-exclusion']) if force_exclusion
58
+ base_command.concat(['--config', config_path.shellescape]) unless config_path.nil?
56
59
 
57
- rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command} #{files_to_lint}`
60
+ rubocop_output = `#{'bundle exec ' if File.exist?('Gemfile')}#{base_command.join(' ')} #{files_to_lint}`
58
61
 
59
62
  return [] if rubocop_output.empty?
60
63
 
61
- JSON.parse(rubocop_output)['files']
62
- .select { |f| f['offenses'].any? }
64
+ files = JSON.parse(rubocop_output)['files']
65
+
66
+ filter_out_offenses(files) if only_report_new_offenses
67
+
68
+ files.select { |f| f['offenses'].any? }
63
69
  end
64
70
 
65
- def offenses_message(offending_files)
71
+ def filter_out_offenses(files)
72
+ files.each do |file|
73
+ added_lines = added_lines(file['path']).to_set
74
+ file['offenses'].select! do |offense|
75
+ added_lines.include?(offense['location']['line'])
76
+ end
77
+ end
78
+ end
79
+
80
+ def added_lines(path)
81
+ git.diff_for_file(path)
82
+ .patch
83
+ .split("\n@@")
84
+ .tap(&:shift)
85
+ .flat_map do |chunk|
86
+ first_line, *diff = chunk.split("\n")
87
+ # Get start from diff.
88
+ lineno = first_line.match(/\+(\d+),(\d+)/).captures.first.to_i
89
+ diff.each_with_object([]) do |current_line, added_lines|
90
+ added_lines << lineno if current_line.start_with?('+')
91
+ lineno += 1 unless current_line.start_with?('-')
92
+ added_lines
93
+ end
94
+ end
95
+ end
96
+
97
+ def offenses_message(offending_files, include_cop_names: false)
66
98
  require 'terminal-table'
67
99
 
68
100
  message = "### Rubocop violations\n\n"
@@ -71,7 +103,9 @@ module Danger
71
103
  style: { border_i: '|' },
72
104
  rows: offending_files.flat_map do |file|
73
105
  file['offenses'].map do |offense|
74
- [file['path'], offense['location']['line'], offense['message']]
106
+ offense_message = offense['message']
107
+ offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
108
+ [file['path'], offense['location']['line'], offense_message]
75
109
  end
76
110
  end
77
111
  ).to_s
@@ -86,10 +120,23 @@ module Danger
86
120
  end
87
121
  end
88
122
 
89
- def warn_each_line(offending_files)
123
+ def add_violation_for_each_line(offending_files, fail_on_inline_comment, include_cop_names: false)
90
124
  offending_files.flat_map do |file|
91
125
  file['offenses'].map do |offense|
92
- warn(offense['message'], file: file['path'], line: offense['location']['line'])
126
+ offense_message = offense['message']
127
+ offense_message = offense['cop_name'] + ': ' + offense_message if include_cop_names
128
+ arguments = [
129
+ offense_message,
130
+ {
131
+ file: file['path'],
132
+ line: offense['location']['line']
133
+ }
134
+ ]
135
+ if fail_on_inline_comment
136
+ fail(*arguments)
137
+ else
138
+ warn(*arguments)
139
+ end
93
140
  end
94
141
  end
95
142
  end
@@ -1,3 +1,3 @@
1
1
  module DangerRubocop
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.8.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,103 @@ 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' => 41 }
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' => 41 }
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ )
88
+ end
89
+ end
90
+
91
+ describe :added_lines do
92
+ before do
93
+ allow(@rubocop.git).to receive(:diff_for_file).with('SAMPLE') do
94
+ instance_double('Git::Diff::DiffFile', patch: <<~DIFF)
95
+ diff --git a/SAMPLE b/SAMPLE
96
+ new file mode 100644
97
+ index 0000000..7bba8c8
98
+ --- /dev/null
99
+ +++ b/SAMPLE
100
+ @@ -0,0 +1,2 @@
101
+ +line 1
102
+ +line 2
103
+ DIFF
104
+ end
105
+ end
106
+
107
+ it 'handles git diff' do
108
+ expect(@rubocop.send(:added_lines, 'SAMPLE')).to eq([1, 2])
109
+ end
110
+ end
111
+
15
112
  describe :lint_files do
16
113
  let(:response_ruby_file) do
17
114
  {
@@ -20,6 +117,7 @@ module Danger
20
117
  'path' => 'spec/fixtures/ruby_file.rb',
21
118
  'offenses' => [
22
119
  {
120
+ 'cop_name' => 'Syntax/WhetherYouShouldDoThat',
23
121
  'message' => "Don't do that!",
24
122
  'location' => { 'line' => 13 }
25
123
  }
@@ -36,6 +134,7 @@ module Danger
36
134
  'path' => 'spec/fixtures/another_ruby_file.rb',
37
135
  'offenses' => [
38
136
  {
137
+ 'cop_name' => 'Syntax/WhetherYouShouldDoThat',
39
138
  'message' => "Don't do that!",
40
139
  'location' => { 'line' => 23 }
41
140
  }
@@ -47,11 +146,11 @@ module Danger
47
146
 
48
147
  it 'handles a rubocop report for specified files' do
49
148
  allow(@rubocop).to receive(:`)
50
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
149
+ .with('bundle exec rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
51
150
  .and_return(response_ruby_file)
52
151
 
53
152
  # Do it
54
- @rubocop.lint(files: 'spec/fixtures/ruby*.rb')
153
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml')
55
154
 
56
155
  output = @rubocop.status_report[:markdowns].first.message
57
156
 
@@ -61,9 +160,25 @@ module Danger
61
160
  expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Don't do that!")
62
161
  end
63
162
 
163
+ it 'includes cop names when include_cop_names is set' do
164
+ allow(@rubocop).to receive(:`)
165
+ .with('bundle exec rubocop -f json --only-recognized-file-types --config path/to/rubocop.yml spec/fixtures/ruby_file.rb')
166
+ .and_return(response_ruby_file)
167
+
168
+ # Do it
169
+ @rubocop.lint(files: 'spec/fixtures/ruby*.rb', config: 'path/to/rubocop.yml', include_cop_names: true)
170
+
171
+ output = @rubocop.status_report[:markdowns].first.message
172
+
173
+ # A title
174
+ expect(output).to include('Rubocop violations')
175
+ # A warning
176
+ expect(output).to include("spec/fixtures/ruby_file.rb | 13 | Syntax/WhetherYouShouldDoThat: Don't do that!")
177
+ end
178
+
64
179
  it 'handles a rubocop report for specified files (legacy)' do
65
180
  allow(@rubocop).to receive(:`)
66
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
181
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
67
182
  .and_return(response_ruby_file)
68
183
 
69
184
  # Do it
@@ -79,7 +194,7 @@ module Danger
79
194
 
80
195
  it 'appends --force-exclusion argument when force_exclusion is set' do
81
196
  allow(@rubocop).to receive(:`)
82
- .with('bundle exec rubocop -f json --force-exclusion spec/fixtures/ruby_file.rb')
197
+ .with('bundle exec rubocop -f json --only-recognized-file-types --force-exclusion spec/fixtures/ruby_file.rb')
83
198
  .and_return(response_ruby_file)
84
199
 
85
200
  # Do it
@@ -99,7 +214,7 @@ module Danger
99
214
  .and_return(["spec/fixtures/another_ruby_file.rb"])
100
215
 
101
216
  allow(@rubocop).to receive(:`)
102
- .with('bundle exec rubocop -f json spec/fixtures/another_ruby_file.rb')
217
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/another_ruby_file.rb')
103
218
  .and_return(response_another_ruby_file)
104
219
 
105
220
  @rubocop.lint
@@ -115,7 +230,7 @@ module Danger
115
230
  .and_return(['spec/fixtures/ruby_file.rb'])
116
231
  allow(@rubocop.git).to receive(:added_files).and_return([])
117
232
  allow(@rubocop).to receive(:`)
118
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
233
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
119
234
  .and_return(response_ruby_file)
120
235
 
121
236
  @rubocop.lint
@@ -130,18 +245,38 @@ EOS
130
245
  expect(@rubocop).not_to receive(:fail)
131
246
  end
132
247
 
133
- it 'is reported as line by line' do
134
- allow(@rubocop.git).to receive(:modified_files)
135
- .and_return(['spec/fixtures/ruby_file.rb'])
136
- allow(@rubocop.git).to receive(:added_files).and_return([])
137
- allow(@rubocop).to receive(:`)
138
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
139
- .and_return(response_ruby_file)
248
+ context 'with inline_comment option' do
249
+ context 'without fail_on_inline_comment option' do
250
+ it 'reports violations as line by line warnings' do
251
+ allow(@rubocop.git).to receive(:modified_files)
252
+ .and_return(['spec/fixtures/ruby_file.rb'])
253
+ allow(@rubocop.git).to receive(:added_files).and_return([])
254
+ allow(@rubocop).to receive(:`)
255
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
256
+ .and_return(response_ruby_file)
257
+
258
+ @rubocop.lint(inline_comment: true)
259
+
260
+ expect(@rubocop.violation_report[:warnings].first.to_s)
261
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: warning }")
262
+ end
263
+ end
264
+
265
+ context 'with fail_on_inline_comment option' do
266
+ it 'reports violations as line by line failures' do
267
+ allow(@rubocop.git).to receive(:modified_files)
268
+ .and_return(['spec/fixtures/ruby_file.rb'])
269
+ allow(@rubocop.git).to receive(:added_files).and_return([])
270
+ allow(@rubocop).to receive(:`)
271
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
272
+ .and_return(response_ruby_file)
140
273
 
141
- @rubocop.lint(inline_comment: true)
274
+ @rubocop.lint(fail_on_inline_comment: true, inline_comment: true)
142
275
 
143
- expect(@rubocop.violation_report[:warnings].first.to_s)
144
- .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13 }")
276
+ expect(@rubocop.violation_report[:errors].first.to_s)
277
+ .to eq("Violation Don't do that! { sticky: false, file: spec/fixtures/ruby_file.rb, line: 13, type: error }")
278
+ end
279
+ end
145
280
  end
146
281
 
147
282
  describe 'a filename with special characters' do
@@ -166,7 +301,7 @@ EOS
166
301
  .and_return(['spec/fixtures/ruby_file.rb'])
167
302
  allow(@rubocop.git).to receive(:added_files).and_return([])
168
303
  allow(@rubocop).to receive(:`)
169
- .with('bundle exec rubocop -f json spec/fixtures/ruby_file.rb')
304
+ .with('bundle exec rubocop -f json --only-recognized-file-types spec/fixtures/ruby_file.rb')
170
305
  .and_return(response_ruby_file)
171
306
 
172
307
  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.6.0
4
+ version: 0.8.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: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +156,7 @@ executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
+ - ".circleci/config.yml"
159
160
  - ".gitignore"
160
161
  - Gemfile
161
162
  - Gemfile.lock
@@ -163,7 +164,6 @@ files:
163
164
  - LICENSE
164
165
  - README.md
165
166
  - Rakefile
166
- - circle.yml
167
167
  - danger-rubocop.gemspec
168
168
  - lib/danger_plugin.rb
169
169
  - lib/version.rb
@@ -192,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.6.11
195
+ rubygems_version: 3.0.1
197
196
  signing_key:
198
197
  specification_version: 4
199
198
  summary: A Danger plugin for running Ruby files through Rubocop.
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- machine:
2
- ruby:
3
- version: "2.2.5"