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
@@ -6,22 +6,22 @@ describe RuboCop::Cop::Style::Tab do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for a line indented with tab' do
9
- inspect_source(cop, ["\tx = 0"])
9
+ inspect_source(cop, "\tx = 0")
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
13
13
  it 'registers an offense for a line indented with multiple tabs' do
14
- inspect_source(cop, ["\t\t\tx = 0"])
14
+ inspect_source(cop, "\t\t\tx = 0")
15
15
  expect(cop.offenses.size).to eq(1)
16
16
  end
17
17
 
18
18
  it 'registers an offense for a line indented with mixed whitespace' do
19
- inspect_source(cop, [" \tx = 0"])
19
+ inspect_source(cop, " \tx = 0")
20
20
  expect(cop.offenses.size).to eq(1)
21
21
  end
22
22
 
23
23
  it 'accepts a line with tab in a string' do
24
- inspect_source(cop, ["(x = \"\t\")"])
24
+ inspect_source(cop, "(x = \"\t\")")
25
25
  expect(cop.offenses).to be_empty
26
26
  end
27
27
 
@@ -25,7 +25,7 @@ describe RuboCop::Cop::Style::TrailingBlankLines, :config do
25
25
  end
26
26
 
27
27
  it 'registers an offense for no final newline' do
28
- inspect_source(cop, ['x = 0'])
28
+ inspect_source(cop, 'x = 0')
29
29
  expect(cop.messages).to eq(['Final newline missing.'])
30
30
  end
31
31
 
@@ -56,7 +56,7 @@ describe RuboCop::Cop::Style::TrailingBlankLines, :config do
56
56
  end
57
57
 
58
58
  it 'registers an offense for no final newline' do
59
- inspect_source(cop, ['x = 0'])
59
+ inspect_source(cop, 'x = 0')
60
60
  expect(cop.messages).to eq(['Final newline missing.'])
61
61
  end
62
62
 
@@ -6,13 +6,13 @@ describe RuboCop::Cop::Style::TrailingWhitespace do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for a line ending with space' do
9
- source = ['x = 0 ']
9
+ source = 'x = 0 '
10
10
  inspect_source(cop, source)
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'registers an offense for a line ending with tab' do
15
- inspect_source(cop, ["x = 0\t"])
15
+ inspect_source(cop, "x = 0\t")
16
16
  expect(cop.offenses.size).to eq(1)
17
17
  end
18
18
 
@@ -453,6 +453,20 @@ describe RuboCop::Cop::Style::TrivialAccessors, :config do
453
453
  end
454
454
  end
455
455
 
456
+ context 'non-matching reader' do
457
+ let(:source) do
458
+ ['def foo',
459
+ ' @bar',
460
+ 'end']
461
+ end
462
+
463
+ it 'does not autocorrect' do
464
+ expect(autocorrect_source(cop, source))
465
+ .to eq(source.join("\n"))
466
+ expect(cop.offenses.map(&:corrected?)).to eq [false]
467
+ end
468
+ end
469
+
456
470
  context 'matching non-DSL writer' do
457
471
  let(:source) do
458
472
  ['def foo=(f)',
@@ -477,6 +491,7 @@ describe RuboCop::Cop::Style::TrivialAccessors, :config do
477
491
  it 'does not autocorrect' do
478
492
  expect(autocorrect_source(cop, source))
479
493
  .to eq(source.join("\n"))
494
+ expect(cop.offenses.map(&:corrected?)).to eq [false]
480
495
  end
481
496
  end
482
497
 
@@ -490,6 +505,7 @@ describe RuboCop::Cop::Style::TrivialAccessors, :config do
490
505
  it 'does not autocorrect' do
491
506
  expect(autocorrect_source(cop, source))
492
507
  .to eq(source.join("\n"))
508
+ expect(cop.offenses.map(&:corrected?)).to eq [false]
493
509
  end
494
510
  end
495
511
 
@@ -6,26 +6,22 @@ describe RuboCop::Cop::Style::UnneededCapitalW do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers no offense for normal arrays of strings' do
9
- inspect_source(cop,
10
- ['["one", "two", "three"]'])
9
+ inspect_source(cop, '["one", "two", "three"]')
11
10
  expect(cop.offenses).to be_empty
12
11
  end
13
12
 
14
13
  it 'registers no offense for normal arrays of strings with interpolation' do
15
- inspect_source(cop,
16
- ['["one", "two", "th#{ ?r }ee"]'])
14
+ inspect_source(cop, '["one", "two", "th#{ ?r }ee"]')
17
15
  expect(cop.offenses).to be_empty
18
16
  end
19
17
 
20
18
  it 'registers an offense for misused %W' do
21
- inspect_source(cop,
22
- ['%W(cat dog)'])
19
+ inspect_source(cop, '%W(cat dog)')
23
20
  expect(cop.offenses.size).to eq(1)
24
21
  end
25
22
 
26
23
  it 'registers no offense for %W with interpolation' do
27
- inspect_source(cop,
28
- ['%W(c#{ ?a }t dog)'])
24
+ inspect_source(cop, '%W(c#{ ?a }t dog)')
29
25
  expect(cop.offenses).to be_empty
30
26
  end
31
27
 
@@ -48,44 +44,37 @@ describe RuboCop::Cop::Style::UnneededCapitalW do
48
44
  end
49
45
 
50
46
  it 'registers no offense for %w without interpolation' do
51
- inspect_source(cop,
52
- ['%w(cat dog)'])
47
+ inspect_source(cop, '%w(cat dog)')
53
48
  expect(cop.offenses).to be_empty
54
49
  end
55
50
 
56
51
  it 'registers no offense for %w with interpolation-like syntax' do
57
- inspect_source(cop,
58
- ['%w(c#{ ?a }t dog)'])
52
+ inspect_source(cop, '%w(c#{ ?a }t dog)')
59
53
  expect(cop.offenses).to be_empty
60
54
  end
61
55
 
62
56
  it 'registers no offense for arrays with character constants' do
63
- inspect_source(cop,
64
- ['["one", ?\n]'])
57
+ inspect_source(cop, '["one", ?\n]')
65
58
  expect(cop.offenses).to be_empty
66
59
  end
67
60
 
68
61
  it 'does not register an offense for array of non-words' do
69
- inspect_source(cop,
70
- ['["one space", "two", "three"]'])
62
+ inspect_source(cop, '["one space", "two", "three"]')
71
63
  expect(cop.offenses).to be_empty
72
64
  end
73
65
 
74
66
  it 'does not register an offense for array containing non-string' do
75
- inspect_source(cop,
76
- ['["one", "two", 3]'])
67
+ inspect_source(cop, '["one", "two", 3]')
77
68
  expect(cop.offenses).to be_empty
78
69
  end
79
70
 
80
71
  it 'does not register an offense for array with one element' do
81
- inspect_source(cop,
82
- ['["three"]'])
72
+ inspect_source(cop, '["three"]')
83
73
  expect(cop.offenses).to be_empty
84
74
  end
85
75
 
86
76
  it 'does not register an offense for array with empty strings' do
87
- inspect_source(cop,
88
- ['["", "two", "three"]'])
77
+ inspect_source(cop, '["", "two", "three"]')
89
78
  expect(cop.offenses).to be_empty
90
79
  end
91
80
 
@@ -7,7 +7,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
7
7
 
8
8
  it 'registers an offense for interpolated global variables in string' do
9
9
  inspect_source(cop,
10
- ['puts "this is a #$test"'])
10
+ 'puts "this is a #$test"')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  expect(cop.highlights).to eq(['$test'])
13
13
  expect(cop.messages)
@@ -17,7 +17,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
17
17
 
18
18
  it 'registers an offense for interpolated global variables in regexp' do
19
19
  inspect_source(cop,
20
- ['puts /this is a #$test/'])
20
+ 'puts /this is a #$test/')
21
21
  expect(cop.offenses.size).to eq(1)
22
22
  expect(cop.highlights).to eq(['$test'])
23
23
  expect(cop.messages)
@@ -27,7 +27,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
27
27
 
28
28
  it 'registers an offense for interpolated global variables in regexp' do
29
29
  inspect_source(cop,
30
- ['puts `this is a #$test`'])
30
+ 'puts `this is a #$test`')
31
31
  expect(cop.offenses.size).to eq(1)
32
32
  expect(cop.highlights).to eq(['$test'])
33
33
  expect(cop.messages)
@@ -37,7 +37,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
37
37
 
38
38
  it 'registers an offense for interpolated regexp back references' do
39
39
  inspect_source(cop,
40
- ['puts "this is a #$1"'])
40
+ 'puts "this is a #$1"')
41
41
  expect(cop.offenses.size).to eq(1)
42
42
  expect(cop.highlights).to eq(['$1'])
43
43
  expect(cop.messages)
@@ -46,7 +46,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
46
46
 
47
47
  it 'registers an offense for interpolated instance variables' do
48
48
  inspect_source(cop,
49
- ['puts "this is a #@test"'])
49
+ 'puts "this is a #@test"')
50
50
  expect(cop.offenses.size).to eq(1)
51
51
  expect(cop.highlights).to eq(['@test'])
52
52
  expect(cop.messages)
@@ -56,7 +56,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
56
56
 
57
57
  it 'registers an offense for interpolated class variables' do
58
58
  inspect_source(cop,
59
- ['puts "this is a #@@t"'])
59
+ 'puts "this is a #@@t"')
60
60
  expect(cop.offenses.size).to eq(1)
61
61
  expect(cop.highlights).to eq(['@@t'])
62
62
  expect(cop.messages)
@@ -65,7 +65,7 @@ describe RuboCop::Cop::Style::VariableInterpolation do
65
65
 
66
66
  it 'does not register an offense for variables in expressions' do
67
67
  inspect_source(cop,
68
- ['puts "this is a #{@test} #{@@t} #{$t} #{$1}"'])
68
+ 'puts "this is a #{@test} #{@@t} #{$t} #{$1}"')
69
69
  expect(cop.offenses).to be_empty
70
70
  end
71
71
 
@@ -18,12 +18,12 @@ describe RuboCop::Cop::Style::WhileUntilDo do
18
18
  end
19
19
 
20
20
  it 'accepts do in single-line while' do
21
- inspect_source(cop, ['while cond do something end'])
21
+ inspect_source(cop, 'while cond do something end')
22
22
  expect(cop.offenses).to be_empty
23
23
  end
24
24
 
25
25
  it 'accepts do in single-line until' do
26
- inspect_source(cop, ['until cond do something end'])
26
+ inspect_source(cop, 'until cond do something end')
27
27
  expect(cop.offenses).to be_empty
28
28
  end
29
29
 
@@ -64,12 +64,12 @@ describe RuboCop::Cop::Style::WhileUntilModifier do
64
64
  end
65
65
 
66
66
  it 'accepts modifier while' do
67
- inspect_source(cop, ['ala while bala'])
67
+ inspect_source(cop, 'ala while bala')
68
68
  expect(cop.offenses).to be_empty
69
69
  end
70
70
 
71
71
  it 'accepts modifier until' do
72
- inspect_source(cop, ['ala until bala'])
72
+ inspect_source(cop, 'ala until bala')
73
73
  expect(cop.offenses).to be_empty
74
74
  end
75
75
 
@@ -8,56 +8,56 @@ describe RuboCop::Cop::Style::WordArray, :config do
8
8
 
9
9
  it 'registers an offense for arrays of single quoted strings' do
10
10
  inspect_source(cop,
11
- ["['one', 'two', 'three']"])
11
+ "['one', 'two', 'three']")
12
12
  expect(cop.offenses.size).to eq(1)
13
13
  expect(cop.config_to_allow_offenses).to eq('MinSize' => 3)
14
14
  end
15
15
 
16
16
  it 'registers an offense for arrays of double quoted strings' do
17
17
  inspect_source(cop,
18
- ['["one", "two", "three"]'])
18
+ '["one", "two", "three"]')
19
19
  expect(cop.offenses.size).to eq(1)
20
20
  end
21
21
 
22
22
  it 'registers an offense for arrays of unicode word characters' do
23
23
  inspect_source(cop,
24
- ['["ВУЗ", "вуз", "中文网"]'])
24
+ '["ВУЗ", "вуз", "中文网"]')
25
25
  expect(cop.offenses.size).to eq(1)
26
26
  end
27
27
 
28
28
  it 'registers an offense for arrays with character constants' do
29
29
  inspect_source(cop,
30
- ['["one", ?\n]'])
30
+ '["one", ?\n]')
31
31
  expect(cop.offenses.size).to eq(1)
32
32
  end
33
33
 
34
34
  it 'does not register an offense for array of non-words' do
35
35
  inspect_source(cop,
36
- ['["one space", "two", "three"]'])
36
+ '["one space", "two", "three"]')
37
37
  expect(cop.offenses).to be_empty
38
38
  end
39
39
 
40
40
  it 'does not register an offense for array containing non-string' do
41
41
  inspect_source(cop,
42
- ['["one", "two", 3]'])
42
+ '["one", "two", 3]')
43
43
  expect(cop.offenses).to be_empty
44
44
  end
45
45
 
46
46
  it 'does not register an offense for array starting with %w' do
47
47
  inspect_source(cop,
48
- ['%w(one two three)'])
48
+ '%w(one two three)')
49
49
  expect(cop.offenses).to be_empty
50
50
  end
51
51
 
52
52
  it 'does not register an offense for array with one element' do
53
53
  inspect_source(cop,
54
- ['["three"]'])
54
+ '["three"]')
55
55
  expect(cop.offenses).to be_empty
56
56
  end
57
57
 
58
58
  it 'does not register an offense for array with empty strings' do
59
59
  inspect_source(cop,
60
- ['["", "two", "three"]'])
60
+ '["", "two", "three"]')
61
61
  expect(cop.offenses).to be_empty
62
62
  end
63
63
 
@@ -65,7 +65,7 @@ describe RuboCop::Cop::Style::WordArray, :config do
65
65
  cop_config['MinSize'] = 3
66
66
 
67
67
  inspect_source(cop,
68
- ['["one", "two", "three"]'])
68
+ '["one", "two", "three"]')
69
69
  expect(cop.offenses).to be_empty
70
70
  end
71
71
 
@@ -105,7 +105,7 @@ describe RuboCop::Cop::Style::WordArray, :config do
105
105
  let(:cop_config) { { 'MinSize' => 0, 'WordRegex' => /\A[\w@.]+\z/ } }
106
106
 
107
107
  it 'registers an offense for arrays of email addresses' do
108
- inspect_source(cop, ["['a@example.com', 'b@example.com']"])
108
+ inspect_source(cop, "['a@example.com', 'b@example.com']")
109
109
  expect(cop.offenses.size).to eq(1)
110
110
  end
111
111
 
@@ -39,6 +39,57 @@ describe RuboCop::Cop::Util do
39
39
  end
40
40
  end
41
41
 
42
+ describe 'source indicated by #range_with_surrounding_comma' do
43
+ let(:input_range) { OpenStruct.new(begin_pos: 7, end_pos: 12) }
44
+ let(:buffer) { OpenStruct.new(source: 'raise ,Error,') }
45
+
46
+ subject do
47
+ r = described_class.range_with_surrounding_comma(input_range,
48
+ side, buffer)
49
+ buffer.source[r.begin_pos...r.end_pos]
50
+ end
51
+
52
+ context 'when side is :both' do
53
+ let(:side) { :both }
54
+ it { should eq(',Error,') }
55
+ end
56
+
57
+ context 'when side is :left' do
58
+ let(:side) { :left }
59
+ it { should eq(',Error') }
60
+ end
61
+
62
+ context 'when side is :right' do
63
+ let(:side) { :right }
64
+ it { should eq('Error,') }
65
+ end
66
+ end
67
+
68
+ describe 'source indicated by #range_with_surrounding_space' do
69
+ let(:input_range) { OpenStruct.new(begin_pos: 5, end_pos: 9) }
70
+ let(:buffer) { OpenStruct.new(source: 'f { a(2) }') }
71
+ subject do
72
+ r = described_class.range_with_surrounding_space(input_range, side,
73
+ buffer)
74
+ buffer.source[r.begin_pos...r.end_pos]
75
+ end
76
+
77
+ context 'when side is :both' do
78
+ let(:side) { :both }
79
+ it { should eq(' a(2) ') }
80
+ end
81
+
82
+ context 'when side is :left' do
83
+ let(:side) { :left }
84
+ it { should eq(' a(2)') }
85
+ end
86
+
87
+ context 'when side is :right' do
88
+ let(:side) { :right }
89
+ it { should eq('a(2) ') }
90
+ end
91
+ end
92
+
42
93
  # Test compatibility with Range#size in Ruby 2.0.
43
94
  describe '#numeric_range_size', ruby: 2 do
44
95
  [1..1, 1...1, 1..2, 1...2, 1..3, 1...3, 1..-1, 1...-1].each do |range|
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'astrolabe/sexp'
5
+
6
+ describe RuboCop::Cop::VariableForce::Reference do
7
+ include Astrolabe::Sexp
8
+
9
+ describe '.new' do
10
+ context 'when non variable reference node is passed' do
11
+ it 'raises error' do
12
+ node = s(:def)
13
+ scope = RuboCop::Cop::VariableForce::Scope.new(s(:class))
14
+ expect { described_class.new(node, scope) }
15
+ .to raise_error(ArgumentError)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -209,6 +209,13 @@ describe RuboCop::Cop::VariableForce::VariableTable do
209
209
  end
210
210
  end
211
211
 
212
+ describe '#find_variable with an empty scope stack' do
213
+ it 'returns nil' do
214
+ found_variable = variable_table.find_variable(:unknown)
215
+ expect(found_variable).to be_nil
216
+ end
217
+ end
218
+
212
219
  describe '#accessible_variables' do
213
220
  let(:accessible_variable_names) do
214
221
  variable_table.accessible_variables.map(&:name)