rubocop 0.28.0 → 0.29.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 (211) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +7 -7
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +59 -0
  5. data/README.md +62 -28
  6. data/config/default.yml +31 -0
  7. data/config/disabled.yml +1 -1
  8. data/config/enabled.yml +17 -0
  9. data/lib/rubocop.rb +4 -0
  10. data/lib/rubocop/cli.rb +1 -1
  11. data/lib/rubocop/config.rb +12 -8
  12. data/lib/rubocop/config_loader.rb +20 -10
  13. data/lib/rubocop/cop/cop.rb +13 -7
  14. data/lib/rubocop/cop/corrector.rb +10 -10
  15. data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -1
  16. data/lib/rubocop/cop/lint/block_alignment.rb +9 -2
  17. data/lib/rubocop/cop/lint/debugger.rb +13 -1
  18. data/lib/rubocop/cop/lint/duplicate_methods.rb +104 -0
  19. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  20. data/lib/rubocop/cop/lint/require_parentheses.rb +3 -3
  21. data/lib/rubocop/cop/mixin/access_modifier_node.rb +27 -0
  22. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +0 -4
  23. data/lib/rubocop/cop/rails/delegate.rb +4 -5
  24. data/lib/rubocop/cop/rails/read_write_attribute.rb +33 -0
  25. data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -7
  26. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +4 -2
  27. data/lib/rubocop/cop/style/class_methods.rb +25 -9
  28. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +7 -1
  29. data/lib/rubocop/cop/style/empty_literal.rb +25 -10
  30. data/lib/rubocop/cop/style/even_odd.rb +32 -14
  31. data/lib/rubocop/cop/style/first_parameter_indentation.rb +106 -0
  32. data/lib/rubocop/cop/style/format_string.rb +2 -2
  33. data/lib/rubocop/cop/style/global_vars.rb +1 -5
  34. data/lib/rubocop/cop/style/hash_syntax.rb +0 -4
  35. data/lib/rubocop/cop/style/indentation_consistency.rb +5 -5
  36. data/lib/rubocop/cop/style/indentation_width.rb +13 -14
  37. data/lib/rubocop/cop/style/lambda.rb +48 -2
  38. data/lib/rubocop/cop/style/line_end_concatenation.rb +43 -47
  39. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -3
  40. data/lib/rubocop/cop/style/module_function.rb +3 -3
  41. data/lib/rubocop/cop/style/multiline_block_layout.rb +65 -17
  42. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +2 -1
  43. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  44. data/lib/rubocop/cop/style/redundant_exception.rb +12 -0
  45. data/lib/rubocop/cop/style/self_assignment.rb +27 -0
  46. data/lib/rubocop/cop/style/semicolon.rb +2 -1
  47. data/lib/rubocop/cop/style/space_around_block_parameters.rb +92 -0
  48. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +0 -8
  49. data/lib/rubocop/cop/style/struct_inheritance.rb +42 -0
  50. data/lib/rubocop/cop/style/trivial_accessors.rb +10 -4
  51. data/lib/rubocop/cop/util.rb +32 -7
  52. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -15
  53. data/lib/rubocop/options.rb +28 -41
  54. data/lib/rubocop/processed_source.rb +6 -0
  55. data/lib/rubocop/rake_task.rb +6 -3
  56. data/lib/rubocop/runner.rb +55 -15
  57. data/lib/rubocop/version.rb +1 -1
  58. data/relnotes/v0.29.0.md +116 -0
  59. data/rubocop.gemspec +3 -3
  60. data/spec/rubocop/cli_spec.rb +329 -25
  61. data/spec/rubocop/config_loader_spec.rb +20 -0
  62. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +27 -3
  63. data/spec/rubocop/cop/lint/block_alignment_spec.rb +3 -4
  64. data/spec/rubocop/cop/lint/condition_position_spec.rb +1 -1
  65. data/spec/rubocop/cop/lint/debugger_spec.rb +20 -7
  66. data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +189 -0
  67. data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +1 -1
  68. data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
  69. data/spec/rubocop/cop/lint/eval_spec.rb +4 -4
  70. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +18 -0
  71. data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +2 -2
  72. data/spec/rubocop/cop/lint/loop_spec.rb +4 -4
  73. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +7 -7
  74. data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +5 -4
  75. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +3 -9
  76. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
  77. data/spec/rubocop/cop/lint/void_spec.rb +1 -1
  78. data/spec/rubocop/cop/metrics/abc_size_spec.rb +10 -0
  79. data/spec/rubocop/cop/metrics/line_length_spec.rb +2 -2
  80. data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +2 -2
  81. data/spec/rubocop/cop/rails/action_filter_spec.rb +6 -12
  82. data/spec/rubocop/cop/rails/default_scope_spec.rb +5 -5
  83. data/spec/rubocop/cop/rails/delegate_spec.rb +8 -0
  84. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
  85. data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +119 -8
  86. data/spec/rubocop/cop/rails/scope_args_spec.rb +3 -3
  87. data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
  88. data/spec/rubocop/cop/style/alias_spec.rb +5 -5
  89. data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
  90. data/spec/rubocop/cop/style/align_parameters_spec.rb +8 -8
  91. data/spec/rubocop/cop/style/and_or_spec.rb +15 -30
  92. data/spec/rubocop/cop/style/array_join_spec.rb +4 -4
  93. data/spec/rubocop/cop/style/ascii_comments_spec.rb +1 -2
  94. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
  95. data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
  96. data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
  97. data/spec/rubocop/cop/style/block_end_newline_spec.rb +1 -1
  98. data/spec/rubocop/cop/style/blocks_spec.rb +2 -2
  99. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +38 -33
  100. data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
  101. data/spec/rubocop/cop/style/character_literal_spec.rb +4 -4
  102. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +4 -2
  103. data/spec/rubocop/cop/style/class_methods_spec.rb +12 -0
  104. data/spec/rubocop/cop/style/class_vars_spec.rb +2 -2
  105. data/spec/rubocop/cop/style/collection_methods_spec.rb +4 -4
  106. data/spec/rubocop/cop/style/colon_method_call_spec.rb +8 -8
  107. data/spec/rubocop/cop/style/comment_annotation_spec.rb +10 -10
  108. data/spec/rubocop/cop/style/constant_name_spec.rb +7 -7
  109. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
  110. data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +4 -4
  111. data/spec/rubocop/cop/style/dot_position_spec.rb +8 -6
  112. data/spec/rubocop/cop/style/each_with_object_spec.rb +2 -2
  113. data/spec/rubocop/cop/style/else_alignment_spec.rb +2 -4
  114. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +78 -0
  115. data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +60 -0
  116. data/spec/rubocop/cop/style/empty_lines_spec.rb +3 -3
  117. data/spec/rubocop/cop/style/empty_literal_spec.rb +29 -12
  118. data/spec/rubocop/cop/style/encoding_spec.rb +3 -3
  119. data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
  120. data/spec/rubocop/cop/style/end_of_line_spec.rb +2 -2
  121. data/spec/rubocop/cop/style/even_odd_spec.rb +109 -20
  122. data/spec/rubocop/cop/style/extra_spacing_spec.rb +3 -3
  123. data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +293 -0
  124. data/spec/rubocop/cop/style/for_spec.rb +2 -2
  125. data/spec/rubocop/cop/style/format_string_spec.rb +45 -21
  126. data/spec/rubocop/cop/style/global_vars_spec.rb +4 -4
  127. data/spec/rubocop/cop/style/guard_clause_spec.rb +17 -0
  128. data/spec/rubocop/cop/style/hash_syntax_spec.rb +15 -15
  129. data/spec/rubocop/cop/{metrics → style}/if_unless_modifier_spec.rb +2 -2
  130. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +2 -2
  131. data/spec/rubocop/cop/style/indent_array_spec.rb +3 -6
  132. data/spec/rubocop/cop/style/indent_hash_spec.rb +4 -4
  133. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +1 -2
  134. data/spec/rubocop/cop/style/indentation_width_spec.rb +1 -2
  135. data/spec/rubocop/cop/style/infinite_loop_spec.rb +1 -1
  136. data/spec/rubocop/cop/style/lambda_call_spec.rb +4 -4
  137. data/spec/rubocop/cop/style/lambda_spec.rb +37 -2
  138. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +7 -12
  139. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +41 -1
  140. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +4 -4
  141. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +3 -3
  142. data/spec/rubocop/cop/style/method_name_spec.rb +1 -1
  143. data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +61 -0
  144. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -3
  145. data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +8 -0
  146. data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +1 -1
  147. data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +1 -1
  148. data/spec/rubocop/cop/style/next_spec.rb +16 -0
  149. data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -5
  150. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
  151. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +22 -4
  152. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +31 -31
  153. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +12 -12
  154. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +3 -3
  155. data/spec/rubocop/cop/style/proc_spec.rb +3 -3
  156. data/spec/rubocop/cop/style/raise_args_spec.rb +9 -9
  157. data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
  158. data/spec/rubocop/cop/style/redundant_exception_spec.rb +36 -4
  159. data/spec/rubocop/cop/style/redundant_self_spec.rb +89 -45
  160. data/spec/rubocop/cop/style/regexp_literal_spec.rb +9 -9
  161. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
  162. data/spec/rubocop/cop/style/self_assignment_spec.rb +16 -10
  163. data/spec/rubocop/cop/style/semicolon_spec.rb +9 -9
  164. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -2
  165. data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +1 -1
  166. data/spec/rubocop/cop/style/space_after_colon_spec.rb +5 -5
  167. data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
  168. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +4 -4
  169. data/spec/rubocop/cop/style/space_after_not_spec.rb +2 -2
  170. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +2 -2
  171. data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +150 -0
  172. data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +18 -9
  173. data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -21
  174. data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +4 -4
  175. data/spec/rubocop/cop/style/space_before_comma_spec.rb +4 -4
  176. data/spec/rubocop/cop/style/space_before_comment_spec.rb +3 -3
  177. data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +2 -2
  178. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +33 -24
  179. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +2 -2
  180. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +9 -9
  181. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
  182. data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -6
  183. data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +3 -3
  184. data/spec/rubocop/cop/style/string_literals_spec.rb +16 -16
  185. data/spec/rubocop/cop/style/struct_inheritance_spec.rb +44 -0
  186. data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
  187. data/spec/rubocop/cop/style/symbol_proc_spec.rb +12 -12
  188. data/spec/rubocop/cop/style/tab_spec.rb +4 -4
  189. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +2 -2
  190. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -2
  191. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +16 -0
  192. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +11 -22
  193. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +7 -7
  194. data/spec/rubocop/cop/style/while_until_do_spec.rb +2 -2
  195. data/spec/rubocop/cop/{metrics → style}/while_until_modifier_spec.rb +2 -2
  196. data/spec/rubocop/cop/style/word_array_spec.rb +11 -11
  197. data/spec/rubocop/cop/util_spec.rb +51 -0
  198. data/spec/rubocop/cop/variable_force/reference_spec.rb +19 -0
  199. data/spec/rubocop/cop/variable_force/variable_table_spec.rb +7 -0
  200. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +7 -8
  201. data/spec/rubocop/formatter/text_util_spec.rb +55 -0
  202. data/spec/rubocop/options_spec.rb +26 -20
  203. data/spec/rubocop/rake_task_spec.rb +122 -0
  204. data/spec/rubocop/runner_spec.rb +37 -2
  205. data/spec/rubocop/token_spec.rb +5 -1
  206. data/spec/spec_helper.rb +5 -2
  207. data/spec/support/cop_helper.rb +3 -0
  208. data/spec/support/cops/class_must_be_a_module_cop.rb +19 -0
  209. data/spec/support/cops/module_must_be_a_class_cop.rb +19 -0
  210. data/spec/support/custom_matchers.rb +1 -1
  211. metadata +35 -12
@@ -11,24 +11,24 @@ describe RuboCop::Cop::Style::GlobalVars, :config do
11
11
  let(:cop_config) { cop_config }
12
12
 
13
13
  it 'registers an offense for $custom' do
14
- inspect_source(cop, ['puts $custom'])
14
+ inspect_source(cop, 'puts $custom')
15
15
  expect(cop.offenses.size).to eq(1)
16
16
  end
17
17
 
18
18
  it 'allows user whitelisted variables' do
19
- inspect_source(cop, ['puts $allowed'])
19
+ inspect_source(cop, 'puts $allowed')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
23
23
  described_class::BUILT_IN_VARS.each do |var|
24
24
  it "does not register an offense for built-in variable #{var}" do
25
- inspect_source(cop, ["puts #{var}"])
25
+ inspect_source(cop, "puts #{var}")
26
26
  expect(cop.offenses).to be_empty
27
27
  end
28
28
  end
29
29
 
30
30
  it 'does not register an offense for backrefs like $1' do
31
- inspect_source(cop, ['puts $1'])
31
+ inspect_source(cop, 'puts $1')
32
32
  expect(cop.offenses).to be_empty
33
33
  end
34
34
  end
@@ -152,4 +152,21 @@ describe RuboCop::Cop::Style::GuardClause, :config do
152
152
  expect(cop.offenses).to be_empty
153
153
  end
154
154
  end
155
+
156
+ context 'Invalid MinBodyLength' do
157
+ let(:cop_config) do
158
+ { 'MinBodyLength' => -2 }
159
+ end
160
+
161
+ it 'fails with an error' do
162
+ source = ['def func',
163
+ ' if something',
164
+ ' work',
165
+ ' end',
166
+ 'end']
167
+
168
+ expect { inspect_source(cop, source) }
169
+ .to raise_error('MinBodyLength needs to be a positive integer!')
170
+ end
171
+ end
155
172
  end
@@ -17,55 +17,55 @@ describe RuboCop::Cop::Style::HashSyntax, :config do
17
17
  end
18
18
 
19
19
  it 'registers offense for hash rocket syntax when new is possible' do
20
- inspect_source(cop, ['x = { :a => 0 }'])
20
+ inspect_source(cop, 'x = { :a => 0 }')
21
21
  expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
22
22
  expect(cop.config_to_allow_offenses)
23
23
  .to eq('EnforcedStyle' => 'hash_rockets')
24
24
  end
25
25
 
26
26
  it 'registers an offense for mixed syntax when new is possible' do
27
- inspect_source(cop, ['x = { :a => 0, b: 1 }'])
27
+ inspect_source(cop, 'x = { :a => 0, b: 1 }')
28
28
  expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
29
29
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
30
30
  end
31
31
 
32
32
  it 'registers an offense for hash rockets in method calls' do
33
- inspect_source(cop, ['func(3, :a => 0)'])
33
+ inspect_source(cop, 'func(3, :a => 0)')
34
34
  expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
35
35
  end
36
36
 
37
37
  it 'accepts hash rockets when keys have different types' do
38
- inspect_source(cop, ['x = { :a => 0, "b" => 1 }'])
38
+ inspect_source(cop, 'x = { :a => 0, "b" => 1 }')
39
39
  expect(cop.messages).to be_empty
40
40
  end
41
41
 
42
42
  it 'accepts hash rockets when keys have whitespaces in them' do
43
- inspect_source(cop, ['x = { :"t o" => 0 }'])
43
+ inspect_source(cop, 'x = { :"t o" => 0 }')
44
44
  expect(cop.messages).to be_empty
45
45
  end
46
46
 
47
47
  it 'accepts hash rockets when keys have special symbols in them' do
48
- inspect_source(cop, ['x = { :"\tab" => 1 }'])
48
+ inspect_source(cop, 'x = { :"\tab" => 1 }')
49
49
  expect(cop.messages).to be_empty
50
50
  end
51
51
 
52
52
  it 'accepts hash rockets when keys start with a digit' do
53
- inspect_source(cop, ['x = { :"1" => 1 }'])
53
+ inspect_source(cop, 'x = { :"1" => 1 }')
54
54
  expect(cop.messages).to be_empty
55
55
  end
56
56
 
57
57
  it 'registers offense when keys start with an uppercase letter' do
58
- inspect_source(cop, ['x = { :A => 0 }'])
58
+ inspect_source(cop, 'x = { :A => 0 }')
59
59
  expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
60
60
  end
61
61
 
62
62
  it 'accepts new syntax in a hash literal' do
63
- inspect_source(cop, ['x = { a: 0, b: 1 }'])
63
+ inspect_source(cop, 'x = { a: 0, b: 1 }')
64
64
  expect(cop.messages).to be_empty
65
65
  end
66
66
 
67
67
  it 'accepts new syntax in method calls' do
68
- inspect_source(cop, ['func(3, a: 0)'])
68
+ inspect_source(cop, 'func(3, a: 0)')
69
69
  expect(cop.messages).to be_empty
70
70
  end
71
71
 
@@ -103,29 +103,29 @@ describe RuboCop::Cop::Style::HashSyntax, :config do
103
103
  let(:cop_config) { { 'EnforcedStyle' => 'hash_rockets' } }
104
104
 
105
105
  it 'registers offense for Ruby 1.9 style' do
106
- inspect_source(cop, ['x = { a: 0 }'])
106
+ inspect_source(cop, 'x = { a: 0 }')
107
107
  expect(cop.messages).to eq(['Always use hash rockets in hashes.'])
108
108
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'ruby19')
109
109
  end
110
110
 
111
111
  it 'registers an offense for mixed syntax' do
112
- inspect_source(cop, ['x = { :a => 0, b: 1 }'])
112
+ inspect_source(cop, 'x = { :a => 0, b: 1 }')
113
113
  expect(cop.messages).to eq(['Always use hash rockets in hashes.'])
114
114
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
115
115
  end
116
116
 
117
117
  it 'registers an offense for 1.9 style in method calls' do
118
- inspect_source(cop, ['func(3, a: 0)'])
118
+ inspect_source(cop, 'func(3, a: 0)')
119
119
  expect(cop.messages).to eq(['Always use hash rockets in hashes.'])
120
120
  end
121
121
 
122
122
  it 'accepts hash rockets in a hash literal' do
123
- inspect_source(cop, ['x = { :a => 0, :b => 1 }'])
123
+ inspect_source(cop, 'x = { :a => 0, :b => 1 }')
124
124
  expect(cop.messages).to be_empty
125
125
  end
126
126
 
127
127
  it 'accepts hash rockets in method calls' do
128
- inspect_source(cop, ['func(3, :a => 0)'])
128
+ inspect_source(cop, 'func(3, :a => 0)')
129
129
  expect(cop.messages).to be_empty
130
130
  end
131
131
 
@@ -73,8 +73,8 @@ describe RuboCop::Cop::Style::IfUnlessModifier do
73
73
 
74
74
  it 'accepts if-else-end' do
75
75
  inspect_source(cop,
76
- ['if args.last.is_a? Hash then args.pop else ' \
77
- 'Hash.new end'])
76
+ 'if args.last.is_a? Hash then args.pop else ' \
77
+ 'Hash.new end')
78
78
  expect(cop.messages).to be_empty
79
79
  end
80
80
 
@@ -6,13 +6,13 @@ describe RuboCop::Cop::Style::IfWithSemicolon do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for one line if/;/end' do
9
- inspect_source(cop, ['if cond; run else dont end'])
9
+ inspect_source(cop, 'if cond; run else dont end')
10
10
  expect(cop.messages).to eq(
11
11
  ['Do not use if x; Use the ternary operator instead.'])
12
12
  end
13
13
 
14
14
  it 'accepts one line if/then/end' do
15
- inspect_source(cop, ['if cond then run else dont end'])
15
+ inspect_source(cop, 'if cond then run else dont end')
16
16
  expect(cop.messages).to be_empty
17
17
  end
18
18
 
@@ -106,14 +106,12 @@ describe RuboCop::Cop::Style::IndentArray do
106
106
  end
107
107
 
108
108
  it 'accepts single line array' do
109
- inspect_source(cop,
110
- ['a = [1, 2]'])
109
+ inspect_source(cop, 'a = [1, 2]')
111
110
  expect(cop.offenses).to be_empty
112
111
  end
113
112
 
114
113
  it 'accepts an empty array' do
115
- inspect_source(cop,
116
- ['a = []'])
114
+ inspect_source(cop, 'a = []')
117
115
  expect(cop.offenses).to be_empty
118
116
  end
119
117
 
@@ -150,8 +148,7 @@ describe RuboCop::Cop::Style::IndentArray do
150
148
 
151
149
  context 'and arguments are not surrounded by parentheses' do
152
150
  it 'accepts single line array' do
153
- inspect_source(cop,
154
- ['func x, [1, 2]'])
151
+ inspect_source(cop, 'func x, [1, 2]')
155
152
  expect(cop.offenses).to be_empty
156
153
  end
157
154
 
@@ -202,13 +202,13 @@ describe RuboCop::Cop::Style::IndentHash do
202
202
 
203
203
  it 'accepts single line hash' do
204
204
  inspect_source(cop,
205
- ['a = { a: 1, b: 2 }'])
205
+ 'a = { a: 1, b: 2 }')
206
206
  expect(cop.offenses).to be_empty
207
207
  end
208
208
 
209
209
  it 'accepts an empty hash' do
210
210
  inspect_source(cop,
211
- ['a = {}'])
211
+ 'a = {}')
212
212
  expect(cop.offenses).to be_empty
213
213
  end
214
214
  end
@@ -334,13 +334,13 @@ describe RuboCop::Cop::Style::IndentHash do
334
334
  context 'and argument are not surrounded by parentheses' do
335
335
  it 'accepts braceless hash' do
336
336
  inspect_source(cop,
337
- ['func a: 1, b: 2'])
337
+ 'func a: 1, b: 2')
338
338
  expect(cop.offenses).to be_empty
339
339
  end
340
340
 
341
341
  it 'accepts single line hash with braces' do
342
342
  inspect_source(cop,
343
- ['func x, { a: 1, b: 2 }'])
343
+ 'func x, { a: 1, b: 2 }')
344
344
  expect(cop.offenses).to be_empty
345
345
  end
346
346
 
@@ -60,8 +60,7 @@ describe RuboCop::Cop::Style::IndentationConsistency do
60
60
  end
61
61
 
62
62
  it 'accepts a one line if statement' do
63
- inspect_source(cop,
64
- ['if cond then func1 else func2 end'])
63
+ inspect_source(cop, 'if cond then func1 else func2 end')
65
64
  expect(cop.offenses).to be_empty
66
65
  end
67
66
 
@@ -235,8 +235,7 @@ describe RuboCop::Cop::Style::IndentationWidth do
235
235
  end
236
236
 
237
237
  it 'accepts a one line if statement' do
238
- inspect_source(cop,
239
- ['if cond then func1 else func2 end'])
238
+ inspect_source(cop, 'if cond then func1 else func2 end')
240
239
  expect(cop.offenses).to be_empty
241
240
  end
242
241
 
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Style::InfiniteLoop do
29
29
 
30
30
  it 'accepts Kernel#loop' do
31
31
  inspect_source(cop,
32
- ['loop { break if something }'])
32
+ 'loop { break if something }')
33
33
 
34
34
  expect(cop.offenses).to be_empty
35
35
  end
@@ -10,7 +10,7 @@ describe RuboCop::Cop::Style::LambdaCall, :config do
10
10
 
11
11
  it 'registers an offense for x.()' do
12
12
  inspect_source(cop,
13
- ['x.(a, b)'])
13
+ 'x.(a, b)')
14
14
  expect(cop.offenses.size).to eq(1)
15
15
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'braces')
16
16
  end
@@ -24,7 +24,7 @@ describe RuboCop::Cop::Style::LambdaCall, :config do
24
24
  end
25
25
 
26
26
  it 'accepts x.call()' do
27
- inspect_source(cop, ['x.call(a, b)'])
27
+ inspect_source(cop, 'x.call(a, b)')
28
28
  expect(cop.offenses).to be_empty
29
29
  end
30
30
 
@@ -39,7 +39,7 @@ describe RuboCop::Cop::Style::LambdaCall, :config do
39
39
 
40
40
  it 'registers an offense for x.call()' do
41
41
  inspect_source(cop,
42
- ['x.call(a, b)'])
42
+ 'x.call(a, b)')
43
43
  expect(cop.offenses.size).to eq(1)
44
44
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'call')
45
45
  end
@@ -53,7 +53,7 @@ describe RuboCop::Cop::Style::LambdaCall, :config do
53
53
  end
54
54
 
55
55
  it 'accepts x.()' do
56
- inspect_source(cop, ['x.(a, b)'])
56
+ inspect_source(cop, 'x.(a, b)')
57
57
  expect(cop.offenses).to be_empty
58
58
  end
59
59
 
@@ -6,12 +6,19 @@ describe RuboCop::Cop::Style::Lambda do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for an old single-line lambda call' do
9
- inspect_source(cop, ['f = lambda { |x| x }'])
9
+ inspect_source(cop, 'f = lambda { |x| x }')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  expect(cop.messages)
12
12
  .to eq(['Use the new lambda literal syntax `->(params) {...}`.'])
13
13
  end
14
14
 
15
+ it 'registers an offense for an old single-line no-argument lambda call' do
16
+ inspect_source(cop, 'f = lambda { x }')
17
+ expect(cop.offenses.size).to eq(1)
18
+ expect(cop.messages)
19
+ .to eq(['Use the new lambda literal syntax `-> {...}`.'])
20
+ end
21
+
15
22
  it 'accepts the new lambda literal with single-line body' do
16
23
  inspect_source(cop, ['lambda = ->(x) { x }',
17
24
  'lambda.(1)'])
@@ -35,7 +42,35 @@ describe RuboCop::Cop::Style::Lambda do
35
42
  end
36
43
 
37
44
  it 'accepts the lambda call outside of block' do
38
- inspect_source(cop, ['l = lambda.test'])
45
+ inspect_source(cop, 'l = lambda.test')
39
46
  expect(cop.offenses).to be_empty
40
47
  end
48
+
49
+ it 'auto-corrects an old single-line lambda call' do
50
+ new_source = autocorrect_source(cop, 'f = lambda { |x| x }')
51
+ expect(new_source).to eq('f = ->(x) { x }')
52
+ end
53
+
54
+ it 'auto-corrects an old single-line no-argument lambda call' do
55
+ new_source = autocorrect_source(cop, 'f = lambda { x }')
56
+ expect(new_source).to eq('f = -> { x }')
57
+ end
58
+
59
+ it 'auto-corrects a new multi-line lambda call' do
60
+ new_source = autocorrect_source(cop, ['f = ->(x) do',
61
+ ' x',
62
+ 'end'])
63
+ expect(new_source).to eq(['f = lambda do |x|',
64
+ ' x',
65
+ 'end'].join("\n"))
66
+ end
67
+
68
+ it 'auto-corrects a new multi-line no-argument lambda call' do
69
+ new_source = autocorrect_source(cop, ['f = -> do',
70
+ ' x',
71
+ 'end'])
72
+ expect(new_source).to eq(['f = lambda do',
73
+ ' x',
74
+ 'end'].join("\n"))
75
+ end
41
76
  end
@@ -6,32 +6,27 @@ describe RuboCop::Cop::Style::LeadingCommentSpace do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for comment without leading space' do
9
- inspect_source(cop,
10
- ['#missing space'])
9
+ inspect_source(cop, '#missing space')
11
10
  expect(cop.offenses.size).to eq(1)
12
11
  end
13
12
 
14
13
  it 'does not register an offense for # followed by no text' do
15
- inspect_source(cop,
16
- ['#'])
14
+ inspect_source(cop, '#')
17
15
  expect(cop.offenses).to be_empty
18
16
  end
19
17
 
20
18
  it 'does not register an offense for more than one space' do
21
- inspect_source(cop,
22
- ['# heavily indented'])
19
+ inspect_source(cop, '# heavily indented')
23
20
  expect(cop.offenses).to be_empty
24
21
  end
25
22
 
26
23
  it 'does not register an offense for more than one #' do
27
- inspect_source(cop,
28
- ['###### heavily indented'])
24
+ inspect_source(cop, '###### heavily indented')
29
25
  expect(cop.offenses).to be_empty
30
26
  end
31
27
 
32
28
  it 'does not register an offense for only #s' do
33
- inspect_source(cop,
34
- ['######'])
29
+ inspect_source(cop, '######')
35
30
  expect(cop.offenses).to be_empty
36
31
  end
37
32
 
@@ -43,8 +38,8 @@ describe RuboCop::Cop::Style::LeadingCommentSpace do
43
38
  end
44
39
 
45
40
  it 'registers an offense for #! after the first line' do
46
- inspect_source(cop,
47
- ['test', '#!/usr/bin/ruby'])
41
+ inspect_source(cop, ['test',
42
+ '#!/usr/bin/ruby'])
48
43
  expect(cop.offenses.size).to eq(1)
49
44
  end
50
45
 
@@ -10,6 +10,7 @@ describe RuboCop::Cop::Style::LineEndConcatenation do
10
10
  ['top = "test" +',
11
11
  '"top"'])
12
12
  expect(cop.offenses.size).to eq(1)
13
+ expect(cop.highlights).to eq(['+'])
13
14
  end
14
15
 
15
16
  it 'registers an offense for string concat with << at line end' do
@@ -17,6 +18,7 @@ describe RuboCop::Cop::Style::LineEndConcatenation do
17
18
  ['top = "test" <<',
18
19
  '"top"'])
19
20
  expect(cop.offenses.size).to eq(1)
21
+ expect(cop.highlights).to eq(['<<'])
20
22
  end
21
23
 
22
24
  it 'registers an offense for string concat with << and \ at line ends' do
@@ -69,7 +71,37 @@ describe RuboCop::Cop::Style::LineEndConcatenation do
69
71
 
70
72
  it 'accepts string concat on the same line' do
71
73
  inspect_source(cop,
72
- ['top = "test" + "top"'])
74
+ 'top = "test" + "top"')
75
+ expect(cop.offenses).to be_empty
76
+ end
77
+
78
+ it 'accepts string concat with a return value of method on a string' do
79
+ inspect_source(cop,
80
+ [
81
+ # What we want here is 'content ', not '
82
+ # content content content '.
83
+ 'content_and_three_spaces = "content" +',
84
+ ' " " * 3',
85
+ # Method call with dot on a string literal.
86
+ "a_thing = 'a ' +",
87
+ " 'gniht'.reverse",
88
+ # Formatting operator.
89
+ "output = 'value: ' +",
90
+ " '%d' % value",
91
+ # Index operator.
92
+ "'letter: ' +",
93
+ " 'abcdefghij'[ix]"
94
+ ])
95
+ expect(cop.offenses).to be_empty
96
+ end
97
+
98
+ it 'accepts string concat with a return value of method on an interpolated ' \
99
+ 'string' do
100
+ source = <<-END
101
+ x3a = 'x' +
102
+ "\#{'a' + "\#{3}"}".reverse
103
+ END
104
+ inspect_source(cop, source)
73
105
  expect(cop.offenses).to be_empty
74
106
  end
75
107
 
@@ -80,6 +112,14 @@ describe RuboCop::Cop::Style::LineEndConcatenation do
80
112
  expect(cop.offenses).to be_empty
81
113
  end
82
114
 
115
+ it 'accepts string concat at line end when followed by a comment line' do
116
+ inspect_source(cop,
117
+ ['top = "test" +',
118
+ '# something',
119
+ '"top"'])
120
+ expect(cop.offenses).to be_empty
121
+ end
122
+
83
123
  it 'accepts string concat at line end when % literals are involved' do
84
124
  inspect_source(cop,
85
125
  ['top = %(test) +',