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
@@ -7,19 +7,19 @@ describe RuboCop::Cop::Rails::ScopeArgs do
7
7
 
8
8
  it 'registers an offense a scope with a method arg' do
9
9
  inspect_source(cop,
10
- ['scope :active, where(active: true)'])
10
+ 'scope :active, where(active: true)')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'accepts a lambda arg' do
15
15
  inspect_source(cop,
16
- ['scope :active, -> { where(active: true) }'])
16
+ 'scope :active, -> { where(active: true) }')
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
 
20
20
  it 'accepts a proc arg' do
21
21
  inspect_source(cop,
22
- ['scope :active, proc { where(active: true) }'])
22
+ 'scope :active, proc { where(active: true) }')
23
23
  expect(cop.offenses).to be_empty
24
24
  end
25
25
  end
@@ -8,13 +8,13 @@ describe RuboCop::Cop::Rails::Validation do
8
8
  described_class::BLACKLIST.each_with_index do |validation, number|
9
9
  it "registers an offense for #{validation}" do
10
10
  inspect_source(cop,
11
- ["#{validation} :name"])
11
+ "#{validation} :name")
12
12
  expect(cop.offenses.size).to eq(1)
13
13
  end
14
14
 
15
15
  it "outputs the correct message for #{validation}" do
16
16
  inspect_source(cop,
17
- ["#{validation} :name"])
17
+ "#{validation} :name")
18
18
  expect(cop.offenses.first.message)
19
19
  .to include(described_class::WHITELIST[number])
20
20
  end
@@ -22,7 +22,7 @@ describe RuboCop::Cop::Rails::Validation do
22
22
 
23
23
  it 'accepts new style validations' do
24
24
  inspect_source(cop,
25
- ['validates :name'])
25
+ 'validates :name')
26
26
  expect(cop.offenses).to be_empty
27
27
  end
28
28
  end
@@ -7,7 +7,7 @@ describe RuboCop::Cop::Style::Alias do
7
7
 
8
8
  it 'registers an offense for alias with symbol args' do
9
9
  inspect_source(cop,
10
- ['alias :ala :bala'])
10
+ 'alias :ala :bala')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  expect(cop.messages)
13
13
  .to eq(['Use `alias_method` instead of `alias`.'])
@@ -20,7 +20,7 @@ describe RuboCop::Cop::Style::Alias do
20
20
 
21
21
  it 'registers an offense for alias with bareword args' do
22
22
  inspect_source(cop,
23
- ['alias ala bala'])
23
+ 'alias ala bala')
24
24
  expect(cop.offenses.size).to eq(1)
25
25
  expect(cop.messages)
26
26
  .to eq(['Use `alias_method` instead of `alias`.'])
@@ -33,19 +33,19 @@ describe RuboCop::Cop::Style::Alias do
33
33
 
34
34
  it 'does not register an offense for alias_method' do
35
35
  inspect_source(cop,
36
- ['alias_method :ala, :bala'])
36
+ 'alias_method :ala, :bala')
37
37
  expect(cop.offenses).to be_empty
38
38
  end
39
39
 
40
40
  it 'does not register an offense for :alias' do
41
41
  inspect_source(cop,
42
- ['[:alias, :ala, :bala]'])
42
+ '[:alias, :ala, :bala]')
43
43
  expect(cop.offenses).to be_empty
44
44
  end
45
45
 
46
46
  it 'does not register an offense for alias with gvars' do
47
47
  inspect_source(cop,
48
- ['alias $ala $bala'])
48
+ 'alias $ala $bala')
49
49
  expect(cop.offenses).to be_empty
50
50
  end
51
51
 
@@ -296,7 +296,7 @@ describe RuboCop::Cop::Style::AlignHash, :config do
296
296
  end
297
297
 
298
298
  it 'accepts a single method argument entry with colon' do
299
- inspect_source(cop, ['merge(parent: nil)'])
299
+ inspect_source(cop, 'merge(parent: nil)')
300
300
  expect(cop.offenses).to be_empty
301
301
  end
302
302
  end
@@ -47,7 +47,7 @@ describe RuboCop::Cop::Style::AlignParameters do
47
47
  end
48
48
 
49
49
  it 'accepts calls that only span one line' do
50
- inspect_source(cop, ['find(path, s, @special[sexp[0]])'])
50
+ inspect_source(cop, 'find(path, s, @special[sexp[0]])')
51
51
  expect(cop.offenses).to be_empty
52
52
  end
53
53
 
@@ -100,12 +100,12 @@ describe RuboCop::Cop::Style::AlignParameters do
100
100
  end
101
101
 
102
102
  it "doesn't get confused by symbols with embedded expressions" do
103
- inspect_source(cop, ['send(:"#{name}_comments_path")'])
103
+ inspect_source(cop, 'send(:"#{name}_comments_path")')
104
104
  expect(cop.offenses).to be_empty
105
105
  end
106
106
 
107
107
  it "doesn't get confused by regexen with embedded expressions" do
108
- inspect_source(cop, ['a(/#{name}/)'])
108
+ inspect_source(cop, 'a(/#{name}/)')
109
109
  expect(cop.offenses).to be_empty
110
110
  end
111
111
 
@@ -142,7 +142,7 @@ describe RuboCop::Cop::Style::AlignParameters do
142
142
  end
143
143
 
144
144
  it 'can handle a call embedded in a string' do
145
- inspect_source(cop, ['model("#{index(name)}", child)'])
145
+ inspect_source(cop, 'model("#{index(name)}", child)')
146
146
  expect(cop.offenses).to be_empty
147
147
  end
148
148
 
@@ -163,12 +163,12 @@ describe RuboCop::Cop::Style::AlignParameters do
163
163
  end
164
164
 
165
165
  it 'can handle a ternary condition with a block reference' do
166
- inspect_source(cop, ['cond ? a : func(&b)'])
166
+ inspect_source(cop, 'cond ? a : func(&b)')
167
167
  expect(cop.offenses).to be_empty
168
168
  end
169
169
 
170
170
  it 'can handle parentheses used with no parameters' do
171
- inspect_source(cop, ['func()'])
171
+ inspect_source(cop, 'func()')
172
172
  expect(cop.offenses).to be_empty
173
173
  end
174
174
 
@@ -180,12 +180,12 @@ describe RuboCop::Cop::Style::AlignParameters do
180
180
  end
181
181
 
182
182
  it 'can handle method calls without parentheses' do
183
- inspect_source(cop, ['a(b c, d)'])
183
+ inspect_source(cop, 'a(b c, d)')
184
184
  expect(cop.offenses).to be_empty
185
185
  end
186
186
 
187
187
  it 'can handle other method calls without parentheses' do
188
- src = ['chars(Unicode.apply_mapping @wrapped_string, :uppercase)']
188
+ src = 'chars(Unicode.apply_mapping @wrapped_string, :uppercase)'
189
189
  inspect_source(cop, src)
190
190
  expect(cop.offenses).to be_empty
191
191
  end
@@ -13,8 +13,7 @@ describe RuboCop::Cop::Style::AndOr, :config do
13
13
 
14
14
  %w(and or).each do |operator|
15
15
  it "accepts \"#{operator}\" outside of conditional" do
16
- inspect_source(cop,
17
- ["x = a + b #{operator} return x"])
16
+ inspect_source(cop, "x = a + b #{operator} return x")
18
17
  expect(cop.offenses).to be_empty
19
18
  end
20
19
 
@@ -51,14 +50,12 @@ describe RuboCop::Cop::Style::AndOr, :config do
51
50
 
52
51
  %w(&& ||).each do |operator|
53
52
  it "accepts #{operator} inside of conditional" do
54
- inspect_source(cop,
55
- ["test if a #{operator} b"])
53
+ inspect_source(cop, "test if a #{operator} b")
56
54
  expect(cop.offenses).to be_empty
57
55
  end
58
56
 
59
57
  it "accepts #{operator} outside of conditional" do
60
- inspect_source(cop,
61
- ["x = a #{operator} b"])
58
+ inspect_source(cop, "x = a #{operator} b")
62
59
  expect(cop.offenses).to be_empty
63
60
  end
64
61
  end
@@ -73,28 +70,24 @@ describe RuboCop::Cop::Style::AndOr, :config do
73
70
  let(:cop_config) { cop_config }
74
71
 
75
72
  it 'registers an offense for "or"' do
76
- inspect_source(cop,
77
- ['test if a or b'])
73
+ inspect_source(cop, 'test if a or b')
78
74
  expect(cop.offenses.size).to eq(1)
79
75
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
80
76
  end
81
77
 
82
78
  it 'registers an offense for "and"' do
83
- inspect_source(cop,
84
- ['test if a and b'])
79
+ inspect_source(cop, 'test if a and b')
85
80
  expect(cop.offenses.size).to eq(1)
86
81
  expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
87
82
  end
88
83
 
89
84
  it 'accepts ||' do
90
- inspect_source(cop,
91
- ['test if a || b'])
85
+ inspect_source(cop, 'test if a || b')
92
86
  expect(cop.offenses).to be_empty
93
87
  end
94
88
 
95
89
  it 'accepts &&' do
96
- inspect_source(cop,
97
- ['test if a && b'])
90
+ inspect_source(cop, 'test if a && b')
98
91
  expect(cop.offenses).to be_empty
99
92
  end
100
93
 
@@ -132,57 +125,49 @@ describe RuboCop::Cop::Style::AndOr, :config do
132
125
  end
133
126
 
134
127
  it 'warns on short-circuit (and)' do
135
- inspect_source(cop,
136
- ['x = a + b and return x'])
128
+ inspect_source(cop, 'x = a + b and return x')
137
129
  expect(cop.offenses.size).to eq(1)
138
130
  expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
139
131
  end
140
132
 
141
133
  it 'also warns on non short-circuit (and)' do
142
- inspect_source(cop,
143
- ['x = a + b if a and b'])
134
+ inspect_source(cop, 'x = a + b if a and b')
144
135
  expect(cop.offenses.size).to eq(1)
145
136
  expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
146
137
  end
147
138
 
148
139
  it 'also warns on non short-circuit (and) (unless)' do
149
- inspect_source(cop,
150
- ['x = a + b unless a and b'])
140
+ inspect_source(cop, 'x = a + b unless a and b')
151
141
  expect(cop.offenses.size).to eq(1)
152
142
  expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
153
143
  end
154
144
 
155
145
  it 'warns on short-circuit (or)' do
156
- inspect_source(cop,
157
- ['x = a + b or return x'])
146
+ inspect_source(cop, 'x = a + b or return x')
158
147
  expect(cop.offenses.size).to eq(1)
159
148
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
160
149
  end
161
150
 
162
151
  it 'also warns on non short-circuit (or)' do
163
- inspect_source(cop,
164
- ['x = a + b if a or b'])
152
+ inspect_source(cop, 'x = a + b if a or b')
165
153
  expect(cop.offenses.size).to eq(1)
166
154
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
167
155
  end
168
156
 
169
157
  it 'also warns on non short-circuit (or) (unless)' do
170
- inspect_source(cop,
171
- ['x = a + b unless a or b'])
158
+ inspect_source(cop, 'x = a + b unless a or b')
172
159
  expect(cop.offenses.size).to eq(1)
173
160
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
174
161
  end
175
162
 
176
163
  it 'also warns on while (or)' do
177
- inspect_source(cop,
178
- ['x = a + b while a or b'])
164
+ inspect_source(cop, 'x = a + b while a or b')
179
165
  expect(cop.offenses.size).to eq(1)
180
166
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
181
167
  end
182
168
 
183
169
  it 'also warns on until (or)' do
184
- inspect_source(cop,
185
- ['x = a + b until a or b'])
170
+ inspect_source(cop, 'x = a + b until a or b')
186
171
  expect(cop.offenses.size).to eq(1)
187
172
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
188
173
  end
@@ -7,23 +7,23 @@ describe RuboCop::Cop::Style::ArrayJoin do
7
7
 
8
8
  it 'registers an offense for an array followed by string' do
9
9
  inspect_source(cop,
10
- ['%w(one two three) * ", "'])
10
+ '%w(one two three) * ", "')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'does not register an offense for numbers' do
15
15
  inspect_source(cop,
16
- ['%w(one two three) * 4'])
16
+ '%w(one two three) * 4')
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
 
20
20
  it 'does not register an offense for ambiguous cases' do
21
21
  inspect_source(cop,
22
- ['test * ", "'])
22
+ 'test * ", "')
23
23
  expect(cop.offenses).to be_empty
24
24
 
25
25
  inspect_source(cop,
26
- ['%w(one two three) * test'])
26
+ '%w(one two three) * test')
27
27
  expect(cop.offenses).to be_empty
28
28
  end
29
29
  end
@@ -15,8 +15,7 @@ describe RuboCop::Cop::Style::AsciiComments do
15
15
  end
16
16
 
17
17
  it 'accepts comments with only ascii chars' do
18
- inspect_source(cop,
19
- ['# AZaz1@$%~,;*_`|'])
18
+ inspect_source(cop, '# AZaz1@$%~,;*_`|')
20
19
  expect(cop.offenses).to be_empty
21
20
  end
22
21
  end
@@ -16,7 +16,7 @@ describe RuboCop::Cop::Style::AsciiIdentifiers do
16
16
 
17
17
  it 'accepts identifiers with only ascii chars' do
18
18
  inspect_source(cop,
19
- ['x.empty?'])
19
+ 'x.empty?')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
@@ -30,7 +30,7 @@ describe RuboCop::Cop::Style::AsciiIdentifiers do
30
30
 
31
31
  it 'does not get confused by an empty file' do
32
32
  inspect_source(cop,
33
- [''])
33
+ '')
34
34
  expect(cop.offenses).to be_empty
35
35
  end
36
36
  end
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::BeginBlock do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'reports an offense for a BEGIN block' do
9
- src = ['BEGIN { test }']
9
+ src = 'BEGIN { test }'
10
10
  inspect_source(cop, src)
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
@@ -15,7 +15,7 @@ describe RuboCop::Cop::Style::BlockComments do
15
15
 
16
16
  it 'accepts regular comments' do
17
17
  inspect_source(cop,
18
- ['# comment'])
18
+ '# comment')
19
19
  expect(cop.offenses).to be_empty
20
20
  end
21
21
 
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::BlockEndNewline do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'does not register an offense for a one-liner' do
9
- inspect_source(cop, ['test do foo end'])
9
+ inspect_source(cop, 'test do foo end')
10
10
  expect(cop.messages).to be_empty
11
11
  end
12
12
 
@@ -12,13 +12,13 @@ describe RuboCop::Cop::Style::Blocks do
12
12
  end
13
13
 
14
14
  it 'registers an offense for a single line block with do-end' do
15
- inspect_source(cop, ['each do |x| end'])
15
+ inspect_source(cop, 'each do |x| end')
16
16
  expect(cop.messages)
17
17
  .to eq(['Prefer {...} over do...end for single-line blocks.'])
18
18
  end
19
19
 
20
20
  it 'accepts a single line block with braces' do
21
- inspect_source(cop, ['each { |x| }'])
21
+ inspect_source(cop, 'each { |x| }')
22
22
  expect(cop.offenses).to be_empty
23
23
  end
24
24
 
@@ -9,15 +9,15 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
9
9
  after(:each) { expect(cop.offenses).to be_empty }
10
10
 
11
11
  it 'accepts one non-hash parameter' do
12
- inspect_source(cop, ['where(2)'])
12
+ inspect_source(cop, 'where(2)')
13
13
  end
14
14
 
15
15
  it 'accepts multiple non-hash parameters' do
16
- inspect_source(cop, ['where(1, "2")'])
16
+ inspect_source(cop, 'where(1, "2")')
17
17
  end
18
18
 
19
19
  it 'accepts one empty hash parameter' do
20
- inspect_source(cop, ['where({})'])
20
+ inspect_source(cop, 'where({})')
21
21
  end
22
22
 
23
23
  it 'accepts one empty hash parameter with whitespace' do
@@ -30,23 +30,23 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
30
30
  after(:each) { expect(cop.offenses).to be_empty }
31
31
 
32
32
  it 'accepts one hash parameter without braces' do
33
- inspect_source(cop, ['where(x: "y")'])
33
+ inspect_source(cop, 'where(x: "y")')
34
34
  end
35
35
 
36
36
  it 'accepts one hash parameter without braces and with multiple keys' do
37
- inspect_source(cop, ['where(x: "y", foo: "bar")'])
37
+ inspect_source(cop, 'where(x: "y", foo: "bar")')
38
38
  end
39
39
 
40
40
  it 'accepts one hash parameter without braces and with one hash value' do
41
- inspect_source(cop, ['where(x: { "y" => "z" })'])
41
+ inspect_source(cop, 'where(x: { "y" => "z" })')
42
42
  end
43
43
 
44
44
  it 'accepts property assignment with braces' do
45
- inspect_source(cop, ['x.z = { y: "z" }'])
45
+ inspect_source(cop, 'x.z = { y: "z" }')
46
46
  end
47
47
 
48
48
  it 'accepts operator with a hash parameter with braces' do
49
- inspect_source(cop, ['x.z - { y: "z" }'])
49
+ inspect_source(cop, 'x.z - { y: "z" }')
50
50
  end
51
51
  end
52
52
 
@@ -55,34 +55,34 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
55
55
 
56
56
  it 'registers an offense for one non-hash parameter followed by a hash ' \
57
57
  'parameter with braces' do
58
- inspect_source(cop, ['where(1, { y: 2 })'])
58
+ inspect_source(cop, 'where(1, { y: 2 })')
59
59
  expect(cop.messages).to eq([msg])
60
60
  expect(cop.highlights).to eq(['{ y: 2 }'])
61
61
  end
62
62
 
63
63
  it 'registers an offense for one object method hash parameter with ' \
64
64
  'braces' do
65
- inspect_source(cop, ['x.func({ y: "z" })'])
65
+ inspect_source(cop, 'x.func({ y: "z" })')
66
66
  expect(cop.messages).to eq([msg])
67
67
  expect(cop.highlights).to eq(['{ y: "z" }'])
68
68
  end
69
69
 
70
70
  it 'registers an offense for one hash parameter with braces' do
71
- inspect_source(cop, ['where({ x: 1 })'])
71
+ inspect_source(cop, 'where({ x: 1 })')
72
72
  expect(cop.messages).to eq([msg])
73
73
  expect(cop.highlights).to eq(['{ x: 1 }'])
74
74
  end
75
75
 
76
76
  it 'registers an offense for one hash parameter with braces and ' \
77
77
  'whitespace' do
78
- inspect_source(cop, ["where( \n { x: 1 } )"])
78
+ inspect_source(cop, "where( \n { x: 1 } )")
79
79
  expect(cop.messages).to eq([msg])
80
80
  expect(cop.highlights).to eq(['{ x: 1 }'])
81
81
  end
82
82
 
83
83
  it 'registers an offense for one hash parameter with braces and multiple ' \
84
84
  'keys' do
85
- inspect_source(cop, ['where({ x: 1, foo: "bar" })'])
85
+ inspect_source(cop, 'where({ x: 1, foo: "bar" })')
86
86
  expect(cop.messages).to eq([msg])
87
87
  expect(cop.highlights).to eq(['{ x: 1, foo: "bar" }'])
88
88
  end
@@ -92,51 +92,56 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
92
92
  it 'corrects one non-hash parameter followed by a hash parameter with ' \
93
93
  'braces' do
94
94
  corrected = autocorrect_source(cop, ['where(1, { y: 2 })'])
95
- expect(corrected).to eq('where(1, y: 2 )')
95
+ expect(corrected).to eq('where(1, y: 2)')
96
96
  end
97
97
 
98
98
  it 'corrects one object method hash parameter with braces' do
99
99
  corrected = autocorrect_source(cop, ['x.func({ y: "z" })'])
100
- expect(corrected).to eq('x.func( y: "z" )')
100
+ expect(corrected).to eq('x.func(y: "z")')
101
101
  end
102
102
 
103
103
  it 'corrects one hash parameter with braces' do
104
104
  corrected = autocorrect_source(cop, ['where({ x: 1 })'])
105
- expect(corrected).to eq('where( x: 1 )')
105
+ expect(corrected).to eq('where(x: 1)')
106
106
  end
107
107
 
108
108
  it 'corrects one hash parameter with braces and whitespace' do
109
109
  corrected = autocorrect_source(cop, ['where( ',
110
110
  ' { x: 1 } )'])
111
111
  expect(corrected).to eq(['where( ',
112
- ' x: 1 )'].join("\n"))
112
+ ' x: 1 )'].join("\n"))
113
113
  end
114
114
 
115
115
  it 'corrects one hash parameter with braces and multiple keys' do
116
116
  corrected = autocorrect_source(cop, ['where({ x: 1, foo: "bar" })'])
117
- expect(corrected).to eq('where( x: 1, foo: "bar" )')
117
+ expect(corrected).to eq('where(x: 1, foo: "bar")')
118
118
  end
119
119
 
120
120
  it 'corrects one hash parameter with braces and extra leading whitespace' do
121
121
  corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
122
- expect(corrected).to eq('where( x: 1, y: 2 )')
122
+ expect(corrected).to eq('where(x: 1, y: 2)')
123
123
  end
124
124
 
125
125
  it 'corrects one hash parameter with braces and extra trailing ' \
126
126
  'whitespace' do
127
127
  corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
128
- expect(corrected).to eq('where( x: 1, y: 2 )')
128
+ expect(corrected).to eq('where(x: 1, y: 2)')
129
129
  end
130
130
 
131
131
  it 'corrects one hash parameter with braces and a trailing comma' do
132
132
  corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
133
- expect(corrected).to eq('where( x: 1, y: 2, )')
133
+ expect(corrected).to eq('where(x: 1, y: 2,)')
134
134
  end
135
135
 
136
136
  it 'corrects one hash parameter with braces and trailing comma and ' \
137
137
  'whitespace' do
138
138
  corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
139
- expect(corrected).to eq('where( x: 1, y: 2, )')
139
+ expect(corrected).to eq('where(x: 1, y: 2,)')
140
+ end
141
+
142
+ it 'corrects one hash parameter with braces without adding extra space' do
143
+ corrected = autocorrect_source(cop, 'get :i, { q: { x: 1 } }')
144
+ expect(corrected).to eq('get :i, q: { x: 1 }')
140
145
  end
141
146
  end
142
147
 
@@ -157,7 +162,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
157
162
  end
158
163
 
159
164
  it 'registers an offense for two hash parameters with braces' do
160
- inspect_source(cop, ['where({ x: 1 }, { y: 2 })'])
165
+ inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
161
166
  expect(cop.highlights).to eq(['{ y: 2 }'])
162
167
  end
163
168
  end
@@ -167,12 +172,12 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
167
172
 
168
173
  it 'corrects one hash parameter with braces' do
169
174
  corrected = autocorrect_source(cop, ['where(1, { x: 1 })'])
170
- expect(corrected).to eq('where(1, x: 1 )')
175
+ expect(corrected).to eq('where(1, x: 1)')
171
176
  end
172
177
 
173
178
  it 'corrects two hash parameters with braces' do
174
179
  corrected = autocorrect_source(cop, ['where(1, { x: 1 }, { y: 2 })'])
175
- expect(corrected).to eq('where(1, { x: 1 }, y: 2 )')
180
+ expect(corrected).to eq('where(1, { x: 1 }, y: 2)')
176
181
  end
177
182
  end
178
183
  end
@@ -185,7 +190,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
185
190
  include_examples 'no_braces and context_dependent non-offenses'
186
191
 
187
192
  it 'accepts two hash parameters with braces' do
188
- inspect_source(cop, ['where({ x: 1 }, { y: 2 })'])
193
+ inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
189
194
  expect(cop.offenses).to be_empty
190
195
  end
191
196
  end
@@ -195,7 +200,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
195
200
 
196
201
  it 'registers an offense for one hash parameter with braces and one ' \
197
202
  'without' do
198
- inspect_source(cop, ['where({ x: 1 }, y: 2)'])
203
+ inspect_source(cop, 'where({ x: 1 }, y: 2)')
199
204
  expect(cop.messages)
200
205
  .to eq(['Missing curly braces around a hash parameter.'])
201
206
  expect(cop.highlights).to eq(['y: 2'])
@@ -212,7 +217,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
212
217
 
213
218
  it 'corrects one hash parameter with braces' do
214
219
  corrected = autocorrect_source(cop, ['where(1, { x: 1 })'])
215
- expect(corrected).to eq('where(1, x: 1 )')
220
+ expect(corrected).to eq('where(1, x: 1)')
216
221
  end
217
222
  end
218
223
  end
@@ -226,11 +231,11 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
226
231
  after(:each) { expect(cop.offenses).to be_empty }
227
232
 
228
233
  it 'accepts one hash parameter with braces' do
229
- inspect_source(cop, ['where({ x: 1 })'])
234
+ inspect_source(cop, 'where({ x: 1 })')
230
235
  end
231
236
 
232
237
  it 'accepts multiple hash parameters with braces' do
233
- inspect_source(cop, ['where({ x: 1 }, { y: 2 })'])
238
+ inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
234
239
  end
235
240
 
236
241
  it 'accepts one hash parameter with braces and whitespace' do
@@ -246,19 +251,19 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
246
251
  end
247
252
 
248
253
  it 'registers an offense for one hash parameter without braces' do
249
- inspect_source(cop, ['where(x: "y")'])
254
+ inspect_source(cop, 'where(x: "y")')
250
255
  expect(cop.highlights).to eq(['x: "y"'])
251
256
  end
252
257
 
253
258
  it 'registers an offense for one hash parameter with multiple keys and ' \
254
259
  'without braces' do
255
- inspect_source(cop, ['where(x: "y", foo: "bar")'])
260
+ inspect_source(cop, 'where(x: "y", foo: "bar")')
256
261
  expect(cop.highlights).to eq(['x: "y", foo: "bar"'])
257
262
  end
258
263
 
259
264
  it 'registers an offense for one hash parameter without braces with ' \
260
265
  'one hash value' do
261
- inspect_source(cop, ['where(x: { "y" => "z" })'])
266
+ inspect_source(cop, 'where(x: { "y" => "z" })')
262
267
  expect(cop.highlights).to eq(['x: { "y" => "z" }'])
263
268
  end
264
269
  end