guard-rubocop 1.0.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +33 -4
- data/.rubocop_todo.yml +12 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -3
- data/Guardfile +13 -9
- data/README.md +50 -7
- data/Rakefile +4 -17
- data/guard-rubocop.gemspec +16 -13
- data/lib/guard/rubocop.rb +10 -8
- data/lib/guard/rubocop/runner.rb +30 -14
- data/lib/guard/rubocop/templates/Guardfile +1 -1
- data/lib/guard/rubocop/version.rb +10 -12
- data/spec/guard/rubocop/runner_spec.rb +169 -79
- data/spec/guard/rubocop_spec.rb +29 -28
- data/spec/spec_helper.rb +21 -19
- data/spec/support/silence_output.rb +20 -7
- data/spec/support/simplecov.rb +19 -0
- metadata +43 -37
- data/.travis.yml +0 -8
- data/spec/.rubocop.yml +0 -5
@@ -1,16 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
PATCH = 1
|
3
|
+
# A workaround for declaring `class RuboCop`
|
4
|
+
# before `class RuboCop < Guard` in rubocop.rb
|
5
|
+
module GuardRuboCopVersion
|
6
|
+
# http://semver.org/
|
7
|
+
MAJOR = 1
|
8
|
+
MINOR = 4
|
9
|
+
PATCH = 0
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
def self.to_s
|
12
|
+
[MAJOR, MINOR, PATCH].join('.')
|
15
13
|
end
|
16
14
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'launchy'
|
4
4
|
|
5
|
-
describe Guard::
|
6
|
-
subject(:runner) { Guard::
|
5
|
+
RSpec.describe Guard::RuboCop::Runner do
|
6
|
+
subject(:runner) { Guard::RuboCop::Runner.new(options) }
|
7
7
|
let(:options) { {} }
|
8
8
|
|
9
9
|
describe '#run' do
|
@@ -25,14 +25,14 @@ describe Guard::Rubocop::Runner do
|
|
25
25
|
before do
|
26
26
|
allow(runner).to receive(:system).and_return(true)
|
27
27
|
end
|
28
|
-
it { should
|
28
|
+
it { should be_truthy }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when RuboCop exited with non 0 status' do
|
32
32
|
before do
|
33
33
|
allow(runner).to receive(:system).and_return(false)
|
34
34
|
end
|
35
|
-
it { should
|
35
|
+
it { should be_falsey }
|
36
36
|
end
|
37
37
|
|
38
38
|
shared_examples 'notifies', :notifies do
|
@@ -77,56 +77,95 @@ describe Guard::Rubocop::Runner do
|
|
77
77
|
|
78
78
|
context 'when :notification option is true' do
|
79
79
|
let(:options) { { notification: true } }
|
80
|
-
include_examples 'notification',
|
80
|
+
include_examples 'notification', passed: true, failed: true
|
81
81
|
end
|
82
82
|
|
83
83
|
context 'when :notification option is :failed' do
|
84
84
|
let(:options) { { notification: :failed } }
|
85
|
-
include_examples 'notification',
|
85
|
+
include_examples 'notification', passed: false, failed: true
|
86
86
|
end
|
87
87
|
|
88
88
|
context 'when :notification option is false' do
|
89
89
|
let(:options) { { notification: false } }
|
90
|
-
include_examples 'notification',
|
90
|
+
include_examples 'notification', passed: false, failed: false
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when :launchy option is present' do
|
94
|
+
let(:options) { { launchy: 'launchy_path' } }
|
95
|
+
|
96
|
+
before do
|
97
|
+
allow(File).to receive(:exist?).with('launchy_path').and_return(true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'opens Launchy' do
|
101
|
+
expect(Launchy).to receive(:open).with('launchy_path')
|
102
|
+
runner.run(paths)
|
103
|
+
end
|
91
104
|
end
|
92
105
|
end
|
93
106
|
|
94
107
|
describe '#build_command' do
|
95
108
|
subject(:build_command) { runner.build_command(paths) }
|
96
|
-
let(:options) { { cli: %w
|
97
|
-
let(:paths) { %w
|
109
|
+
let(:options) { { cli: %w[--debug --rails] } }
|
110
|
+
let(:paths) { %w[file1.rb file2.rb] }
|
98
111
|
|
99
|
-
context 'when :
|
100
|
-
|
112
|
+
context 'when :hide_stdout is not set' do
|
113
|
+
context 'and :cli option includes formatter for console' do
|
114
|
+
before { options[:cli] = %w[--format simple] }
|
101
115
|
|
102
|
-
|
103
|
-
|
116
|
+
it 'does not add args for the default formatter for console' do
|
117
|
+
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'and :cli option does not include formatter for console' do
|
122
|
+
before { options[:cli] = %w[--format simple --out simple.txt] }
|
123
|
+
|
124
|
+
it 'adds args for the default formatter for console' do
|
125
|
+
expect(build_command[0..2]).to eq(%w[rubocop --format progress])
|
126
|
+
end
|
104
127
|
end
|
105
128
|
end
|
106
129
|
|
107
|
-
context 'when :
|
108
|
-
|
130
|
+
context 'when :hide_stdout is set' do
|
131
|
+
before { options[:hide_stdout] = true }
|
132
|
+
|
133
|
+
context 'and :cli option includes formatter for console' do
|
134
|
+
before { options[:cli] = %w[--format simple] }
|
135
|
+
|
136
|
+
it 'does not add args for the default formatter for console' do
|
137
|
+
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'and :cli option does not include formatter for console' do
|
142
|
+
before { options[:cli] = %w[--format simple --out simple.txt] }
|
109
143
|
|
110
|
-
|
111
|
-
|
144
|
+
it 'does not add args for the default formatter for console' do
|
145
|
+
expect(build_command[0..2]).not_to eq(%w[rubocop --format progress])
|
146
|
+
end
|
112
147
|
end
|
113
148
|
end
|
114
149
|
|
115
|
-
it 'adds args for JSON formatter
|
116
|
-
expect(build_command[3..4]).to eq(%w
|
150
|
+
it 'adds args for JSON formatter' do
|
151
|
+
expect(build_command[3..4]).to eq(%w[--format json])
|
117
152
|
end
|
118
153
|
|
119
|
-
it 'adds args for output file path of JSON formatter
|
154
|
+
it 'adds args for output file path of JSON formatter' do
|
120
155
|
expect(build_command[5]).to eq('--out')
|
121
156
|
expect(build_command[6]).not_to be_empty
|
122
157
|
end
|
123
158
|
|
159
|
+
it 'adds --force-exclusion option' do
|
160
|
+
expect(build_command[7]).to eq('--force-exclusion')
|
161
|
+
end
|
162
|
+
|
124
163
|
it 'adds args specified by user' do
|
125
|
-
expect(build_command[
|
164
|
+
expect(build_command[8..9]).to eq(%w[--debug --rails])
|
126
165
|
end
|
127
166
|
|
128
167
|
it 'adds the passed paths' do
|
129
|
-
expect(build_command[
|
168
|
+
expect(build_command[10..-1]).to eq(%w[file1.rb file2.rb])
|
130
169
|
end
|
131
170
|
end
|
132
171
|
|
@@ -159,7 +198,7 @@ describe Guard::Rubocop::Runner do
|
|
159
198
|
let(:options) { { cli: { key: 'value' } } }
|
160
199
|
|
161
200
|
it 'raises error' do
|
162
|
-
expect { runner.args_specified_by_user }.to raise_error
|
201
|
+
expect { runner.args_specified_by_user }.to raise_error(ArgumentError)
|
163
202
|
end
|
164
203
|
end
|
165
204
|
end
|
@@ -169,86 +208,86 @@ describe Guard::Rubocop::Runner do
|
|
169
208
|
|
170
209
|
context 'when the passed args include a -f/--format' do
|
171
210
|
context 'but does not include an -o/--output' do
|
172
|
-
let(:args) { %w
|
211
|
+
let(:args) { %w[--format simple --debug] }
|
173
212
|
|
174
213
|
it 'returns true' do
|
175
|
-
expect(include_formatter_for_console?).to
|
214
|
+
expect(include_formatter_for_console?).to be_truthy
|
176
215
|
end
|
177
216
|
end
|
178
217
|
|
179
218
|
context 'and include an -o/--output just after the -f/--format' do
|
180
|
-
let(:args) { %w
|
219
|
+
let(:args) { %w[--format simple --out simple.txt] }
|
181
220
|
|
182
221
|
it 'returns false' do
|
183
|
-
expect(include_formatter_for_console?).to
|
222
|
+
expect(include_formatter_for_console?).to be_falsey
|
184
223
|
end
|
185
224
|
end
|
186
225
|
|
187
226
|
context 'and include an -o/--output after the -f/--format across another arg' do
|
188
|
-
let(:args) { %w
|
227
|
+
let(:args) { %w[--format simple --debug --out simple.txt] }
|
189
228
|
|
190
229
|
it 'returns false' do
|
191
|
-
expect(include_formatter_for_console?).to
|
230
|
+
expect(include_formatter_for_console?).to be_falsey
|
192
231
|
end
|
193
232
|
end
|
194
233
|
end
|
195
234
|
|
196
235
|
context 'when the passed args include a -f with its arg without separator' do
|
197
236
|
context 'but does not include an -o/--output' do
|
198
|
-
let(:args) { %w
|
237
|
+
let(:args) { %w[-fs --debug] }
|
199
238
|
|
200
239
|
it 'returns true' do
|
201
|
-
expect(include_formatter_for_console?).to
|
240
|
+
expect(include_formatter_for_console?).to be_truthy
|
202
241
|
end
|
203
242
|
end
|
204
243
|
|
205
244
|
context 'and include an -o with its arg without separator just after the -f/--format' do
|
206
|
-
let(:args) { %w
|
245
|
+
let(:args) { %w[-fs -osimple.txt] }
|
207
246
|
|
208
247
|
it 'returns false' do
|
209
|
-
expect(include_formatter_for_console?).to
|
248
|
+
expect(include_formatter_for_console?).to be_falsey
|
210
249
|
end
|
211
250
|
end
|
212
251
|
end
|
213
252
|
|
214
253
|
context 'when the passed args include multiple -f/--format' do
|
215
254
|
context 'and all -f/--format have associated -o/--out' do
|
216
|
-
let(:args) { %w
|
255
|
+
let(:args) { %w[--format simple --out simple.txt --format emacs --out emacs.txt] }
|
217
256
|
|
218
257
|
it 'returns false' do
|
219
|
-
expect(include_formatter_for_console?).to
|
258
|
+
expect(include_formatter_for_console?).to be_falsey
|
220
259
|
end
|
221
260
|
end
|
222
261
|
|
223
262
|
context 'and any -f/--format has associated -o/--out' do
|
224
|
-
let(:args) { %w
|
263
|
+
let(:args) { %w[--format simple --format emacs --out emacs.txt] }
|
225
264
|
|
226
265
|
it 'returns true' do
|
227
|
-
expect(include_formatter_for_console?).to
|
266
|
+
expect(include_formatter_for_console?).to be_truthy
|
228
267
|
end
|
229
268
|
end
|
230
269
|
|
231
270
|
context 'and no -f/--format has associated -o/--out' do
|
232
|
-
let(:args) { %w
|
271
|
+
let(:args) { %w[--format simple --format emacs] }
|
233
272
|
|
234
273
|
it 'returns true' do
|
235
|
-
expect(include_formatter_for_console?).to
|
274
|
+
expect(include_formatter_for_console?).to be_truthy
|
236
275
|
end
|
237
276
|
end
|
238
277
|
end
|
239
278
|
|
240
279
|
context 'when the passed args do not include -f/--format' do
|
241
|
-
let(:args) { %w
|
280
|
+
let(:args) { %w[--debug] }
|
242
281
|
|
243
282
|
it 'returns false' do
|
244
|
-
expect(include_formatter_for_console?).to
|
283
|
+
expect(include_formatter_for_console?).to be_falsey
|
245
284
|
end
|
246
285
|
end
|
247
286
|
end
|
248
287
|
|
249
288
|
describe '#json_file_path' do
|
250
289
|
it 'is not world readable' do
|
251
|
-
expect(File.world_readable?(runner.json_file_path)).to
|
290
|
+
expect(File.world_readable?(runner.json_file_path)).to be_falsey
|
252
291
|
end
|
253
292
|
end
|
254
293
|
|
@@ -265,10 +304,10 @@ describe Guard::Rubocop::Runner do
|
|
265
304
|
},
|
266
305
|
"files": [{
|
267
306
|
"path": "lib/foo.rb",
|
268
|
-
"
|
307
|
+
"offenses": []
|
269
308
|
}, {
|
270
309
|
"path": "lib/bar.rb",
|
271
|
-
"
|
310
|
+
"offenses": [{
|
272
311
|
"severity": "convention",
|
273
312
|
"message": "Line is too long. [81/79]",
|
274
313
|
"cop_name": "LineLength",
|
@@ -289,7 +328,7 @@ describe Guard::Rubocop::Runner do
|
|
289
328
|
}
|
290
329
|
],
|
291
330
|
"summary": {
|
292
|
-
"
|
331
|
+
"offense_count": 2,
|
293
332
|
"target_file_count": 2,
|
294
333
|
"inspected_file_count": 2
|
295
334
|
}
|
@@ -301,32 +340,30 @@ describe Guard::Rubocop::Runner do
|
|
301
340
|
|
302
341
|
describe '#result', :json_file do
|
303
342
|
it 'parses JSON file' do
|
304
|
-
expect(runner.result[:summary][:
|
343
|
+
expect(runner.result[:summary][:offense_count]).to eq(2)
|
305
344
|
end
|
306
345
|
end
|
307
346
|
|
308
347
|
describe '#notify' do
|
309
348
|
before do
|
310
349
|
allow(runner).to receive(:result).and_return(
|
311
|
-
{
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
inspected_file_count: 2
|
316
|
-
}
|
350
|
+
summary: {
|
351
|
+
offense_count: 4,
|
352
|
+
target_file_count: 3,
|
353
|
+
inspected_file_count: 2
|
317
354
|
}
|
318
355
|
)
|
319
356
|
end
|
320
357
|
|
321
358
|
it 'notifies summary' do
|
322
|
-
expect(Guard::Notifier).to receive(:notify) do |message,
|
323
|
-
expect(message).to eq('2 files inspected, 4
|
359
|
+
expect(Guard::Notifier).to receive(:notify) do |message, _options|
|
360
|
+
expect(message).to eq('2 files inspected, 4 offenses detected')
|
324
361
|
end
|
325
362
|
runner.notify(true)
|
326
363
|
end
|
327
364
|
|
328
365
|
it 'notifies with title "RuboCop results"' do
|
329
|
-
expect(Guard::Notifier).to receive(:notify) do |
|
366
|
+
expect(Guard::Notifier).to receive(:notify) do |_message, options|
|
330
367
|
expect(options[:title]).to eq('RuboCop results')
|
331
368
|
end
|
332
369
|
runner.notify(true)
|
@@ -334,7 +371,7 @@ describe Guard::Rubocop::Runner do
|
|
334
371
|
|
335
372
|
context 'when passed' do
|
336
373
|
it 'shows success image' do
|
337
|
-
expect(Guard::Notifier).to receive(:notify) do |
|
374
|
+
expect(Guard::Notifier).to receive(:notify) do |_message, options|
|
338
375
|
expect(options[:image]).to eq(:success)
|
339
376
|
end
|
340
377
|
runner.notify(true)
|
@@ -343,7 +380,7 @@ describe Guard::Rubocop::Runner do
|
|
343
380
|
|
344
381
|
context 'when failed' do
|
345
382
|
it 'shows failed image' do
|
346
|
-
expect(Guard::Notifier).to receive(:notify) do |
|
383
|
+
expect(Guard::Notifier).to receive(:notify) do |_message, options|
|
347
384
|
expect(options[:image]).to eq(:failed)
|
348
385
|
end
|
349
386
|
runner.notify(false)
|
@@ -354,19 +391,17 @@ describe Guard::Rubocop::Runner do
|
|
354
391
|
describe '#summary_text' do
|
355
392
|
before do
|
356
393
|
allow(runner).to receive(:result).and_return(
|
357
|
-
{
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
inspected_file_count: inspected_file_count
|
362
|
-
}
|
394
|
+
summary: {
|
395
|
+
offense_count: offense_count,
|
396
|
+
target_file_count: target_file_count,
|
397
|
+
inspected_file_count: inspected_file_count
|
363
398
|
}
|
364
399
|
)
|
365
400
|
end
|
366
401
|
|
367
402
|
subject(:summary_text) { runner.summary_text }
|
368
403
|
|
369
|
-
let(:
|
404
|
+
let(:offense_count) { 0 }
|
370
405
|
let(:target_file_count) { 0 }
|
371
406
|
let(:inspected_file_count) { 0 }
|
372
407
|
|
@@ -391,31 +426,86 @@ describe Guard::Rubocop::Runner do
|
|
391
426
|
end
|
392
427
|
end
|
393
428
|
|
394
|
-
context 'when no
|
395
|
-
let(:
|
396
|
-
it 'includes "no
|
397
|
-
expect(summary_text).to include 'no
|
429
|
+
context 'when no offenses are detected' do
|
430
|
+
let(:offense_count) { 0 }
|
431
|
+
it 'includes "no offenses"' do
|
432
|
+
expect(summary_text).to include 'no offenses'
|
398
433
|
end
|
399
434
|
end
|
400
435
|
|
401
|
-
context 'when an
|
402
|
-
let(:
|
403
|
-
it 'includes "1
|
404
|
-
expect(summary_text).to include '1
|
436
|
+
context 'when an offense is detected' do
|
437
|
+
let(:offense_count) { 1 }
|
438
|
+
it 'includes "1 offense"' do
|
439
|
+
expect(summary_text).to include '1 offense'
|
405
440
|
end
|
406
441
|
end
|
407
442
|
|
408
|
-
context 'when 2
|
409
|
-
let(:
|
410
|
-
it 'includes "2
|
411
|
-
expect(summary_text).to include '2
|
443
|
+
context 'when 2 offenses are detected' do
|
444
|
+
let(:offense_count) { 2 }
|
445
|
+
it 'includes "2 offenses"' do
|
446
|
+
expect(summary_text).to include '2 offenses'
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
context 'with spelling "offence" in old RuboCop' do
|
451
|
+
before do
|
452
|
+
allow(runner).to receive(:result).and_return(
|
453
|
+
summary: {
|
454
|
+
offence_count: 2,
|
455
|
+
target_file_count: 1,
|
456
|
+
inspected_file_count: 1
|
457
|
+
}
|
458
|
+
)
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'handles the spelling' do
|
462
|
+
expect(summary_text).to include '2 offenses'
|
412
463
|
end
|
413
464
|
end
|
414
465
|
end
|
415
466
|
|
416
467
|
describe '#failed_paths', :json_file do
|
417
|
-
it 'returns file paths which have
|
468
|
+
it 'returns file paths which have offenses' do
|
418
469
|
expect(runner.failed_paths).to eq(['lib/bar.rb'])
|
419
470
|
end
|
471
|
+
|
472
|
+
context 'with spelling "offence" in old RuboCop' do
|
473
|
+
before do
|
474
|
+
json = <<-END
|
475
|
+
{
|
476
|
+
"files": [{
|
477
|
+
"path": "lib/foo.rb",
|
478
|
+
"offences": []
|
479
|
+
}, {
|
480
|
+
"path": "lib/bar.rb",
|
481
|
+
"offences": [{
|
482
|
+
"severity": "convention",
|
483
|
+
"message": "Line is too long. [81/79]",
|
484
|
+
"cop_name": "LineLength",
|
485
|
+
"location": {
|
486
|
+
"line": 546,
|
487
|
+
"column": 80
|
488
|
+
}
|
489
|
+
}, {
|
490
|
+
"severity": "warning",
|
491
|
+
"message": "Unreachable code detected.",
|
492
|
+
"cop_name": "UnreachableCode",
|
493
|
+
"location": {
|
494
|
+
"line": 15,
|
495
|
+
"column": 9
|
496
|
+
}
|
497
|
+
}
|
498
|
+
]
|
499
|
+
}
|
500
|
+
]
|
501
|
+
}
|
502
|
+
END
|
503
|
+
File.write(runner.json_file_path, json)
|
504
|
+
end
|
505
|
+
|
506
|
+
it 'handles the spelling' do
|
507
|
+
expect(runner.failed_paths).to eq(['lib/bar.rb'])
|
508
|
+
end
|
509
|
+
end
|
420
510
|
end
|
421
511
|
end
|