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,7 +9,8 @@ describe RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, :config do
9
9
  let(:cop_config) { { 'EnforcedStyle' => 'space' } }
10
10
 
11
11
  it 'registers an offense for default value assignment without space' do
12
- inspect_source(cop, ['def f(x, y=0, z= 1)', 'end'])
12
+ inspect_source(cop, ['def f(x, y=0, z= 1)',
13
+ 'end'])
13
14
  expect(cop.messages)
14
15
  .to eq(['Surrounding space missing in default value assignment.'] * 2)
15
16
  expect(cop.highlights).to eq(['=', '= '])
@@ -17,18 +18,21 @@ describe RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, :config do
17
18
  end
18
19
 
19
20
  it 'registers an offense for assignment empty string without space' do
20
- inspect_source(cop, ['def f(x, y="", z=1)', 'end'])
21
+ inspect_source(cop, ['def f(x, y="", z=1)',
22
+ 'end'])
21
23
  expect(cop.offenses.size).to eq(2)
22
24
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'no_space')
23
25
  end
24
26
 
25
27
  it 'registers an offense for assignment of empty list without space' do
26
- inspect_source(cop, ['def f(x, y=[])', 'end'])
28
+ inspect_source(cop, ['def f(x, y=[])',
29
+ 'end'])
27
30
  expect(cop.offenses.size).to eq(1)
28
31
  end
29
32
 
30
33
  it 'accepts default value assignment with space' do
31
- inspect_source(cop, ['def f(x, y = 0, z = {})', 'end'])
34
+ inspect_source(cop, ['def f(x, y = 0, z = {})',
35
+ 'end'])
32
36
  expect(cop.messages).to be_empty
33
37
  end
34
38
 
@@ -38,7 +42,8 @@ describe RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, :config do
38
42
  end
39
43
 
40
44
  it 'accepts default value assignment with space' do
41
- inspect_source(cop, ['def f(x, y = +1, z = {})', 'end'])
45
+ inspect_source(cop, ['def f(x, y = +1, z = {})',
46
+ 'end'])
42
47
  expect(cop.messages).to be_empty
43
48
  end
44
49
 
@@ -53,7 +58,8 @@ describe RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, :config do
53
58
  let(:cop_config) { { 'EnforcedStyle' => 'no_space' } }
54
59
 
55
60
  it 'registers an offense for default value assignment with space' do
56
- inspect_source(cop, ['def f(x, y = 0, z =1, w= 2)', 'end'])
61
+ inspect_source(cop, ['def f(x, y = 0, z =1, w= 2)',
62
+ 'end'])
57
63
  expect(cop.messages)
58
64
  .to eq(['Surrounding space detected in default value assignment.'] * 3)
59
65
  expect(cop.highlights).to eq([' = ', ' =', '= '])
@@ -61,18 +67,21 @@ describe RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, :config do
61
67
  end
62
68
 
63
69
  it 'registers an offense for assignment empty string with space' do
64
- inspect_source(cop, ['def f(x, y = "", z = 1)', 'end'])
70
+ inspect_source(cop, ['def f(x, y = "", z = 1)',
71
+ 'end'])
65
72
  expect(cop.offenses.size).to eq(2)
66
73
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'space')
67
74
  end
68
75
 
69
76
  it 'registers an offense for assignment of empty list with space' do
70
- inspect_source(cop, ['def f(x, y = [])', 'end'])
77
+ inspect_source(cop, ['def f(x, y = [])',
78
+ 'end'])
71
79
  expect(cop.offenses.size).to eq(1)
72
80
  end
73
81
 
74
82
  it 'accepts default value assignment without space' do
75
- inspect_source(cop, ['def f(x, y=0, z={})', 'end'])
83
+ inspect_source(cop, ['def f(x, y=0, z={})',
84
+ 'end'])
76
85
  expect(cop.messages).to be_empty
77
86
  end
78
87
 
@@ -6,9 +6,11 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for assignment without space on both sides' do
9
- inspect_source(cop, ['x=0', 'y= 0', 'z =0'])
10
- expect(cop.messages).to eq(
11
- ["Surrounding space missing for operator '='."] * 3)
9
+ inspect_source(cop, ['x=0', 'y+= 0', 'z[0] =0'])
10
+ expect(cop.messages)
11
+ .to eq(["Surrounding space missing for operator '='.",
12
+ "Surrounding space missing for operator '+='.",
13
+ "Surrounding space missing for operator '='."])
12
14
  end
13
15
 
14
16
  it 'auto-corrects assignment without space on both sides' do
@@ -17,7 +19,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
17
19
  end
18
20
 
19
21
  it 'registers an offense for ternary operator without space' do
20
- inspect_source(cop, ['x == 0?1:2'])
22
+ inspect_source(cop, 'x == 0?1:2')
21
23
  expect(cop.messages).to eq(
22
24
  ["Surrounding space missing for operator '?'.",
23
25
  "Surrounding space missing for operator ':'."])
@@ -71,7 +73,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
71
73
  end
72
74
 
73
75
  it 'registers an offense for arguments to a method' do
74
- inspect_source(cop, ['puts 1+2'])
76
+ inspect_source(cop, 'puts 1+2')
75
77
  expect(cop.messages).to eq(
76
78
  ["Surrounding space missing for operator '+'."])
77
79
  end
@@ -82,34 +84,34 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
82
84
  end
83
85
 
84
86
  it 'accepts operator surrounded by tabs' do
85
- inspect_source(cop, ["a\t+\tb"])
87
+ inspect_source(cop, "a\t+\tb")
86
88
  expect(cop.messages).to be_empty
87
89
  end
88
90
 
89
91
  it 'accepts operator symbols' do
90
- inspect_source(cop, ['func(:-)'])
92
+ inspect_source(cop, 'func(:-)')
91
93
  expect(cop.messages).to be_empty
92
94
  end
93
95
 
94
96
  it 'accepts ranges' do
95
- inspect_source(cop, ['a, b = (1..2), (1...3)'])
97
+ inspect_source(cop, 'a, b = (1..2), (1...3)')
96
98
  expect(cop.messages).to be_empty
97
99
  end
98
100
 
99
101
  it 'accepts scope operator' do
100
- source = ['@io.class == Zlib::GzipWriter']
102
+ source = '@io.class == Zlib::GzipWriter'
101
103
  inspect_source(cop, source)
102
104
  expect(cop.messages).to be_empty
103
105
  end
104
106
 
105
107
  it 'accepts ::Kernel::raise' do
106
- source = ['::Kernel::raise IllegalBlockError.new']
108
+ source = '::Kernel::raise IllegalBlockError.new'
107
109
  inspect_source(cop, source)
108
110
  expect(cop.messages).to be_empty
109
111
  end
110
112
 
111
113
  it 'accepts exclamation point negation' do
112
- inspect_source(cop, ['x = !a&&!b'])
114
+ inspect_source(cop, 'x = !a&&!b')
113
115
  expect(cop.messages).to eq(
114
116
  ["Surrounding space missing for operator '&&'."])
115
117
  end
@@ -143,7 +145,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
143
145
  end
144
146
 
145
147
  it 'accepts splat operator' do
146
- inspect_source(cop, ['return *list if options'])
148
+ inspect_source(cop, 'return *list if options')
147
149
  expect(cop.messages).to be_empty
148
150
  end
149
151
 
@@ -161,12 +163,12 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
161
163
  end
162
164
 
163
165
  it 'accepts an assignment with spaces' do
164
- inspect_source(cop, ['x = 0'])
166
+ inspect_source(cop, 'x = 0')
165
167
  expect(cop.offenses).to be_empty
166
168
  end
167
169
 
168
170
  it 'accepts an operator called with method syntax' do
169
- inspect_source(cop, ['Date.today.+(1).to_s'])
171
+ inspect_source(cop, 'Date.today.+(1).to_s')
170
172
  expect(cop.offenses).to be_empty
171
173
  end
172
174
 
@@ -216,7 +218,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
216
218
  end
217
219
 
218
220
  it 'registers an offenses for exponent operator with spaces' do
219
- inspect_source(cop, ['x = a * b ** 2'])
221
+ inspect_source(cop, 'x = a * b ** 2')
220
222
  expect(cop.messages).to eq(
221
223
  ['Space around operator ** detected.'])
222
224
  end
@@ -229,18 +231,18 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
229
231
  end
230
232
 
231
233
  it 'accepts exponent operator without spaces' do
232
- inspect_source(cop, ['x = a * b**2'])
234
+ inspect_source(cop, 'x = a * b**2')
233
235
  expect(cop.offenses).to be_empty
234
236
  end
235
237
 
236
238
  it 'registers an offense for a setter call without spaces' do
237
- inspect_source(cop, ['x.y=2'])
239
+ inspect_source(cop, 'x.y=2')
238
240
  expect(cop.messages).to eq(
239
241
  ["Surrounding space missing for operator '='."])
240
242
  end
241
243
 
242
244
  it 'registers an offense for a hash rocket without spaces' do
243
- inspect_source(cop, ['{ 1=>2, a: b }'])
245
+ inspect_source(cop, '{ 1=>2, a: b }')
244
246
  expect(cop.messages).to eq(
245
247
  ["Surrounding space missing for operator '=>'."])
246
248
  end
@@ -255,7 +257,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
255
257
  end
256
258
 
257
259
  it 'accepts [] without space' do
258
- inspect_source(cop, ['files[2]'])
260
+ inspect_source(cop, 'files[2]')
259
261
  expect(cop.messages).to eq([])
260
262
  end
261
263
 
@@ -275,7 +277,8 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
275
277
  end
276
278
 
277
279
  it 'registers an offense for match operators without space' do
278
- inspect_source(cop, ['x=~/abc/', 'y !~/abc/'])
280
+ inspect_source(cop, ['x=~/abc/',
281
+ 'y !~/abc/'])
279
282
  expect(cop.messages)
280
283
  .to eq(["Surrounding space missing for operator '=~'.",
281
284
  "Surrounding space missing for operator '!~'."])
@@ -305,7 +308,7 @@ describe RuboCop::Cop::Style::SpaceAroundOperators do
305
308
  end
306
309
 
307
310
  it 'registers an offense for - without space with negative lhs operand' do
308
- inspect_source(cop, ['-1-arg'])
311
+ inspect_source(cop, '-1-arg')
309
312
  expect(cop.messages)
310
313
  .to eq(["Surrounding space missing for operator '-'."])
311
314
  end
@@ -15,13 +15,13 @@ describe RuboCop::Cop::Style::SpaceBeforeBlockBraces do
15
15
 
16
16
  context 'when EnforcedStyle is space' do
17
17
  it 'accepts braces surrounded by spaces' do
18
- inspect_source(cop, ['each { puts }'])
18
+ inspect_source(cop, 'each { puts }')
19
19
  expect(cop.messages).to be_empty
20
20
  expect(cop.highlights).to be_empty
21
21
  end
22
22
 
23
23
  it 'registers an offense for left brace without outer space' do
24
- inspect_source(cop, ['each{ puts }'])
24
+ inspect_source(cop, 'each{ puts }')
25
25
  expect(cop.messages).to eq(['Space missing to the left of {.'])
26
26
  expect(cop.highlights).to eq(['{'])
27
27
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'no_space')
@@ -45,7 +45,7 @@ describe RuboCop::Cop::Style::SpaceBeforeBlockBraces do
45
45
  let(:cop_config) { { 'EnforcedStyle' => 'no_space' } }
46
46
 
47
47
  it 'registers an offense for braces surrounded by spaces' do
48
- inspect_source(cop, ['each { puts }'])
48
+ inspect_source(cop, 'each { puts }')
49
49
  expect(cop.messages).to eq(['Space detected to the left of {.'])
50
50
  expect(cop.highlights).to eq([' '])
51
51
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'space')
@@ -65,7 +65,7 @@ describe RuboCop::Cop::Style::SpaceBeforeBlockBraces do
65
65
  end
66
66
 
67
67
  it 'accepts left brace without outer space' do
68
- inspect_source(cop, ['each{ puts }'])
68
+ inspect_source(cop, 'each{ puts }')
69
69
  expect(cop.messages).to be_empty
70
70
  expect(cop.highlights).to be_empty
71
71
  end
@@ -6,25 +6,25 @@ describe RuboCop::Cop::Style::SpaceBeforeComma do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for block argument with space before comma' do
9
- inspect_source(cop, ['each { |s , t| }'])
9
+ inspect_source(cop, 'each { |s , t| }')
10
10
  expect(cop.messages).to eq(
11
11
  ['Space found before comma.'])
12
12
  end
13
13
 
14
14
  it 'registers an offense for array index with space before comma' do
15
- inspect_source(cop, ['formats[0 , 1]'])
15
+ inspect_source(cop, 'formats[0 , 1]')
16
16
  expect(cop.messages).to eq(
17
17
  ['Space found before comma.'])
18
18
  end
19
19
 
20
20
  it 'registers an offense for method call arg with space before comma' do
21
- inspect_source(cop, ['a(1 , 2)'])
21
+ inspect_source(cop, 'a(1 , 2)')
22
22
  expect(cop.messages).to eq(
23
23
  ['Space found before comma.'])
24
24
  end
25
25
 
26
26
  it 'does not register an offense for no spaces before comma' do
27
- inspect_source(cop, ['a(1, 2)'])
27
+ inspect_source(cop, 'a(1, 2)')
28
28
  expect(cop.messages).to be_empty
29
29
  end
30
30
 
@@ -6,17 +6,17 @@ describe RuboCop::Cop::Style::SpaceBeforeComment do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for missing space before an EOL comment' do
9
- inspect_source(cop, ['a += 1# increment'])
9
+ inspect_source(cop, 'a += 1# increment')
10
10
  expect(cop.highlights).to eq(['# increment'])
11
11
  end
12
12
 
13
13
  it 'accepts an EOL comment with a preceding space' do
14
- inspect_source(cop, ['a += 1 # increment'])
14
+ inspect_source(cop, 'a += 1 # increment')
15
15
  expect(cop.offenses).to be_empty
16
16
  end
17
17
 
18
18
  it 'accepts a comment that begins a line' do
19
- inspect_source(cop, ['# comment'])
19
+ inspect_source(cop, '# comment')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
@@ -6,13 +6,13 @@ describe RuboCop::Cop::Style::SpaceBeforeSemicolon do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for space before semicolon' do
9
- inspect_source(cop, ['x = 1 ; y = 2'])
9
+ inspect_source(cop, 'x = 1 ; y = 2')
10
10
  expect(cop.messages).to eq(
11
11
  ['Space found before semicolon.'])
12
12
  end
13
13
 
14
14
  it 'does not register an offense for no space before semicolons' do
15
- inspect_source(cop, ['x = 1; y = 2'])
15
+ inspect_source(cop, 'x = 1; y = 2')
16
16
  expect(cop.messages).to be_empty
17
17
  end
18
18
 
@@ -25,7 +25,7 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
25
25
  let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
26
26
 
27
27
  it 'accepts empty braces with no space inside' do
28
- inspect_source(cop, ['each {}'])
28
+ inspect_source(cop, 'each {}')
29
29
  expect(cop.messages).to be_empty
30
30
  end
31
31
 
@@ -42,7 +42,7 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
42
42
  end
43
43
 
44
44
  it 'registers an offense for empty braces with space inside' do
45
- inspect_source(cop, ['each { }'])
45
+ inspect_source(cop, 'each { }')
46
46
  expect(cop.messages).to eq(['Space inside empty braces detected.'])
47
47
  expect(cop.highlights).to eq([' '])
48
48
  end
@@ -67,12 +67,12 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
67
67
  let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
68
68
 
69
69
  it 'accepts empty braces with space inside' do
70
- inspect_source(cop, ['each { }'])
70
+ inspect_source(cop, 'each { }')
71
71
  expect(cop.messages).to be_empty
72
72
  end
73
73
 
74
74
  it 'registers an offense for empty braces with no space inside' do
75
- inspect_source(cop, ['each {}'])
75
+ inspect_source(cop, 'each {}')
76
76
  expect(cop.messages).to eq(['Space missing inside empty braces.'])
77
77
  expect(cop.highlights).to eq(['{}'])
78
78
  end
@@ -83,25 +83,34 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
83
83
  end
84
84
  end
85
85
 
86
+ context 'with invalid value for EnforcedStyleForEmptyBraces' do
87
+ let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'unknown' } }
88
+
89
+ it 'fails with an error' do
90
+ expect { inspect_source(cop, 'each { }') }
91
+ .to raise_error('Unknown EnforcedStyleForEmptyBraces selected!')
92
+ end
93
+ end
94
+
86
95
  it 'accepts braces surrounded by spaces' do
87
- inspect_source(cop, ['each { puts }'])
96
+ inspect_source(cop, 'each { puts }')
88
97
  expect(cop.messages).to be_empty
89
98
  expect(cop.highlights).to be_empty
90
99
  end
91
100
 
92
101
  it 'accepts left brace without outer space' do
93
- inspect_source(cop, ['each{ puts }'])
102
+ inspect_source(cop, 'each{ puts }')
94
103
  expect(cop.highlights).to be_empty
95
104
  end
96
105
 
97
106
  it 'registers an offense for left brace without inner space' do
98
- inspect_source(cop, ['each {puts }'])
107
+ inspect_source(cop, 'each {puts }')
99
108
  expect(cop.messages).to eq(['Space missing inside {.'])
100
109
  expect(cop.highlights).to eq(['p'])
101
110
  end
102
111
 
103
112
  it 'registers an offense for right brace without inner space' do
104
- inspect_source(cop, ['each { puts}'])
113
+ inspect_source(cop, 'each { puts}')
105
114
  expect(cop.messages).to eq(['Space missing inside }.'])
106
115
  expect(cop.highlights).to eq(['}'])
107
116
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
@@ -130,19 +139,19 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
130
139
 
131
140
  context 'with passed in parameters' do
132
141
  it 'accepts left brace with inner space' do
133
- inspect_source(cop, ['each { |x| puts }'])
142
+ inspect_source(cop, 'each { |x| puts }')
134
143
  expect(cop.messages).to be_empty
135
144
  expect(cop.highlights).to be_empty
136
145
  end
137
146
 
138
147
  it 'registers an offense for left brace without inner space' do
139
- inspect_source(cop, ['each {|x| puts }'])
148
+ inspect_source(cop, 'each {|x| puts }')
140
149
  expect(cop.messages).to eq(['Space between { and | missing.'])
141
150
  expect(cop.highlights).to eq(['{|'])
142
151
  end
143
152
 
144
153
  it 'accepts new lambda syntax' do
145
- inspect_source(cop, ['->(x) { x }'])
154
+ inspect_source(cop, '->(x) { x }')
146
155
  expect(cop.messages).to be_empty
147
156
  end
148
157
 
@@ -183,13 +192,13 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
183
192
  end
184
193
 
185
194
  it 'registers an offense for left brace with inner space' do
186
- inspect_source(cop, ['each { |x| puts }'])
195
+ inspect_source(cop, 'each { |x| puts }')
187
196
  expect(cop.messages).to eq(['Space between { and | detected.'])
188
197
  expect(cop.highlights).to eq([' '])
189
198
  end
190
199
 
191
200
  it 'accepts new lambda syntax' do
192
- inspect_source(cop, ['->(x) { x }'])
201
+ inspect_source(cop, '->(x) { x }')
193
202
  expect(cop.messages).to be_empty
194
203
  end
195
204
 
@@ -199,7 +208,7 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
199
208
  end
200
209
 
201
210
  it 'accepts left brace without inner space' do
202
- inspect_source(cop, ['each {|x| puts }'])
211
+ inspect_source(cop, 'each {|x| puts }')
203
212
  expect(cop.messages).to be_empty
204
213
  expect(cop.highlights).to be_empty
205
214
  end
@@ -216,26 +225,26 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
216
225
  end
217
226
 
218
227
  it 'accepts braces without spaces inside' do
219
- inspect_source(cop, ['each {puts}'])
228
+ inspect_source(cop, 'each {puts}')
220
229
  expect(cop.messages).to be_empty
221
230
  expect(cop.highlights).to be_empty
222
231
  end
223
232
 
224
233
  it 'registers an offense for left brace with inner space' do
225
- inspect_source(cop, ['each { puts}'])
234
+ inspect_source(cop, 'each { puts}')
226
235
  expect(cop.messages).to eq(['Space inside { detected.'])
227
236
  expect(cop.highlights).to eq([' '])
228
237
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
229
238
  end
230
239
 
231
240
  it 'registers an offense for right brace with inner space' do
232
- inspect_source(cop, ['each {puts }'])
241
+ inspect_source(cop, 'each {puts }')
233
242
  expect(cop.messages).to eq(['Space inside } detected.'])
234
243
  expect(cop.highlights).to eq([' '])
235
244
  end
236
245
 
237
246
  it 'registers offenses for both braces with inner space' do
238
- inspect_source(cop, ['each { puts }'])
247
+ inspect_source(cop, 'each { puts }')
239
248
  expect(cop.messages).to eq(['Space inside { detected.',
240
249
  'Space inside } detected.'])
241
250
  expect(cop.highlights).to eq([' ', ' '])
@@ -244,7 +253,7 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
244
253
  end
245
254
 
246
255
  it 'accepts left brace without outer space' do
247
- inspect_source(cop, ['each {puts}'])
256
+ inspect_source(cop, 'each {puts}')
248
257
  expect(cop.highlights).to be_empty
249
258
  end
250
259
 
@@ -256,19 +265,19 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
256
265
  context 'with passed in parameters' do
257
266
  context 'and space before block parameters allowed' do
258
267
  it 'accepts left brace with inner space' do
259
- inspect_source(cop, ['each { |x| puts}'])
268
+ inspect_source(cop, 'each { |x| puts}')
260
269
  expect(cop.messages).to eq([])
261
270
  expect(cop.highlights).to eq([])
262
271
  end
263
272
 
264
273
  it 'registers an offense for left brace without inner space' do
265
- inspect_source(cop, ['each {|x| puts}'])
274
+ inspect_source(cop, 'each {|x| puts}')
266
275
  expect(cop.messages).to eq(['Space between { and | missing.'])
267
276
  expect(cop.highlights).to eq(['{|'])
268
277
  end
269
278
 
270
279
  it 'accepts new lambda syntax' do
271
- inspect_source(cop, ['->(x) {x}'])
280
+ inspect_source(cop, '->(x) {x}')
272
281
  expect(cop.messages).to be_empty
273
282
  end
274
283
 
@@ -288,13 +297,13 @@ describe RuboCop::Cop::Style::SpaceInsideBlockBraces do
288
297
  end
289
298
 
290
299
  it 'registers an offense for left brace with inner space' do
291
- inspect_source(cop, ['each { |x| puts}'])
300
+ inspect_source(cop, 'each { |x| puts}')
292
301
  expect(cop.messages).to eq(['Space between { and | detected.'])
293
302
  expect(cop.highlights).to eq([' '])
294
303
  end
295
304
 
296
305
  it 'accepts new lambda syntax' do
297
- inspect_source(cop, ['->(x) {x}'])
306
+ inspect_source(cop, '->(x) {x}')
298
307
  expect(cop.messages).to be_empty
299
308
  end
300
309