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
@@ -9,22 +9,22 @@ describe RuboCop::Cop::Style::MethodCallParentheses, :config do
9
9
  end
10
10
 
11
11
  it 'registers an offense for parens in method call without args' do
12
- inspect_source(cop, ['top.test()'])
12
+ inspect_source(cop, 'top.test()')
13
13
  expect(cop.offenses.size).to eq(1)
14
14
  end
15
15
 
16
16
  it 'accepts parentheses for methods starting with an upcase letter' do
17
- inspect_source(cop, ['Test()'])
17
+ inspect_source(cop, 'Test()')
18
18
  expect(cop.offenses).to be_empty
19
19
  end
20
20
 
21
21
  it 'accepts no parens in method call without args' do
22
- inspect_source(cop, ['top.test'])
22
+ inspect_source(cop, 'top.test')
23
23
  expect(cop.offenses).to be_empty
24
24
  end
25
25
 
26
26
  it 'accepts parens in method call with args' do
27
- inspect_source(cop, ['top.test(a)'])
27
+ inspect_source(cop, 'top.test(a)')
28
28
  expect(cop.offenses).to be_empty
29
29
  end
30
30
 
@@ -33,13 +33,13 @@ describe RuboCop::Cop::Style::MethodCalledOnDoEndBlock do
33
33
 
34
34
  context 'with a single-line do..end block' do
35
35
  it 'registers an offense for a chained call' do
36
- inspect_source(cop, ['a do b end.c'])
36
+ inspect_source(cop, 'a do b end.c')
37
37
  expect(cop.offenses.size).to eq(1)
38
38
  expect(cop.highlights).to eq(['end.c'])
39
39
  end
40
40
 
41
41
  it 'accepts a single-line do..end block with a chained block' do
42
- inspect_source(cop, ['a do b end.c do d end'])
42
+ inspect_source(cop, 'a do b end.c do d end')
43
43
  expect(cop.offenses).to be_empty
44
44
  end
45
45
  end
@@ -53,7 +53,7 @@ describe RuboCop::Cop::Style::MethodCalledOnDoEndBlock do
53
53
  end
54
54
 
55
55
  it 'accepts a single-line block with a chained call' do
56
- inspect_source(cop, ['a { b }.c'])
56
+ inspect_source(cop, 'a { b }.c')
57
57
  expect(cop.offenses).to be_empty
58
58
  end
59
59
  end
@@ -118,7 +118,7 @@ describe RuboCop::Cop::Style::MethodName, :config do
118
118
  let(:cop_config) { { 'EnforcedStyle' => 'other' } }
119
119
 
120
120
  it 'fails' do
121
- expect { inspect_source(cop, ['def a', 'end']) }
121
+ expect { inspect_source(cop, 'def a', 'end') }
122
122
  .to raise_error(RuntimeError)
123
123
  end
124
124
  end
@@ -87,6 +87,36 @@ describe RuboCop::Cop::Style::MultilineBlockLayout do
87
87
  .to eq(['Block body expression is on the same line as the block start.'])
88
88
  end
89
89
 
90
+ it 'registers an offense for line-break before arguments' do
91
+ inspect_source(cop,
92
+ ['test do',
93
+ ' |x| play_with(x)',
94
+ 'end'])
95
+ expect(cop.messages)
96
+ .to eq(['Block argument expression is not on the same line as the ' \
97
+ 'block start.'])
98
+ end
99
+
100
+ it 'registers an offense for line-break before arguments with empty block' do
101
+ inspect_source(cop,
102
+ ['test do',
103
+ ' |x|',
104
+ 'end'])
105
+ expect(cop.messages)
106
+ .to eq(['Block argument expression is not on the same line as the ' \
107
+ 'block start.'])
108
+ end
109
+
110
+ it 'registers an offense for line-break within arguments' do
111
+ inspect_source(cop,
112
+ ['test do |x,',
113
+ ' y|',
114
+ 'end'])
115
+ expect(cop.messages)
116
+ .to eq(['Block argument expression is not on the same line as the ' \
117
+ 'block start.'])
118
+ end
119
+
90
120
  it 'auto-corrects a do/end block with params that is missing newlines' do
91
121
  src = ['test do |foo| bar',
92
122
  'end']
@@ -135,4 +165,35 @@ describe RuboCop::Cop::Style::MultilineBlockLayout do
135
165
  ' bar',
136
166
  '}'].join("\n"))
137
167
  end
168
+
169
+ it 'auto-corrects a line-break before arguments' do
170
+ new_source = autocorrect_source(cop,
171
+ ['test do',
172
+ ' |x| play_with(x)',
173
+ 'end'])
174
+
175
+ expect(new_source).to eq(['test do |x|',
176
+ ' play_with(x)',
177
+ 'end'].join("\n"))
178
+ end
179
+
180
+ it 'auto-corrects a line-break before arguments with empty block' do
181
+ new_source = autocorrect_source(cop,
182
+ ['test do',
183
+ ' |x|',
184
+ 'end'])
185
+
186
+ expect(new_source).to eq(['test do |x|',
187
+ 'end'].join("\n"))
188
+ end
189
+
190
+ it 'auto-corrects a line-break within arguments' do
191
+ new_source = autocorrect_source(cop,
192
+ ['test do |x,',
193
+ ' y| play_with(x, y)',
194
+ 'end'])
195
+ expect(new_source).to eq(['test do |x, y|',
196
+ ' play_with(x, y)',
197
+ 'end'].join("\n"))
198
+ end
138
199
  end
@@ -102,9 +102,7 @@ describe RuboCop::Cop::Style::MultilineIfThen do
102
102
  end
103
103
 
104
104
  it 'does not get confused by a postfix unless' do
105
- inspect_source(cop,
106
- ['two unless one'
107
- ])
105
+ inspect_source(cop, 'two unless one')
108
106
  expect(cop.offenses).to be_empty
109
107
  end
110
108
 
@@ -151,6 +151,14 @@ describe RuboCop::Cop::Style::MultilineOperationIndentation do
151
151
  expect(cop.messages).to be_empty
152
152
  end
153
153
 
154
+ it 'accepts any indentation of parameters to #[]' do
155
+ inspect_source(cop,
156
+ ['payment = Models::IncomingPayments[',
157
+ " id: input['incoming-payment-id'],",
158
+ ' user_id: @user[:id]]'])
159
+ expect(cop.messages).to be_empty
160
+ end
161
+
154
162
  it 'registers an offense for extra indentation of 3rd line in typical ' \
155
163
  'RSpec code' do
156
164
  inspect_source(cop,
@@ -12,7 +12,7 @@ describe RuboCop::Cop::Style::MultilineTernaryOperator do
12
12
  end
13
13
 
14
14
  it 'accepts a single line ternary operator expression' do
15
- inspect_source(cop, ['a = cond ? b : c'])
15
+ inspect_source(cop, 'a = cond ? b : c')
16
16
  expect(cop.offenses).to be_empty
17
17
  end
18
18
  end
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::NestedTernaryOperator do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for a nested ternary operator expression' do
9
- inspect_source(cop, ['a ? (b ? b1 : b2) : a2'])
9
+ inspect_source(cop, 'a ? (b ? b1 : b2) : a2')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
@@ -282,4 +282,20 @@ describe RuboCop::Cop::Style::Next, :config do
282
282
  expect(cop.highlights).to eq(['each'])
283
283
  end
284
284
  end
285
+
286
+ context 'Invalid MinBodyLength' do
287
+ let(:cop_config) do
288
+ { 'MinBodyLength' => -2 }
289
+ end
290
+
291
+ it 'fails with an error' do
292
+ source = ['loop do',
293
+ ' if o == 1',
294
+ ' puts o',
295
+ ' end',
296
+ 'end']
297
+ expect { inspect_source(cop, source) }
298
+ .to raise_error('MinBodyLength needs to be a positive integer!')
299
+ end
300
+ end
285
301
  end
@@ -7,19 +7,19 @@ describe RuboCop::Cop::Style::NumericLiterals, :config do
7
7
  let(:cop_config) { { 'MinDigits' => 5 } }
8
8
 
9
9
  it 'registers an offense for a long undelimited integer' do
10
- inspect_source(cop, ['a = 12345'])
10
+ inspect_source(cop, 'a = 12345')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  expect(cop.config_to_allow_offenses).to eq('MinDigits' => 6)
13
13
  end
14
14
 
15
15
  it 'registers an offense for a float with a long undelimited integer part' do
16
- inspect_source(cop, ['a = 123456.789'])
16
+ inspect_source(cop, 'a = 123456.789')
17
17
  expect(cop.offenses.size).to eq(1)
18
18
  expect(cop.config_to_allow_offenses).to eq('MinDigits' => 7)
19
19
  end
20
20
 
21
21
  it 'registers an offense for an integer with misplaced underscore' do
22
- inspect_source(cop, ['a = 123_456_78_90_00'])
22
+ inspect_source(cop, 'a = 123_456_78_90_00')
23
23
  expect(cop.offenses.size).to eq(1)
24
24
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
25
25
  end
@@ -31,12 +31,12 @@ describe RuboCop::Cop::Style::NumericLiterals, :config do
31
31
  end
32
32
 
33
33
  it 'accepts a short integer without underscore' do
34
- inspect_source(cop, ['a = 123'])
34
+ inspect_source(cop, 'a = 123')
35
35
  expect(cop.messages).to be_empty
36
36
  end
37
37
 
38
38
  it 'does not count a leading minus sign as a digit' do
39
- inspect_source(cop, ['a = -1230'])
39
+ inspect_source(cop, 'a = -1230')
40
40
  expect(cop.messages).to be_empty
41
41
  end
42
42
 
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::OneLineConditional do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for one line if/then/end' do
9
- inspect_source(cop, ['if cond then run else dont end'])
9
+ inspect_source(cop, 'if cond then run else dont end')
10
10
  expect(cop.messages).to eq(['Favor the ternary operator (?:)' \
11
11
  ' over if/then/else/end constructs.'])
12
12
  end
@@ -88,7 +88,7 @@ describe RuboCop::Cop::Style::ParenthesesAroundCondition, :config do
88
88
  end
89
89
 
90
90
  it 'is not confused by leading parenthesis in subexpression' do
91
- inspect_source(cop, ['(a > b) && other ? one : two'])
91
+ inspect_source(cop, '(a > b) && other ? one : two')
92
92
  expect(cop.offenses).to be_empty
93
93
  end
94
94
 
@@ -107,12 +107,12 @@ describe RuboCop::Cop::Style::ParenthesesAroundCondition, :config do
107
107
  end
108
108
 
109
109
  it 'does not blow up when the condition is a ternary op' do
110
- inspect_source(cop, ['x if (a ? b : c)'])
110
+ inspect_source(cop, 'x if (a ? b : c)')
111
111
  expect(cop.offenses.size).to eq(1)
112
112
  end
113
113
 
114
114
  context 'safe assignment is allowed' do
115
- it 'accepts = in condition surrounded with parentheses' do
115
+ it 'accepts variable assignment in condition surrounded with parentheses' do
116
116
  inspect_source(cop,
117
117
  ['if (test = 10)',
118
118
  'end'
@@ -120,6 +120,14 @@ describe RuboCop::Cop::Style::ParenthesesAroundCondition, :config do
120
120
  expect(cop.offenses).to be_empty
121
121
  end
122
122
 
123
+ it 'accepts element assignment in condition surrounded with parentheses' do
124
+ inspect_source(cop,
125
+ ['if (test[0] = 10)',
126
+ 'end'
127
+ ])
128
+ expect(cop.offenses).to be_empty
129
+ end
130
+
123
131
  it 'accepts setter in condition surrounded with parentheses' do
124
132
  inspect_source(cop,
125
133
  ['if (self.test = 10)',
@@ -132,12 +140,22 @@ describe RuboCop::Cop::Style::ParenthesesAroundCondition, :config do
132
140
  context 'safe assignment is not allowed' do
133
141
  let(:cop_config) { { 'AllowSafeAssignment' => false } }
134
142
 
135
- it 'does not accept = in condition surrounded with parentheses' do
143
+ it 'does not accept variable assignment in condition surrounded with ' \
144
+ 'parentheses' do
136
145
  inspect_source(cop,
137
146
  ['if (test = 10)',
138
147
  'end'
139
148
  ])
140
149
  expect(cop.offenses.size).to eq(1)
141
150
  end
151
+
152
+ it 'does not accept element assignment in condition surrounded with ' \
153
+ 'parentheses' do
154
+ inspect_source(cop,
155
+ ['if (test[0] = 10)',
156
+ 'end'
157
+ ])
158
+ expect(cop.offenses.size).to eq(1)
159
+ end
142
160
  end
143
161
  end
@@ -23,12 +23,12 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
23
23
 
24
24
  context '`%` interpolated string' do
25
25
  it 'does not register an offense for preferred delimiters' do
26
- inspect_source(cop, ['%[string]'])
26
+ inspect_source(cop, '%[string]')
27
27
  expect(cop.offenses).to be_empty
28
28
  end
29
29
 
30
30
  it 'registers an offense for other delimiters' do
31
- inspect_source(cop, ['%(string)'])
31
+ inspect_source(cop, '%(string)')
32
32
  expect(cop.messages).to eq([
33
33
  '`%`-literals should be delimited by `[` and `]`'
34
34
  ])
@@ -36,25 +36,25 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
36
36
 
37
37
  it 'does not register an offense for other delimiters ' \
38
38
  'when containing preferred delimiter characters' do
39
- inspect_source(cop, ['%([string])'])
39
+ inspect_source(cop, '%([string])')
40
40
  expect(cop.offenses).to be_empty
41
41
  end
42
42
 
43
43
  it 'registers an offense for other delimiters ' \
44
44
  'when containing preferred delimiter characters in interpolation' do
45
- inspect_source(cop, ['%(#{[1].first})'])
45
+ inspect_source(cop, '%(#{[1].first})')
46
46
  expect(cop.messages.size).to eq(1)
47
47
  end
48
48
  end
49
49
 
50
50
  context '`%q` string' do
51
51
  it 'does not register an offense for preferred delimiters' do
52
- inspect_source(cop, ['%q[string]'])
52
+ inspect_source(cop, '%q[string]')
53
53
  expect(cop.offenses).to be_empty
54
54
  end
55
55
 
56
56
  it 'registers an offense for other delimiters' do
57
- inspect_source(cop, ['%q(string)'])
57
+ inspect_source(cop, '%q(string)')
58
58
  expect(cop.messages).to eq([
59
59
  '`%q`-literals should be delimited by `[` and `]`'
60
60
  ])
@@ -62,19 +62,19 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
62
62
 
63
63
  it 'does not register an offense for other delimiters ' \
64
64
  'when containing preferred delimiter characters' do
65
- inspect_source(cop, ['%q([string])'])
65
+ inspect_source(cop, '%q([string])')
66
66
  expect(cop.offenses).to be_empty
67
67
  end
68
68
  end
69
69
 
70
70
  context '`%Q` interpolated string' do
71
71
  it 'does not register an offense for preferred delimiters' do
72
- inspect_source(cop, ['%Q[string]'])
72
+ inspect_source(cop, '%Q[string]')
73
73
  expect(cop.offenses).to be_empty
74
74
  end
75
75
 
76
76
  it 'registers an offense for other delimiters' do
77
- inspect_source(cop, ['%Q(string)'])
77
+ inspect_source(cop, '%Q(string)')
78
78
  expect(cop.messages).to eq([
79
79
  '`%Q`-literals should be delimited by `[` and `]`'
80
80
  ])
@@ -82,25 +82,25 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
82
82
 
83
83
  it 'does not register an offense for other delimiters ' \
84
84
  'when containing preferred delimiter characters' do
85
- inspect_source(cop, ['%Q([string])'])
85
+ inspect_source(cop, '%Q([string])')
86
86
  expect(cop.offenses).to be_empty
87
87
  end
88
88
 
89
89
  it 'registers an offense for other delimiters ' \
90
90
  'when containing preferred delimiter characters in interpolation' do
91
- inspect_source(cop, ['%Q(#{[1].first})'])
91
+ inspect_source(cop, '%Q(#{[1].first})')
92
92
  expect(cop.messages.size).to eq(1)
93
93
  end
94
94
  end
95
95
 
96
96
  context '`%w` string array' do
97
97
  it 'does not register an offense for preferred delimiters' do
98
- inspect_source(cop, ['%w[some words]'])
98
+ inspect_source(cop, '%w[some words]')
99
99
  expect(cop.offenses).to be_empty
100
100
  end
101
101
 
102
102
  it 'registers an offense for other delimiters' do
103
- inspect_source(cop, ['%w(some words)'])
103
+ inspect_source(cop, '%w(some words)')
104
104
  expect(cop.messages).to eq([
105
105
  '`%w`-literals should be delimited by `[` and `]`'
106
106
  ])
@@ -108,19 +108,19 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
108
108
 
109
109
  it 'does not register an offense for other delimiters ' \
110
110
  'when containing preferred delimiter characters' do
111
- inspect_source(cop, ['%w([some] [words])'])
111
+ inspect_source(cop, '%w([some] [words])')
112
112
  expect(cop.offenses).to be_empty
113
113
  end
114
114
  end
115
115
 
116
116
  context '`%W` interpolated string array' do
117
117
  it 'does not register an offense for preferred delimiters' do
118
- inspect_source(cop, ['%W[some words]'])
118
+ inspect_source(cop, '%W[some words]')
119
119
  expect(cop.offenses).to be_empty
120
120
  end
121
121
 
122
122
  it 'registers an offense for other delimiters' do
123
- inspect_source(cop, ['%W(some words)'])
123
+ inspect_source(cop, '%W(some words)')
124
124
  expect(cop.messages).to eq([
125
125
  '`%W`-literals should be delimited by `[` and `]`'
126
126
  ])
@@ -128,25 +128,25 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
128
128
 
129
129
  it 'does not register an offense for other delimiters ' \
130
130
  'when containing preferred delimiter characters' do
131
- inspect_source(cop, ['%W([some] [words])'])
131
+ inspect_source(cop, '%W([some] [words])')
132
132
  expect(cop.offenses).to be_empty
133
133
  end
134
134
 
135
135
  it 'registers an offense for other delimiters ' \
136
136
  'when containing preferred delimiter characters in interpolation' do
137
- inspect_source(cop, ['%W(#{[1].first})'])
137
+ inspect_source(cop, '%W(#{[1].first})')
138
138
  expect(cop.messages.size).to eq(1)
139
139
  end
140
140
  end
141
141
 
142
142
  context '`%r` interpolated regular expression' do
143
143
  it 'does not register an offense for preferred delimiters' do
144
- inspect_source(cop, ['%r[regexp]'])
144
+ inspect_source(cop, '%r[regexp]')
145
145
  expect(cop.offenses).to be_empty
146
146
  end
147
147
 
148
148
  it 'registers an offense for other delimiters' do
149
- inspect_source(cop, ['%r(regexp)'])
149
+ inspect_source(cop, '%r(regexp)')
150
150
  expect(cop.messages).to eq([
151
151
  '`%r`-literals should be delimited by `[` and `]`'
152
152
  ])
@@ -154,25 +154,25 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
154
154
 
155
155
  it 'does not register an offense for other delimiters ' \
156
156
  'when containing preferred delimiter characters' do
157
- inspect_source(cop, ['%r([regexp])'])
157
+ inspect_source(cop, '%r([regexp])')
158
158
  expect(cop.offenses).to be_empty
159
159
  end
160
160
 
161
161
  it 'registers an offense for other delimiters ' \
162
162
  'when containing preferred delimiter characters in interpolation' do
163
- inspect_source(cop, ['%r(#{[1].first})'])
163
+ inspect_source(cop, '%r(#{[1].first})')
164
164
  expect(cop.messages.size).to eq(1)
165
165
  end
166
166
  end
167
167
 
168
- context '`%i` symbol array', ruby: 2.0 do
168
+ context '`%i` symbol array', ruby: 2 do
169
169
  it 'does not register an offense for preferred delimiters' do
170
- inspect_source(cop, ['%i[some symbols]'])
170
+ inspect_source(cop, '%i[some symbols]')
171
171
  expect(cop.offenses).to be_empty
172
172
  end
173
173
 
174
174
  it 'registers an offense for other delimiters' do
175
- inspect_source(cop, ['%i(some symbols)'])
175
+ inspect_source(cop, '%i(some symbols)')
176
176
  expect(cop.messages).to eq([
177
177
  '`%i`-literals should be delimited by `[` and `]`'
178
178
  ])
@@ -181,12 +181,12 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
181
181
 
182
182
  context '`%s` symbol' do
183
183
  it 'does not register an offense for preferred delimiters' do
184
- inspect_source(cop, ['%s[symbol]'])
184
+ inspect_source(cop, '%s[symbol]')
185
185
  expect(cop.offenses).to be_empty
186
186
  end
187
187
 
188
188
  it 'registers an offense for other delimiters' do
189
- inspect_source(cop, ['%s(symbol)'])
189
+ inspect_source(cop, '%s(symbol)')
190
190
  expect(cop.messages).to eq([
191
191
  '`%s`-literals should be delimited by `[` and `]`'
192
192
  ])
@@ -195,12 +195,12 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
195
195
 
196
196
  context '`%x` interpolated system call' do
197
197
  it 'does not register an offense for preferred delimiters' do
198
- inspect_source(cop, ['%x[command]'])
198
+ inspect_source(cop, '%x[command]')
199
199
  expect(cop.offenses).to be_empty
200
200
  end
201
201
 
202
202
  it 'registers an offense for other delimiters' do
203
- inspect_source(cop, ['%x(command)'])
203
+ inspect_source(cop, '%x(command)')
204
204
  expect(cop.messages).to eq([
205
205
  '`%x`-literals should be delimited by `[` and `]`'
206
206
  ])
@@ -208,13 +208,13 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
208
208
 
209
209
  it 'does not register an offense for other delimiters ' \
210
210
  'when containing preferred delimiter characters' do
211
- inspect_source(cop, ['%x([command])'])
211
+ inspect_source(cop, '%x([command])')
212
212
  expect(cop.offenses).to be_empty
213
213
  end
214
214
 
215
215
  it 'registers an offense for other delimiters ' \
216
216
  'when containing preferred delimiter characters in interpolation' do
217
- inspect_source(cop, ['%x(#{[1].first})'])
217
+ inspect_source(cop, '%x(#{[1].first})')
218
218
  expect(cop.messages.size).to eq(1)
219
219
  end
220
220
  end