rubocop 0.23.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +35 -1
  4. data/CONTRIBUTING.md +1 -1
  5. data/README.md +6 -6
  6. data/config/default.yml +25 -6
  7. data/config/enabled.yml +20 -0
  8. data/lib/rubocop.rb +10 -13
  9. data/lib/rubocop/cli.rb +23 -20
  10. data/lib/rubocop/cop/lint/def_end_alignment.rb +47 -0
  11. data/lib/rubocop/cop/lint/end_alignment.rb +18 -65
  12. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
  13. data/lib/rubocop/cop/lint/syntax.rb +28 -4
  14. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +1 -1
  15. data/lib/rubocop/cop/lint/unused_block_argument.rb +13 -1
  16. data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -2
  17. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -9
  18. data/lib/rubocop/cop/lint/useless_setter_call.rb +28 -20
  19. data/lib/rubocop/cop/mixin/access_modifier_node.rb +18 -0
  20. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +4 -2
  21. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +42 -0
  22. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +32 -0
  23. data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -8
  24. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
  25. data/lib/rubocop/cop/offense.rb +27 -14
  26. data/lib/rubocop/cop/style/access_modifier_indentation.rb +2 -9
  27. data/lib/rubocop/cop/style/attr.rb +3 -1
  28. data/lib/rubocop/cop/style/class_check.rb +42 -0
  29. data/lib/rubocop/cop/style/each_with_object.rb +5 -1
  30. data/lib/rubocop/cop/style/empty_lines.rb +1 -4
  31. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +2 -8
  32. data/lib/rubocop/cop/style/empty_lines_around_body.rb +1 -4
  33. data/lib/rubocop/cop/style/encoding.rb +3 -5
  34. data/lib/rubocop/cop/style/end_of_line.rb +2 -5
  35. data/lib/rubocop/cop/style/file_name.rb +2 -4
  36. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -1
  37. data/lib/rubocop/cop/style/indentation_consistency.rb +2 -1
  38. data/lib/rubocop/cop/style/indentation_width.rb +25 -5
  39. data/lib/rubocop/cop/style/line_length.rb +59 -5
  40. data/lib/rubocop/cop/style/next.rb +18 -18
  41. data/lib/rubocop/cop/style/numeric_literals.rb +22 -9
  42. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
  43. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  44. data/lib/rubocop/cop/style/semicolon.rb +1 -3
  45. data/lib/rubocop/cop/style/space_after_colon.rb +7 -3
  46. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +3 -1
  47. data/lib/rubocop/cop/style/space_before_comma.rb +16 -0
  48. data/lib/rubocop/cop/style/space_before_semicolon.rb +16 -0
  49. data/lib/rubocop/cop/style/tab.rb +6 -5
  50. data/lib/rubocop/cop/style/trailing_comma.rb +33 -6
  51. data/lib/rubocop/cop/style/trailing_whitespace.rb +4 -3
  52. data/lib/rubocop/cop/style/unneeded_capital_w.rb +6 -0
  53. data/lib/rubocop/cop/style/unneeded_percent_q.rb +45 -0
  54. data/lib/rubocop/cop/style/unneeded_percent_x.rb +2 -3
  55. data/lib/rubocop/cop/style/word_array.rb +1 -1
  56. data/lib/rubocop/cop/team.rb +6 -12
  57. data/lib/rubocop/cop/util.rb +26 -8
  58. data/lib/rubocop/cop/variable_force.rb +3 -6
  59. data/lib/rubocop/cop/variable_force/variable.rb +7 -3
  60. data/lib/rubocop/processed_source.rb +52 -12
  61. data/lib/rubocop/{file_inspector.rb → runner.rb} +50 -59
  62. data/lib/rubocop/version.rb +1 -1
  63. data/relnotes/v0.24.0.md +77 -0
  64. data/rubocop.gemspec +4 -4
  65. data/spec/rubocop/cli_spec.rb +38 -21
  66. data/spec/rubocop/config_loader_spec.rb +7 -6
  67. data/spec/rubocop/config_spec.rb +8 -8
  68. data/spec/rubocop/cop/cop_spec.rb +1 -1
  69. data/spec/rubocop/cop/lint/def_end_alignment_spec.rb +108 -0
  70. data/spec/rubocop/cop/lint/end_alignment_spec.rb +0 -47
  71. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +6 -7
  72. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +19 -0
  73. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +8 -18
  74. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +99 -51
  75. data/spec/rubocop/cop/offense_spec.rb +3 -3
  76. data/spec/rubocop/cop/rails/delegate_spec.rb +1 -1
  77. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +12 -0
  78. data/spec/rubocop/cop/style/align_hash_spec.rb +4 -4
  79. data/spec/rubocop/cop/style/align_parameters_spec.rb +1 -1
  80. data/spec/rubocop/cop/style/attr_spec.rb +12 -2
  81. data/spec/rubocop/cop/style/class_check_spec.rb +41 -0
  82. data/spec/rubocop/cop/style/each_with_object_spec.rb +5 -0
  83. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +5 -0
  84. data/spec/rubocop/cop/style/indentation_width_spec.rb +95 -0
  85. data/spec/rubocop/cop/style/line_length_spec.rb +75 -0
  86. data/spec/rubocop/cop/style/next_spec.rb +28 -0
  87. data/spec/rubocop/cop/style/numeric_literals_spec.rb +10 -0
  88. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +5 -0
  89. data/spec/rubocop/cop/style/space_after_colon_spec.rb +17 -0
  90. data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +11 -0
  91. data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
  92. data/spec/rubocop/cop/style/space_before_comma_spec.rb +42 -0
  93. data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +28 -0
  94. data/spec/rubocop/cop/style/trailing_comma_spec.rb +37 -15
  95. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +8 -10
  96. data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +72 -0
  97. data/spec/rubocop/cop/style/word_array_spec.rb +6 -0
  98. data/spec/rubocop/cop/team_spec.rb +8 -8
  99. data/spec/rubocop/cop/util_spec.rb +10 -0
  100. data/spec/rubocop/cop/variable_force/assignment_spec.rb +1 -1
  101. data/spec/rubocop/cop/variable_force/locatable_spec.rb +1 -1
  102. data/spec/rubocop/cop/variable_force/scope_spec.rb +1 -1
  103. data/spec/rubocop/cop/variable_force/variable_spec.rb +4 -4
  104. data/spec/rubocop/formatter/base_formatter_spec.rb +5 -5
  105. data/spec/rubocop/formatter/colorizable_spec.rb +2 -2
  106. data/spec/rubocop/formatter/json_formatter_spec.rb +1 -1
  107. data/spec/rubocop/path_util_spec.rb +15 -15
  108. data/spec/rubocop/processed_source_spec.rb +104 -50
  109. data/spec/rubocop/runner_spec.rb +64 -0
  110. data/spec/spec_helper.rb +8 -10
  111. data/spec/support/shared_examples.rb +22 -0
  112. metadata +39 -15
  113. data/lib/rubocop/source_parser.rb +0 -47
  114. data/spec/rubocop/file_inspector_spec.rb +0 -84
  115. data/spec/rubocop/source_parser_spec.rb +0 -85
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module RuboCop
6
+ class Runner
7
+ attr_writer :errors # Needed only for testing.
8
+ end
9
+ end
10
+
11
+ describe RuboCop::Runner, :isolated_environment do
12
+ include FileHelper
13
+
14
+ subject(:runner) { described_class.new(options, RuboCop::ConfigStore.new) }
15
+ let(:options) { { formatters: [['progress', formatter_output_path]] } }
16
+ let(:formatter_output_path) { 'formatter_output.txt' }
17
+ let(:formatter_output) { File.read(formatter_output_path) }
18
+
19
+ before do
20
+ create_file('example.rb', source)
21
+ end
22
+
23
+ describe '#run' do
24
+ context 'if there are no offenses in inspected files' do
25
+ let(:source) { <<-END.strip_indent }
26
+ # coding: utf-8
27
+ def valid_code
28
+ end
29
+ END
30
+
31
+ it 'returns true' do
32
+ expect(runner.run([])).to be true
33
+ end
34
+ end
35
+
36
+ context 'if there is an offense in an inspected file' do
37
+ let(:source) { <<-END.strip_indent }
38
+ # coding: utf-8
39
+ def INVALID_CODE
40
+ end
41
+ END
42
+
43
+ it 'returns false' do
44
+ expect(runner.run([])).to be false
45
+ end
46
+
47
+ it 'sends the offense to a formatter' do
48
+ runner.run([])
49
+ expect(formatter_output).to eq <<-END.strip_indent
50
+ Inspecting 1 file
51
+ C
52
+
53
+ Offenses:
54
+
55
+ example.rb:2:5: C: Use snake_case for methods.
56
+ def INVALID_CODE
57
+ ^^^^^^^^^^^^
58
+
59
+ 1 file inspected, 1 offense detected
60
+ END
61
+ end
62
+ end
63
+ end
64
+ end
@@ -37,6 +37,7 @@ Rainbow.enabled = false
37
37
 
38
38
  module ExitCodeMatchers
39
39
  RSpec::Matchers.define :exit_with_code do |code|
40
+ supports_block_expectations
40
41
  actual = nil
41
42
  match do |block|
42
43
  begin
@@ -46,11 +47,11 @@ module ExitCodeMatchers
46
47
  end
47
48
  actual && actual == code
48
49
  end
49
- failure_message_for_should do
50
+ failure_message do
50
51
  "expected block to call exit(#{code}) but exit" +
51
52
  (actual.nil? ? ' not called' : "(#{actual}) was called")
52
53
  end
53
- failure_message_for_should_not do
54
+ failure_message_when_negated do
54
55
  "expected block not to call exit(#{code})"
55
56
  end
56
57
  description do
@@ -60,8 +61,6 @@ module ExitCodeMatchers
60
61
  end
61
62
 
62
63
  RSpec.configure do |config|
63
- config.treat_symbols_as_metadata_keys_with_true_values = true
64
-
65
64
  # These two settings work together to allow you to limit a spec run
66
65
  # to individual examples or groups you care about by tagging them with
67
66
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
@@ -99,15 +98,14 @@ end
99
98
 
100
99
  def parse_source(source, file = nil)
101
100
  source = source.join($RS) if source.is_a?(Array)
102
- if file.is_a? String
103
- RuboCop::SourceParser.parse(source, file)
104
- elsif file
101
+
102
+ if file && file.respond_to?(:write)
105
103
  file.write(source)
106
104
  file.rewind
107
- RuboCop::SourceParser.parse(source, file.path)
108
- else
109
- RuboCop::SourceParser.parse(source)
105
+ file = file.path
110
106
  end
107
+
108
+ RuboCop::ProcessedSource.new(source, file)
111
109
  end
112
110
 
113
111
  def autocorrect_source_file(cop, source)
@@ -31,3 +31,25 @@ shared_examples_for 'mimics MRI 2.1' do |grep_mri_warning|
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ shared_examples_for 'misaligned' do |prefix, alignment_base, arg, end_kw, name|
36
+ name ||= alignment_base
37
+ it "registers an offense for mismatched #{name} ... end" do
38
+ inspect_source(cop, ["#{prefix}#{alignment_base} #{arg}",
39
+ end_kw])
40
+ expect(cop.offenses.size).to eq(1)
41
+ regexp = /`end` at 2, \d+ is not aligned with `#{alignment_base}` at 1,/
42
+ expect(cop.messages.first).to match(regexp)
43
+ expect(cop.highlights.first).to eq('end')
44
+ expect(cop.config_to_allow_offenses).to eq('AlignWith' => opposite)
45
+ end
46
+ end
47
+
48
+ shared_examples_for 'aligned' do |alignment_base, arg, end_kw, name|
49
+ name ||= alignment_base
50
+ it "accepts matching #{name} ... end" do
51
+ inspect_source(cop, ["#{alignment_base} #{arg}",
52
+ end_kw])
53
+ expect(cop.offenses).to be_empty
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
+ - Jonas Arvidsson
9
+ - Yuji Nakayama
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2014-06-02 00:00:00.000000000 Z
13
+ date: 2014-06-25 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: rainbow
@@ -34,16 +36,22 @@ dependencies:
34
36
  name: parser
35
37
  requirement: !ruby/object:Gem::Requirement
36
38
  requirements:
37
- - - "~>"
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.2.0.pre.2
42
+ - - "<"
38
43
  - !ruby/object:Gem::Version
39
- version: 2.1.9
44
+ version: '3.0'
40
45
  type: :runtime
41
46
  prerelease: false
42
47
  version_requirements: !ruby/object:Gem::Requirement
43
48
  requirements:
44
- - - "~>"
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.2.0.pre.2
52
+ - - "<"
45
53
  - !ruby/object:Gem::Version
46
- version: 2.1.9
54
+ version: '3.0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: powerpack
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +120,14 @@ dependencies:
112
120
  requirements:
113
121
  - - "~>"
114
122
  - !ruby/object:Gem::Version
115
- version: '2.14'
123
+ version: '3.0'
116
124
  type: :development
117
125
  prerelease: false
118
126
  version_requirements: !ruby/object:Gem::Requirement
119
127
  requirements:
120
128
  - - "~>"
121
129
  - !ruby/object:Gem::Version
122
- version: '2.14'
130
+ version: '3.0'
123
131
  - !ruby/object:Gem::Dependency
124
132
  name: yard
125
133
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +173,7 @@ dependencies:
165
173
  description: |2
166
174
  Automatic Ruby code style checking tool.
167
175
  Aims to enforce the community-driven Ruby Style Guide.
168
- email: bozhidar@batsov.com
176
+ email: rubocop@googlegroups.com
169
177
  executables:
170
178
  - rubocop
171
179
  extensions: []
@@ -206,6 +214,7 @@ files:
206
214
  - lib/rubocop/cop/lint/block_alignment.rb
207
215
  - lib/rubocop/cop/lint/condition_position.rb
208
216
  - lib/rubocop/cop/lint/debugger.rb
217
+ - lib/rubocop/cop/lint/def_end_alignment.rb
209
218
  - lib/rubocop/cop/lint/deprecated_class_methods.rb
210
219
  - lib/rubocop/cop/lint/else_layout.rb
211
220
  - lib/rubocop/cop/lint/empty_ensure.rb
@@ -236,6 +245,7 @@ files:
236
245
  - lib/rubocop/cop/lint/useless_else_without_rescue.rb
237
246
  - lib/rubocop/cop/lint/useless_setter_call.rb
238
247
  - lib/rubocop/cop/lint/void.rb
248
+ - lib/rubocop/cop/mixin/access_modifier_node.rb
239
249
  - lib/rubocop/cop/mixin/annotation_comment.rb
240
250
  - lib/rubocop/cop/mixin/array_syntax.rb
241
251
  - lib/rubocop/cop/mixin/autocorrect_alignment.rb
@@ -246,6 +256,7 @@ files:
246
256
  - lib/rubocop/cop/mixin/configurable_enforced_style.rb
247
257
  - lib/rubocop/cop/mixin/configurable_max.rb
248
258
  - lib/rubocop/cop/mixin/configurable_naming.rb
259
+ - lib/rubocop/cop/mixin/end_keyword_alignment.rb
249
260
  - lib/rubocop/cop/mixin/if_node.rb
250
261
  - lib/rubocop/cop/mixin/if_then_else.rb
251
262
  - lib/rubocop/cop/mixin/negative_conditional.rb
@@ -253,6 +264,7 @@ files:
253
264
  - lib/rubocop/cop/mixin/percent_literal.rb
254
265
  - lib/rubocop/cop/mixin/safe_assignment.rb
255
266
  - lib/rubocop/cop/mixin/space_after_punctuation.rb
267
+ - lib/rubocop/cop/mixin/space_before_punctuation.rb
256
268
  - lib/rubocop/cop/mixin/space_inside.rb
257
269
  - lib/rubocop/cop/mixin/statement_modifier.rb
258
270
  - lib/rubocop/cop/mixin/string_help.rb
@@ -289,6 +301,7 @@ files:
289
301
  - lib/rubocop/cop/style/character_literal.rb
290
302
  - lib/rubocop/cop/style/class_and_module_camel_case.rb
291
303
  - lib/rubocop/cop/style/class_and_module_children.rb
304
+ - lib/rubocop/cop/style/class_check.rb
292
305
  - lib/rubocop/cop/style/class_length.rb
293
306
  - lib/rubocop/cop/style/class_methods.rb
294
307
  - lib/rubocop/cop/style/class_vars.rb
@@ -379,8 +392,10 @@ files:
379
392
  - lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb
380
393
  - lib/rubocop/cop/style/space_around_operators.rb
381
394
  - lib/rubocop/cop/style/space_before_block_braces.rb
395
+ - lib/rubocop/cop/style/space_before_comma.rb
382
396
  - lib/rubocop/cop/style/space_before_comment.rb
383
397
  - lib/rubocop/cop/style/space_before_modifier_keyword.rb
398
+ - lib/rubocop/cop/style/space_before_semicolon.rb
384
399
  - lib/rubocop/cop/style/space_inside_block_braces.rb
385
400
  - lib/rubocop/cop/style/space_inside_brackets.rb
386
401
  - lib/rubocop/cop/style/space_inside_hash_literal_braces.rb
@@ -395,6 +410,7 @@ files:
395
410
  - lib/rubocop/cop/style/trivial_accessors.rb
396
411
  - lib/rubocop/cop/style/unless_else.rb
397
412
  - lib/rubocop/cop/style/unneeded_capital_w.rb
413
+ - lib/rubocop/cop/style/unneeded_percent_q.rb
398
414
  - lib/rubocop/cop/style/unneeded_percent_x.rb
399
415
  - lib/rubocop/cop/style/variable_interpolation.rb
400
416
  - lib/rubocop/cop/style/variable_name.rb
@@ -411,7 +427,6 @@ files:
411
427
  - lib/rubocop/cop/variable_force/scope.rb
412
428
  - lib/rubocop/cop/variable_force/variable.rb
413
429
  - lib/rubocop/cop/variable_force/variable_table.rb
414
- - lib/rubocop/file_inspector.rb
415
430
  - lib/rubocop/formatter/base_formatter.rb
416
431
  - lib/rubocop/formatter/clang_style_formatter.rb
417
432
  - lib/rubocop/formatter/colorizable.rb
@@ -429,7 +444,7 @@ files:
429
444
  - lib/rubocop/path_util.rb
430
445
  - lib/rubocop/processed_source.rb
431
446
  - lib/rubocop/rake_task.rb
432
- - lib/rubocop/source_parser.rb
447
+ - lib/rubocop/runner.rb
433
448
  - lib/rubocop/target_finder.rb
434
449
  - lib/rubocop/token.rb
435
450
  - lib/rubocop/version.rb
@@ -440,6 +455,7 @@ files:
440
455
  - relnotes/v0.21.0.md
441
456
  - relnotes/v0.22.0.md
442
457
  - relnotes/v0.23.0.md
458
+ - relnotes/v0.24.0.md
443
459
  - rubocop.gemspec
444
460
  - spec/.rubocop.yml
445
461
  - spec/isolated_environment_spec.rb
@@ -459,6 +475,7 @@ files:
459
475
  - spec/rubocop/cop/lint/block_alignment_spec.rb
460
476
  - spec/rubocop/cop/lint/condition_position_spec.rb
461
477
  - spec/rubocop/cop/lint/debugger_spec.rb
478
+ - spec/rubocop/cop/lint/def_end_alignment_spec.rb
462
479
  - spec/rubocop/cop/lint/deprecated_class_methods_spec.rb
463
480
  - spec/rubocop/cop/lint/else_layout_spec.rb
464
481
  - spec/rubocop/cop/lint/empty_ensure_spec.rb
@@ -520,6 +537,7 @@ files:
520
537
  - spec/rubocop/cop/style/character_literal_spec.rb
521
538
  - spec/rubocop/cop/style/class_and_module_camel_case_spec.rb
522
539
  - spec/rubocop/cop/style/class_and_module_children_spec.rb
540
+ - spec/rubocop/cop/style/class_check_spec.rb
523
541
  - spec/rubocop/cop/style/class_length_spec.rb
524
542
  - spec/rubocop/cop/style/class_methods_spec.rb
525
543
  - spec/rubocop/cop/style/class_vars_spec.rb
@@ -610,8 +628,10 @@ files:
610
628
  - spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb
611
629
  - spec/rubocop/cop/style/space_around_operators_spec.rb
612
630
  - spec/rubocop/cop/style/space_before_block_braces_spec.rb
631
+ - spec/rubocop/cop/style/space_before_comma_spec.rb
613
632
  - spec/rubocop/cop/style/space_before_comment_spec.rb
614
633
  - spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb
634
+ - spec/rubocop/cop/style/space_before_semicolon_spec.rb
615
635
  - spec/rubocop/cop/style/space_inside_block_braces_spec.rb
616
636
  - spec/rubocop/cop/style/space_inside_brackets_spec.rb
617
637
  - spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb
@@ -626,6 +646,7 @@ files:
626
646
  - spec/rubocop/cop/style/trivial_accessors_spec.rb
627
647
  - spec/rubocop/cop/style/unless_else_spec.rb
628
648
  - spec/rubocop/cop/style/unneeded_capital_w_spec.rb
649
+ - spec/rubocop/cop/style/unneeded_percent_q_spec.rb
629
650
  - spec/rubocop/cop/style/unneeded_percent_x_spec.rb
630
651
  - spec/rubocop/cop/style/variable_interpolation_spec.rb
631
652
  - spec/rubocop/cop/style/variable_name_spec.rb
@@ -641,7 +662,6 @@ files:
641
662
  - spec/rubocop/cop/variable_force/variable_spec.rb
642
663
  - spec/rubocop/cop/variable_force/variable_table_spec.rb
643
664
  - spec/rubocop/cop/variable_force_spec.rb
644
- - spec/rubocop/file_inspector_spec.rb
645
665
  - spec/rubocop/formatter/base_formatter_spec.rb
646
666
  - spec/rubocop/formatter/clang_style_formatter_spec.rb
647
667
  - spec/rubocop/formatter/colorizable_spec.rb
@@ -658,7 +678,7 @@ files:
658
678
  - spec/rubocop/options_spec.rb
659
679
  - spec/rubocop/path_util_spec.rb
660
680
  - spec/rubocop/processed_source_spec.rb
661
- - spec/rubocop/source_parser_spec.rb
681
+ - spec/rubocop/runner_spec.rb
662
682
  - spec/rubocop/target_finder_spec.rb
663
683
  - spec/rubocop/token_spec.rb
664
684
  - spec/spec_helper.rb
@@ -713,6 +733,7 @@ test_files:
713
733
  - spec/rubocop/cop/lint/block_alignment_spec.rb
714
734
  - spec/rubocop/cop/lint/condition_position_spec.rb
715
735
  - spec/rubocop/cop/lint/debugger_spec.rb
736
+ - spec/rubocop/cop/lint/def_end_alignment_spec.rb
716
737
  - spec/rubocop/cop/lint/deprecated_class_methods_spec.rb
717
738
  - spec/rubocop/cop/lint/else_layout_spec.rb
718
739
  - spec/rubocop/cop/lint/empty_ensure_spec.rb
@@ -774,6 +795,7 @@ test_files:
774
795
  - spec/rubocop/cop/style/character_literal_spec.rb
775
796
  - spec/rubocop/cop/style/class_and_module_camel_case_spec.rb
776
797
  - spec/rubocop/cop/style/class_and_module_children_spec.rb
798
+ - spec/rubocop/cop/style/class_check_spec.rb
777
799
  - spec/rubocop/cop/style/class_length_spec.rb
778
800
  - spec/rubocop/cop/style/class_methods_spec.rb
779
801
  - spec/rubocop/cop/style/class_vars_spec.rb
@@ -864,8 +886,10 @@ test_files:
864
886
  - spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb
865
887
  - spec/rubocop/cop/style/space_around_operators_spec.rb
866
888
  - spec/rubocop/cop/style/space_before_block_braces_spec.rb
889
+ - spec/rubocop/cop/style/space_before_comma_spec.rb
867
890
  - spec/rubocop/cop/style/space_before_comment_spec.rb
868
891
  - spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb
892
+ - spec/rubocop/cop/style/space_before_semicolon_spec.rb
869
893
  - spec/rubocop/cop/style/space_inside_block_braces_spec.rb
870
894
  - spec/rubocop/cop/style/space_inside_brackets_spec.rb
871
895
  - spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb
@@ -880,6 +904,7 @@ test_files:
880
904
  - spec/rubocop/cop/style/trivial_accessors_spec.rb
881
905
  - spec/rubocop/cop/style/unless_else_spec.rb
882
906
  - spec/rubocop/cop/style/unneeded_capital_w_spec.rb
907
+ - spec/rubocop/cop/style/unneeded_percent_q_spec.rb
883
908
  - spec/rubocop/cop/style/unneeded_percent_x_spec.rb
884
909
  - spec/rubocop/cop/style/variable_interpolation_spec.rb
885
910
  - spec/rubocop/cop/style/variable_name_spec.rb
@@ -895,7 +920,6 @@ test_files:
895
920
  - spec/rubocop/cop/variable_force/variable_spec.rb
896
921
  - spec/rubocop/cop/variable_force/variable_table_spec.rb
897
922
  - spec/rubocop/cop/variable_force_spec.rb
898
- - spec/rubocop/file_inspector_spec.rb
899
923
  - spec/rubocop/formatter/base_formatter_spec.rb
900
924
  - spec/rubocop/formatter/clang_style_formatter_spec.rb
901
925
  - spec/rubocop/formatter/colorizable_spec.rb
@@ -912,7 +936,7 @@ test_files:
912
936
  - spec/rubocop/options_spec.rb
913
937
  - spec/rubocop/path_util_spec.rb
914
938
  - spec/rubocop/processed_source_spec.rb
915
- - spec/rubocop/source_parser_spec.rb
939
+ - spec/rubocop/runner_spec.rb
916
940
  - spec/rubocop/target_finder_spec.rb
917
941
  - spec/rubocop/token_spec.rb
918
942
  - spec/spec_helper.rb
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module RuboCop
4
- # SourceParser provides a way to parse Ruby source with Parser gem
5
- # and also parses comment directives which disable arbitrary cops.
6
- module SourceParser
7
- module_function
8
-
9
- def parse_file(path)
10
- parse(File.read(path), path)
11
- end
12
-
13
- def parse(string, name = '(string)')
14
- source_buffer = Parser::Source::Buffer.new(name, 1)
15
- source_buffer.source = string
16
-
17
- parser = create_parser
18
- diagnostics = []
19
- parser.diagnostics.consumer = lambda do |diagnostic|
20
- diagnostics << diagnostic
21
- end
22
-
23
- begin
24
- ast, comments, tokens = parser.tokenize(source_buffer)
25
- rescue Parser::SyntaxError # rubocop:disable Lint/HandleExceptions
26
- # All errors are in diagnostics. No need to handle exception.
27
- end
28
-
29
- tokens = tokens.map { |t| Token.from_parser_token(t) } if tokens
30
-
31
- ProcessedSource.new(source_buffer, ast, comments, tokens, diagnostics)
32
- end
33
-
34
- def create_parser
35
- parser = Parser::CurrentRuby.new
36
-
37
- # On JRuby and Rubinius, there's a risk that we hang in tokenize() if we
38
- # don't set the all errors as fatal flag. The problem is caused by a bug
39
- # in Racc that is discussed in issue #93 of the whitequark/parser project
40
- # on GitHub.
41
- parser.diagnostics.all_errors_are_fatal = RUBY_ENGINE != 'ruby'
42
- parser.diagnostics.ignore_warnings = false
43
-
44
- parser
45
- end
46
- end
47
- end
@@ -1,84 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- module RuboCop
6
- class FileInspector
7
- attr_writer :errors # Needed only for testing.
8
- end
9
- end
10
-
11
- describe RuboCop::FileInspector do
12
- subject(:inspector) { described_class.new(options) }
13
- let(:options) { {} }
14
- let(:offenses) { [] }
15
- let(:errors) { [] }
16
-
17
- before(:each) do
18
- $stdout = StringIO.new
19
- $stderr = StringIO.new
20
-
21
- allow(inspector).to receive(:process_source) do
22
- [double('ProcessedSource').as_null_object, []]
23
- end
24
-
25
- allow(inspector).to receive(:inspect_file) do
26
- inspector.errors = errors
27
- [offenses, !:updated_source_file]
28
- end
29
- end
30
-
31
- after(:each) do
32
- $stdout = STDOUT
33
- $stderr = STDERR
34
- end
35
-
36
- describe '#display_error_summary' do
37
- let(:errors) do
38
- ['An error occurred while Encoding cop was inspecting file.rb.']
39
- end
40
-
41
- it 'displays an error message to stderr when errors are present' do
42
- inspector.process_files(['file.rb'], nil) {}
43
- inspector.display_error_summary
44
- expect($stderr.string.lines.to_a[-6..-5])
45
- .to eq(["1 error occurred:\n", "#{errors.first}\n"])
46
- end
47
- end
48
-
49
- describe '#process_files' do
50
- context 'if there are no offenses in inspected files' do
51
- it 'returns false' do
52
- result = inspector.process_files(['file.rb'], nil) {}
53
- expect(result).to eq(false)
54
- end
55
- end
56
-
57
- context 'if there is an offense in an inspected file' do
58
- let(:offenses) do
59
- [RuboCop::Cop::Offense.new(:convention,
60
- Struct.new(:line, :column,
61
- :source_line).new(1, 0, ''),
62
- 'Use alias_method instead of alias.',
63
- 'Alias')]
64
- end
65
-
66
- it 'returns true' do
67
- expect(inspector.process_files(['file.rb'], nil) {}).to eq(true)
68
- end
69
-
70
- it 'sends the offense to a formatter' do
71
- inspector.process_files(['file.rb'], nil) {}
72
- expect($stdout.string.split("\n"))
73
- .to eq(['Inspecting 1 file',
74
- 'C',
75
- '',
76
- 'Offenses:',
77
- '',
78
- "file.rb:1:1: C: #{offenses.first.message}",
79
- '',
80
- '1 file inspected, 1 offense detected'])
81
- end
82
- end
83
- end
84
- end