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
@@ -56,12 +56,12 @@ describe RuboCop::Cop::Style::SpaceInsideBrackets do
56
56
  end
57
57
 
58
58
  it 'accepts square brackets called with method call syntax' do
59
- inspect_source(cop, ['subject.[](0)'])
59
+ inspect_source(cop, 'subject.[](0)')
60
60
  expect(cop.messages).to be_empty
61
61
  end
62
62
 
63
63
  it 'only reports a single space once' do
64
- inspect_source(cop, ['[ ]'])
64
+ inspect_source(cop, '[ ]')
65
65
  expect(cop.messages).to eq(
66
66
  ['Space inside square brackets detected.'])
67
67
  end
@@ -10,12 +10,12 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
10
10
  let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
11
11
 
12
12
  it 'accepts empty braces with no space inside' do
13
- inspect_source(cop, ['h = {}'])
13
+ inspect_source(cop, 'h = {}')
14
14
  expect(cop.messages).to be_empty
15
15
  end
16
16
 
17
17
  it 'registers an offense for empty braces with space inside' do
18
- inspect_source(cop, ['h = { }'])
18
+ inspect_source(cop, 'h = { }')
19
19
  expect(cop.messages)
20
20
  .to eq(['Space inside empty hash literal braces detected.'])
21
21
  expect(cop.highlights).to eq([' '])
@@ -31,12 +31,12 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
31
31
  let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
32
32
 
33
33
  it 'accepts empty braces with space inside' do
34
- inspect_source(cop, ['h = { }'])
34
+ inspect_source(cop, 'h = { }')
35
35
  expect(cop.messages).to be_empty
36
36
  end
37
37
 
38
38
  it 'registers an offense for empty braces with no space inside' do
39
- inspect_source(cop, ['h = {}'])
39
+ inspect_source(cop, 'h = {}')
40
40
  expect(cop.messages)
41
41
  .to eq(['Space inside empty hash literal braces missing.'])
42
42
  expect(cop.highlights).to eq(['{'])
@@ -62,7 +62,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
62
62
 
63
63
  it 'registers an offense for correct + opposite' do
64
64
  inspect_source(cop,
65
- ['h = { a: 1}'])
65
+ 'h = { a: 1}')
66
66
  expect(cop.messages).to eq(['Space inside } missing.'])
67
67
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
68
68
  end
@@ -79,7 +79,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
79
79
 
80
80
  it 'registers an offense for hashes with spaces' do
81
81
  inspect_source(cop,
82
- ['h = { a: 1, b: 2 }'])
82
+ 'h = { a: 1, b: 2 }')
83
83
  expect(cop.messages).to eq(['Space inside { detected.',
84
84
  'Space inside } detected.'])
85
85
  expect(cop.highlights).to eq([' ', ' '])
@@ -88,7 +88,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
88
88
 
89
89
  it 'registers an offense for opposite + correct' do
90
90
  inspect_source(cop,
91
- ['h = {a: 1 }'])
91
+ 'h = {a: 1 }')
92
92
  expect(cop.messages).to eq(['Space inside } detected.'])
93
93
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
94
94
  end
@@ -134,14 +134,14 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
134
134
  end
135
135
 
136
136
  it 'accepts hash literals with no braces' do
137
- inspect_source(cop, ['x(a: b.c)'])
137
+ inspect_source(cop, 'x(a: b.c)')
138
138
  expect(cop.offenses).to be_empty
139
139
  end
140
140
 
141
141
  it 'can handle interpolation in a braceless hash literal' do
142
142
  # A tricky special case where the closing brace of the
143
143
  # interpolation risks getting confused for a hash literal brace.
144
- inspect_source(cop, ['f(get: "#{x}")'])
144
+ inspect_source(cop, 'f(get: "#{x}")')
145
145
  expect(cop.offenses).to be_empty
146
146
  end
147
147
  end
@@ -19,7 +19,7 @@ describe RuboCop::Cop::Style::SpaceInsideParens do
19
19
  end
20
20
 
21
21
  it 'accepts parentheses with no spaces' do
22
- inspect_source(cop, ['split("\n")'])
22
+ inspect_source(cop, 'split("\n")')
23
23
  expect(cop.messages).to be_empty
24
24
  end
25
25
 
@@ -6,28 +6,28 @@ describe RuboCop::Cop::Style::SpecialGlobalVars do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for $:' do
9
- inspect_source(cop, ['puts $:'])
9
+ inspect_source(cop, 'puts $:')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  expect(cop.messages)
12
12
  .to eq(['Prefer `$LOAD_PATH` over `$:`.'])
13
13
  end
14
14
 
15
15
  it 'registers an offense for $"' do
16
- inspect_source(cop, ['puts $"'])
16
+ inspect_source(cop, 'puts $"')
17
17
  expect(cop.offenses.size).to eq(1)
18
18
  expect(cop.messages)
19
19
  .to eq(['Prefer `$LOADED_FEATURES` over `$"`.'])
20
20
  end
21
21
 
22
22
  it 'registers an offense for $0' do
23
- inspect_source(cop, ['puts $0'])
23
+ inspect_source(cop, 'puts $0')
24
24
  expect(cop.offenses.size).to eq(1)
25
25
  expect(cop.messages)
26
26
  .to eq(['Prefer `$PROGRAM_NAME` over `$0`.'])
27
27
  end
28
28
 
29
29
  it 'registers an offense for $$' do
30
- inspect_source(cop, ['puts $$'])
30
+ inspect_source(cop, 'puts $$')
31
31
  expect(cop.offenses.size).to eq(1)
32
32
  expect(cop.messages)
33
33
  .to eq(['Prefer `$PROCESS_ID` or `$PID` from the English ' \
@@ -35,13 +35,13 @@ describe RuboCop::Cop::Style::SpecialGlobalVars do
35
35
  end
36
36
 
37
37
  it 'is clear about variables from the English library vs those not' do
38
- inspect_source(cop, ['puts $*'])
38
+ inspect_source(cop, 'puts $*')
39
39
  expect(cop.messages)
40
40
  .to eq(['Prefer `$ARGV` from the English library, or `ARGV` over `$*`.'])
41
41
  end
42
42
 
43
43
  it 'does not register an offense for backrefs like $1' do
44
- inspect_source(cop, ['puts $1'])
44
+ inspect_source(cop, 'puts $1')
45
45
  expect(cop.offenses).to be_empty
46
46
  end
47
47
 
@@ -9,7 +9,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
9
9
  let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } }
10
10
 
11
11
  it 'registers an offense for double quotes within embedded expression' do
12
- src = ['"#{"A"}"']
12
+ src = '"#{"A"}"'
13
13
  inspect_source(cop, src)
14
14
  expect(cop.messages)
15
15
  .to eq(['Prefer single-quoted strings inside interpolations.'])
@@ -26,7 +26,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
26
26
  end
27
27
 
28
28
  it 'accepts double quotes on a static string' do
29
- src = ['"A"']
29
+ src = '"A"'
30
30
  inspect_source(cop, src)
31
31
  expect(cop.offenses).to be_empty
32
32
  end
@@ -92,7 +92,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
92
92
  let(:cop_config) { { 'EnforcedStyle' => 'other' } }
93
93
 
94
94
  it 'fails' do
95
- expect { inspect_source(cop, ['a = "#{"b"}"']) }
95
+ expect { inspect_source(cop, 'a = "#{"b"}"') }
96
96
  .to raise_error(RuntimeError)
97
97
  end
98
98
  end
@@ -35,22 +35,22 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
35
35
  end
36
36
 
37
37
  it 'accepts single quotes' do
38
- inspect_source(cop, ["a = 'x'"])
38
+ inspect_source(cop, "a = 'x'")
39
39
  expect(cop.offenses).to be_empty
40
40
  end
41
41
 
42
42
  it 'accepts single quotes in interpolation' do
43
- inspect_source(cop, [%q("hello#{hash['there']}")])
43
+ inspect_source(cop, %q("hello#{hash['there']}"))
44
44
  expect(cop.offenses).to be_empty
45
45
  end
46
46
 
47
47
  it 'accepts %q and %Q quotes' do
48
- inspect_source(cop, ['a = %q(x) + %Q[x]'])
48
+ inspect_source(cop, 'a = %q(x) + %Q[x]')
49
49
  expect(cop.offenses).to be_empty
50
50
  end
51
51
 
52
52
  it 'accepts % quotes' do
53
- inspect_source(cop, ['a = %(x)'])
53
+ inspect_source(cop, 'a = %(x)')
54
54
  expect(cop.offenses).to be_empty
55
55
  end
56
56
 
@@ -77,7 +77,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
77
77
  end
78
78
 
79
79
  it 'accepts double quotes at the start of regexp literals' do
80
- inspect_source(cop, ['s = /"((?:[^\\"]|\\.)*)"/'])
80
+ inspect_source(cop, 's = /"((?:[^\\"]|\\.)*)"/')
81
81
  expect(cop.offenses).to be_empty
82
82
  end
83
83
 
@@ -91,17 +91,17 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
91
91
  end
92
92
 
93
93
  it 'accepts " in a %w' do
94
- inspect_source(cop, ['%w(")'])
94
+ inspect_source(cop, '%w(")')
95
95
  expect(cop.offenses).to be_empty
96
96
  end
97
97
 
98
98
  it 'accepts \\\\\n in a string' do # this would be: "\\\n"
99
- inspect_source(cop, ['"foo \\\\\n bar"'])
99
+ inspect_source(cop, '"foo \\\\\n bar"')
100
100
  expect(cop.offenses).to be_empty
101
101
  end
102
102
 
103
103
  it 'accepts double quotes in interpolation' do
104
- src = ['"#{"A"}"']
104
+ src = '"#{"A"}"'
105
105
  inspect_source(cop, src)
106
106
  expect(cop.offenses).to be_empty
107
107
  end
@@ -137,7 +137,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
137
137
 
138
138
  it 'registers offense for single quotes when double quotes would ' \
139
139
  'be equivalent' do
140
- inspect_source(cop, ["s = 'abc'"])
140
+ inspect_source(cop, "s = 'abc'")
141
141
  expect(cop.highlights).to eq(["'abc'"])
142
142
  expect(cop.messages)
143
143
  .to eq(['Prefer double-quoted strings unless you need ' \
@@ -158,22 +158,22 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
158
158
  end
159
159
 
160
160
  it 'accepts double quotes' do
161
- inspect_source(cop, ['a = "x"'])
161
+ inspect_source(cop, 'a = "x"')
162
162
  expect(cop.offenses).to be_empty
163
163
  end
164
164
 
165
165
  it 'accepts single quotes in interpolation' do
166
- inspect_source(cop, [%q("hello#{hash['there']}")])
166
+ inspect_source(cop, %q("hello#{hash['there']}"))
167
167
  expect(cop.offenses).to be_empty
168
168
  end
169
169
 
170
170
  it 'accepts %q and %Q quotes' do
171
- inspect_source(cop, ['a = %q(x) + %Q[x]'])
171
+ inspect_source(cop, 'a = %q(x) + %Q[x]')
172
172
  expect(cop.offenses).to be_empty
173
173
  end
174
174
 
175
175
  it 'accepts % quotes' do
176
- inspect_source(cop, ['a = %(x)'])
176
+ inspect_source(cop, 'a = %(x)')
177
177
  expect(cop.offenses).to be_empty
178
178
  end
179
179
 
@@ -194,12 +194,12 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
194
194
  end
195
195
 
196
196
  it 'accepts single quotes at the start of regexp literals' do
197
- inspect_source(cop, ["s = /'((?:[^\\']|\\.)*)'/"])
197
+ inspect_source(cop, "s = /'((?:[^\\']|\\.)*)'/")
198
198
  expect(cop.offenses).to be_empty
199
199
  end
200
200
 
201
201
  it "accepts ' in a %w" do
202
- inspect_source(cop, ["%w(')"])
202
+ inspect_source(cop, "%w(')")
203
203
  expect(cop.offenses).to be_empty
204
204
  end
205
205
 
@@ -221,7 +221,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
221
221
  let(:cop_config) { { 'EnforcedStyle' => 'other' } }
222
222
 
223
223
  it 'fails' do
224
- expect { inspect_source(cop, ['a = "b"']) }
224
+ expect { inspect_source(cop, 'a = "b"') }
225
225
  .to raise_error(RuntimeError)
226
226
  end
227
227
  end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RuboCop::Cop::Style::StructInheritance do
6
+ subject(:cop) { described_class.new }
7
+
8
+ it 'registers an offense when extending instance of Struct' do
9
+ inspect_source(cop,
10
+ ['class Person < Struct.new(:first_name, :last_name)',
11
+ 'end'
12
+ ])
13
+ expect(cop.offenses.size).to eq(1)
14
+ end
15
+
16
+ it 'registers an offense when extending instance of Struct' do
17
+ inspect_source(cop,
18
+ ['class Person < Struct.new(:first_name, :last_name) do end',
19
+ 'end'
20
+ ])
21
+ expect(cop.offenses).to be_empty
22
+ end
23
+
24
+ it 'accepts plain class' do
25
+ inspect_source(cop,
26
+ ['class Person',
27
+ 'end'
28
+ ])
29
+ expect(cop.offenses).to be_empty
30
+ end
31
+
32
+ it 'accepts extending DelegateClass' do
33
+ inspect_source(cop,
34
+ ['class Person < DelegateClass(Animal)',
35
+ 'end'
36
+ ])
37
+ expect(cop.offenses).to be_empty
38
+ end
39
+
40
+ it 'accepts assignment to Struct.new' do
41
+ inspect_source(cop, 'Person = Struct.new(:first_name, :last_name)')
42
+ expect(cop.offenses).to be_empty
43
+ end
44
+ end
@@ -5,33 +5,33 @@ require 'spec_helper'
5
5
  describe RuboCop::Cop::Style::SymbolArray do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
- it 'registers an offense for arrays of symbols', ruby: 2.0 do
8
+ it 'registers an offense for arrays of symbols', ruby: 2 do
9
9
  inspect_source(cop,
10
- ['[:one, :two, :three]'])
10
+ '[:one, :two, :three]')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
- it 'does not reg an offense for array with non-syms', ruby: 2.0 do
14
+ it 'does not reg an offense for array with non-syms', ruby: 2 do
15
15
  inspect_source(cop,
16
- ['[:one, :two, "three"]'])
16
+ '[:one, :two, "three"]')
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
 
20
- it 'does not reg an offense for array starting with %i', ruby: 2.0 do
20
+ it 'does not reg an offense for array starting with %i', ruby: 2 do
21
21
  inspect_source(cop,
22
- ['%i(one two three)'])
22
+ '%i(one two three)')
23
23
  expect(cop.offenses).to be_empty
24
24
  end
25
25
 
26
- it 'does not reg an offense for array with one element', ruby: 2.0 do
26
+ it 'does not reg an offense for array with one element', ruby: 2 do
27
27
  inspect_source(cop,
28
- ['[:three]'])
28
+ '[:three]')
29
29
  expect(cop.offenses).to be_empty
30
30
  end
31
31
 
32
32
  it 'does nothing on Ruby 1.9', ruby: 1.9 do
33
33
  inspect_source(cop,
34
- ['[:one, :two, :three]'])
34
+ '[:one, :two, :three]')
35
35
  expect(cop.offenses).to be_empty
36
36
  end
37
37
  end
@@ -16,68 +16,68 @@ describe RuboCop::Cop::Style::SymbolProc, :config do
16
16
  end
17
17
 
18
18
  it 'registers an offense for a block when method in body is unary -/=' do
19
- inspect_source(cop, ['something.map { |x| -x }'])
19
+ inspect_source(cop, 'something.map { |x| -x }')
20
20
  expect(cop.offenses.size).to eq(1)
21
21
  expect(cop.messages)
22
22
  .to eq(['Pass `&:-@` as an argument to `map` instead of a block.'])
23
23
  end
24
24
 
25
25
  it 'accepts method receiving another argument beside the block' do
26
- inspect_source(cop, ['File.open(file) { |f| f.readlines }'])
26
+ inspect_source(cop, 'File.open(file) { |f| f.readlines }')
27
27
 
28
28
  expect(cop.offenses).to be_empty
29
29
  end
30
30
 
31
31
  it 'accepts block with more than 1 arguments' do
32
- inspect_source(cop, ['something { |x, y| x.method }'])
32
+ inspect_source(cop, 'something { |x, y| x.method }')
33
33
 
34
34
  expect(cop.offenses).to be_empty
35
35
  end
36
36
 
37
37
  it 'accepts lambda with 1 argument' do
38
- inspect_source(cop, ['->(x) { x.method }'])
38
+ inspect_source(cop, '->(x) { x.method }')
39
39
 
40
40
  expect(cop.offenses).to be_empty
41
41
  end
42
42
 
43
43
  it 'accepts proc with 1 argument' do
44
- inspect_source(cop, ['proc { |x| x.method }'])
44
+ inspect_source(cop, 'proc { |x| x.method }')
45
45
 
46
46
  expect(cop.offenses).to be_empty
47
47
  end
48
48
 
49
49
  it 'accepts Proc.new with 1 argument' do
50
- inspect_source(cop, ['Proc.new { |x| x.method }'])
50
+ inspect_source(cop, 'Proc.new { |x| x.method }')
51
51
 
52
52
  expect(cop.offenses).to be_empty
53
53
  end
54
54
 
55
55
  it 'accepts ignored method' do
56
- inspect_source(cop, ['respond_to { |format| format.xml }'])
56
+ inspect_source(cop, 'respond_to { |format| format.xml }')
57
57
 
58
58
  expect(cop.offenses).to be_empty
59
59
  end
60
60
 
61
61
  it 'accepts block with no arguments' do
62
- inspect_source(cop, ['something { x.method }'])
62
+ inspect_source(cop, 'something { x.method }')
63
63
 
64
64
  expect(cop.offenses).to be_empty
65
65
  end
66
66
 
67
67
  it 'accepts empty block body' do
68
- inspect_source(cop, ['something { |x| }'])
68
+ inspect_source(cop, 'something { |x| }')
69
69
 
70
70
  expect(cop.offenses).to be_empty
71
71
  end
72
72
 
73
73
  it 'accepts block with more than 1 expression in body' do
74
- inspect_source(cop, ['something { |x| x.method; something_else }'])
74
+ inspect_source(cop, 'something { |x| x.method; something_else }')
75
75
 
76
76
  expect(cop.offenses).to be_empty
77
77
  end
78
78
 
79
79
  it 'accepts block when method in body is not called on block arg' do
80
- inspect_source(cop, ['something { |x| y.method }'])
80
+ inspect_source(cop, 'something { |x| y.method }')
81
81
 
82
82
  expect(cop.offenses).to be_empty
83
83
  end
@@ -94,7 +94,7 @@ describe RuboCop::Cop::Style::SymbolProc, :config do
94
94
  end
95
95
 
96
96
  it 'does not crash with a bare method call' do
97
- run = -> { inspect_source(cop, ['coll.map { |s| bare_method }']) }
97
+ run = -> { inspect_source(cop, 'coll.map { |s| bare_method }') }
98
98
  expect(&run).not_to raise_error
99
99
  end
100
100
  end