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,7 +6,7 @@ describe RuboCop::Cop::Style::CaseEquality do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for ===' do
9
- inspect_source(cop, ['Array === var'])
9
+ inspect_source(cop, 'Array === var')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  expect(cop.highlights).to eq(['==='])
12
12
  end
@@ -6,22 +6,22 @@ describe RuboCop::Cop::Style::CharacterLiteral do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for character literals' do
9
- inspect_source(cop, ['x = ?x'])
9
+ inspect_source(cop, 'x = ?x')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
13
13
  it 'registers an offense for literals like \n' do
14
- inspect_source(cop, ['x = ?\n'])
14
+ inspect_source(cop, 'x = ?\n')
15
15
  expect(cop.offenses.size).to eq(1)
16
16
  end
17
17
 
18
18
  it 'accepts literals like ?\C-\M-d' do
19
- inspect_source(cop, ['x = ?\C-\M-d'])
19
+ inspect_source(cop, 'x = ?\C-\M-d')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
23
23
  it 'accepts ? in a %w literal' do
24
- inspect_source(cop, ['%w{? A}'])
24
+ inspect_source(cop, '%w{? A}')
25
25
  expect(cop.offenses).to be_empty
26
26
  end
27
27
 
@@ -9,7 +9,8 @@ describe RuboCop::Cop::Style::ClassAndModuleChildren, :config do
9
9
  let(:cop_config) { { 'EnforcedStyle' => 'nested' } }
10
10
 
11
11
  it 'registers an offense for not nested classes' do
12
- inspect_source(cop, ['class FooClass::BarClass', 'end'])
12
+ inspect_source(cop, ['class FooClass::BarClass',
13
+ 'end'])
13
14
 
14
15
  expect(cop.offenses.size).to eq 1
15
16
  expect(cop.messages).to eq [
@@ -19,7 +20,8 @@ describe RuboCop::Cop::Style::ClassAndModuleChildren, :config do
19
20
  end
20
21
 
21
22
  it 'registers an offense for not nested modules' do
22
- inspect_source(cop, ['module FooModule::BarModule', 'end'])
23
+ inspect_source(cop, ['module FooModule::BarModule',
24
+ 'end'])
23
25
 
24
26
  expect(cop.offenses.size).to eq 1
25
27
  expect(cop.messages).to eq [
@@ -41,6 +41,18 @@ describe RuboCop::Cop::Style::ClassMethods do
41
41
  expect(cop.offenses).to be_empty
42
42
  end
43
43
 
44
+ it 'does not register an offense for other top-level singleton methods' do
45
+ inspect_source(cop,
46
+ ['class Test',
47
+ ' X = Something.new',
48
+ '',
49
+ ' def X.some_method',
50
+ ' do_something',
51
+ ' end',
52
+ 'end'])
53
+ expect(cop.offenses).to be_empty
54
+ end
55
+
44
56
  it 'does not register an offense outside class/module bodies' do
45
57
  inspect_source(cop,
46
58
  ['def Test.some_method',
@@ -6,14 +6,14 @@ describe RuboCop::Cop::Style::ClassVars do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for class variable declaration' do
9
- inspect_source(cop, ['class TestClass; @@test = 10; end'])
9
+ inspect_source(cop, 'class TestClass; @@test = 10; end')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  expect(cop.messages)
12
12
  .to eq(['Replace class var @@test with a class instance var.'])
13
13
  end
14
14
 
15
15
  it 'does not register an offense for class variable usage' do
16
- inspect_source(cop, ['@@test.test(20)'])
16
+ inspect_source(cop, '@@test.test(20)')
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
  end
@@ -17,26 +17,26 @@ describe RuboCop::Cop::Style::CollectionMethods, :config do
17
17
 
18
18
  cop_config['PreferredMethods'].each do |method, preferred_method|
19
19
  it "registers an offense for #{method} with block" do
20
- inspect_source(cop, ["[1, 2, 3].#{method} { |e| e + 1 }"])
20
+ inspect_source(cop, "[1, 2, 3].#{method} { |e| e + 1 }")
21
21
  expect(cop.offenses.size).to eq(1)
22
22
  expect(cop.messages)
23
23
  .to eq(["Prefer `#{preferred_method}` over `#{method}`."])
24
24
  end
25
25
 
26
26
  it "registers an offense for #{method} with proc param" do
27
- inspect_source(cop, ["[1, 2, 3].#{method}(&:test)"])
27
+ inspect_source(cop, "[1, 2, 3].#{method}(&:test)")
28
28
  expect(cop.offenses.size).to eq(1)
29
29
  expect(cop.messages)
30
30
  .to eq(["Prefer `#{preferred_method}` over `#{method}`."])
31
31
  end
32
32
 
33
33
  it "accepts #{method} with more than 1 param" do
34
- inspect_source(cop, ["[1, 2, 3].#{method}(other, &:test)"])
34
+ inspect_source(cop, "[1, 2, 3].#{method}(other, &:test)")
35
35
  expect(cop.offenses).to be_empty
36
36
  end
37
37
 
38
38
  it "accepts #{method} without a block" do
39
- inspect_source(cop, ["[1, 2, 3].#{method}"])
39
+ inspect_source(cop, "[1, 2, 3].#{method}")
40
40
  expect(cop.offenses).to be_empty
41
41
  end
42
42
 
@@ -7,49 +7,49 @@ describe RuboCop::Cop::Style::ColonMethodCall do
7
7
 
8
8
  it 'registers an offense for instance method call' do
9
9
  inspect_source(cop,
10
- ['test::method_name'])
10
+ 'test::method_name')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'registers an offense for instance method call with arg' do
15
15
  inspect_source(cop,
16
- ['test::method_name(arg)'])
16
+ 'test::method_name(arg)')
17
17
  expect(cop.offenses.size).to eq(1)
18
18
  end
19
19
 
20
20
  it 'registers an offense for class method call' do
21
21
  inspect_source(cop,
22
- ['Class::method_name'])
22
+ 'Class::method_name')
23
23
  expect(cop.offenses.size).to eq(1)
24
24
  end
25
25
 
26
26
  it 'registers an offense for class method call with arg' do
27
27
  inspect_source(cop,
28
- ['Class::method_name(arg, arg2)'])
28
+ 'Class::method_name(arg, arg2)')
29
29
  expect(cop.offenses.size).to eq(1)
30
30
  end
31
31
 
32
32
  it 'does not register an offense for constant access' do
33
33
  inspect_source(cop,
34
- ['Tip::Top::SOME_CONST'])
34
+ 'Tip::Top::SOME_CONST')
35
35
  expect(cop.offenses).to be_empty
36
36
  end
37
37
 
38
38
  it 'does not register an offense for nested class' do
39
39
  inspect_source(cop,
40
- ['Tip::Top.some_method'])
40
+ 'Tip::Top.some_method')
41
41
  expect(cop.offenses).to be_empty
42
42
  end
43
43
 
44
44
  it 'does not register an offense for op methods' do
45
45
  inspect_source(cop,
46
- ['Tip::Top.some_method[3]'])
46
+ 'Tip::Top.some_method[3]')
47
47
  expect(cop.offenses).to be_empty
48
48
  end
49
49
 
50
50
  it 'does not register an offense when for constructor methods' do
51
51
  inspect_source(cop,
52
- ['Tip::Top(some_arg)'])
52
+ 'Tip::Top(some_arg)')
53
53
  expect(cop.offenses).to be_empty
54
54
  end
55
55
 
@@ -9,7 +9,7 @@ describe RuboCop::Cop::Style::CommentAnnotation, :config do
9
9
  end
10
10
 
11
11
  it 'registers an offense for a missing colon' do
12
- inspect_source(cop, ['# TODO make better'])
12
+ inspect_source(cop, '# TODO make better')
13
13
  expect(cop.offenses.size).to eq(1)
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ describe RuboCop::Cop::Style::CommentAnnotation, :config do
17
17
  let(:cop_config) { { 'Keywords' => %w(ISSUE) } }
18
18
 
19
19
  it 'registers an offense for a missing colon after the word' do
20
- inspect_source(cop, ['# ISSUE wrong order'])
20
+ inspect_source(cop, '# ISSUE wrong order')
21
21
  expect(cop.offenses.size).to eq(1)
22
22
  end
23
23
  end
@@ -27,7 +27,7 @@ describe RuboCop::Cop::Style::CommentAnnotation, :config do
27
27
  let(:output) { StringIO.new }
28
28
 
29
29
  it 'marks the annotation keyword' do
30
- inspect_source(cop, ['# TODO:make better'])
30
+ inspect_source(cop, '# TODO:make better')
31
31
  formatter.report_file('t', cop.offenses)
32
32
  expect(output.string).to eq(["t:1:3: C: #{described_class::MSG}",
33
33
  '# TODO:make better',
@@ -37,32 +37,32 @@ describe RuboCop::Cop::Style::CommentAnnotation, :config do
37
37
  end
38
38
 
39
39
  it 'registers an offense for lower case' do
40
- inspect_source(cop, ['# fixme: does not work'])
40
+ inspect_source(cop, '# fixme: does not work')
41
41
  expect(cop.offenses.size).to eq(1)
42
42
  end
43
43
 
44
44
  it 'registers an offense for capitalized annotation keyword' do
45
- inspect_source(cop, ['# Optimize: does not work'])
45
+ inspect_source(cop, '# Optimize: does not work')
46
46
  expect(cop.offenses.size).to eq(1)
47
47
  end
48
48
 
49
49
  it 'registers an offense for upper case with colon but no note' do
50
- inspect_source(cop, ['# HACK:'])
50
+ inspect_source(cop, '# HACK:')
51
51
  expect(cop.offenses.size).to eq(1)
52
52
  end
53
53
 
54
54
  it 'accepts upper case keyword with colon, space and note' do
55
- inspect_source(cop, ['# REVIEW: not sure about this'])
55
+ inspect_source(cop, '# REVIEW: not sure about this')
56
56
  expect(cop.offenses).to be_empty
57
57
  end
58
58
 
59
59
  it 'accepts upper case keyword alone' do
60
- inspect_source(cop, ['# OPTIMIZE'])
60
+ inspect_source(cop, '# OPTIMIZE')
61
61
  expect(cop.offenses).to be_empty
62
62
  end
63
63
 
64
64
  it 'accepts a comment that is obviously a code example' do
65
- inspect_source(cop, ['# Todo.destroy(1)'])
65
+ inspect_source(cop, '# Todo.destroy(1)')
66
66
  expect(cop.offenses).to be_empty
67
67
  end
68
68
 
@@ -79,7 +79,7 @@ describe RuboCop::Cop::Style::CommentAnnotation, :config do
79
79
  end
80
80
 
81
81
  it 'accepts the word without colon' do
82
- inspect_source(cop, ['# TODO make better'])
82
+ inspect_source(cop, '# TODO make better')
83
83
  expect(cop.offenses).to be_empty
84
84
  end
85
85
  end
@@ -7,37 +7,37 @@ describe RuboCop::Cop::Style::ConstantName do
7
7
 
8
8
  it 'registers an offense for camel case in const name' do
9
9
  inspect_source(cop,
10
- ['TopCase = 5'])
10
+ 'TopCase = 5')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'registers offenses for camel case in multiple const assignment' do
15
15
  inspect_source(cop,
16
- ['TopCase, Test2, TEST_3 = 5, 6, 7'])
16
+ 'TopCase, Test2, TEST_3 = 5, 6, 7')
17
17
  expect(cop.offenses.size).to eq(2)
18
18
  end
19
19
 
20
20
  it 'registers an offense for snake case in const name' do
21
21
  inspect_source(cop,
22
- ['TOP_test = 5'])
22
+ 'TOP_test = 5')
23
23
  expect(cop.offenses.size).to eq(1)
24
24
  end
25
25
 
26
26
  it 'allows screaming snake case in const name' do
27
27
  inspect_source(cop,
28
- ['TOP_TEST = 5'])
28
+ 'TOP_TEST = 5')
29
29
  expect(cop.offenses).to be_empty
30
30
  end
31
31
 
32
32
  it 'allows screaming snake case in multiple const assignment' do
33
33
  inspect_source(cop,
34
- ['TOP_TEST, TEST_2 = 5, 6'])
34
+ 'TOP_TEST, TEST_2 = 5, 6')
35
35
  expect(cop.offenses).to be_empty
36
36
  end
37
37
 
38
38
  it 'does not check names if rhs is a method call' do
39
39
  inspect_source(cop,
40
- ['AnythingGoes = test'])
40
+ 'AnythingGoes = test')
41
41
  expect(cop.offenses).to be_empty
42
42
  end
43
43
 
@@ -52,7 +52,7 @@ describe RuboCop::Cop::Style::ConstantName do
52
52
 
53
53
  it 'does not check if rhs is another constant' do
54
54
  inspect_source(cop,
55
- ['Parser::CurrentRuby = Parser::Ruby20'])
55
+ 'Parser::CurrentRuby = Parser::Ruby20')
56
56
  expect(cop.offenses).to be_empty
57
57
  end
58
58
 
@@ -27,7 +27,7 @@ describe RuboCop::Cop::Style::DefWithParentheses do
27
27
  end
28
28
 
29
29
  it 'accepts empty parentheses in one liners' do
30
- src = ["def to_s() join '/' end"]
30
+ src = "def to_s() join '/' end"
31
31
  inspect_source(cop, src)
32
32
  expect(cop.offenses).to be_empty
33
33
  end
@@ -7,7 +7,7 @@ describe RuboCop::Cop::Style::DeprecatedHashMethods do
7
7
 
8
8
  it 'registers an offense for has_key? with one arg' do
9
9
  inspect_source(cop,
10
- ['o.has_key?(o)'])
10
+ 'o.has_key?(o)')
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  expect(cop.messages)
13
13
  .to eq(['`Hash#has_key?` is deprecated in favor of `Hash#key?`.'])
@@ -15,13 +15,13 @@ describe RuboCop::Cop::Style::DeprecatedHashMethods do
15
15
 
16
16
  it 'accepts has_key? with no args' do
17
17
  inspect_source(cop,
18
- ['o.has_key?'])
18
+ 'o.has_key?')
19
19
  expect(cop.offenses).to be_empty
20
20
  end
21
21
 
22
22
  it 'registers an offense for has_value? with one arg' do
23
23
  inspect_source(cop,
24
- ['o.has_value?(o)'])
24
+ 'o.has_value?(o)')
25
25
  expect(cop.offenses.size).to eq(1)
26
26
  expect(cop.messages)
27
27
  .to eq(['`Hash#has_value?` is deprecated in favor of `Hash#value?`.'])
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Style::DeprecatedHashMethods do
29
29
 
30
30
  it 'accepts has_value? with no args' do
31
31
  inspect_source(cop,
32
- ['o.has_value?'])
32
+ 'o.has_value?')
33
33
  expect(cop.offenses).to be_empty
34
34
  end
35
35
 
@@ -32,17 +32,18 @@ describe RuboCop::Cop::Style::DotPosition, :config do
32
32
  end
33
33
 
34
34
  it 'does not err on method call with no dots' do
35
- inspect_source(cop, ['puts something'])
35
+ inspect_source(cop, 'puts something')
36
36
  expect(cop.offenses).to be_empty
37
37
  end
38
38
 
39
39
  it 'does not err on method call without a method name' do
40
- inspect_source(cop, ['l.', '(1)'])
40
+ inspect_source(cop, ['l.',
41
+ '(1)'])
41
42
  expect(cop.offenses.size).to eq(1)
42
43
  end
43
44
 
44
45
  it 'does not err on method call on same line' do
45
- inspect_source(cop, ['something.method_name'])
46
+ inspect_source(cop, 'something.method_name')
46
47
  expect(cop.offenses).to be_empty
47
48
  end
48
49
 
@@ -92,17 +93,18 @@ describe RuboCop::Cop::Style::DotPosition, :config do
92
93
  end
93
94
 
94
95
  it 'does not err on method call with no dots' do
95
- inspect_source(cop, ['puts something'])
96
+ inspect_source(cop, 'puts something')
96
97
  expect(cop.offenses).to be_empty
97
98
  end
98
99
 
99
100
  it 'does not err on method call without a method name' do
100
- inspect_source(cop, ['l', '.(1)'])
101
+ inspect_source(cop, ['l',
102
+ '.(1)'])
101
103
  expect(cop.offenses.size).to eq(1)
102
104
  end
103
105
 
104
106
  it 'does not err on method call on same line' do
105
- inspect_source(cop, ['something.method_name'])
107
+ inspect_source(cop, 'something.method_name')
106
108
  expect(cop.offenses).to be_empty
107
109
  end
108
110
 
@@ -62,12 +62,12 @@ describe RuboCop::Cop::Style::EachWithObject do
62
62
  end
63
63
 
64
64
  it 'ignores inject and reduce passed in symbol' do
65
- inspect_source(cop, ['[].inject(:+)', '[].reduce(:+)'])
65
+ inspect_source(cop, '[].inject(:+)', '[].reduce(:+)')
66
66
  expect(cop.offenses).to be_empty
67
67
  end
68
68
 
69
69
  it 'does not blow up for reduce with no arguments' do
70
- inspect_source(cop, ['[1, 2, 3].inject { |a, e| a + e }'])
70
+ inspect_source(cop, '[1, 2, 3].inject { |a, e| a + e }')
71
71
  expect(cop.offenses).to be_empty
72
72
  end
73
73
  end
@@ -12,8 +12,7 @@ describe RuboCop::Cop::Style::ElseAlignment do
12
12
  end
13
13
 
14
14
  it 'accepts a ternary if' do
15
- inspect_source(cop,
16
- ['cond ? func1 : func2'])
15
+ inspect_source(cop, 'cond ? func1 : func2')
17
16
  expect(cop.offenses).to be_empty
18
17
  end
19
18
 
@@ -64,8 +63,7 @@ describe RuboCop::Cop::Style::ElseAlignment do
64
63
  end
65
64
 
66
65
  it 'accepts a one line if statement' do
67
- inspect_source(cop,
68
- ['if cond then func1 else func2 end'])
66
+ inspect_source(cop, 'if cond then func1 else func2 end')
69
67
  expect(cop.offenses).to be_empty
70
68
  end
71
69
 
@@ -32,6 +32,38 @@ describe RuboCop::Cop::Style::EmptyLinesAroundAccessModifier do
32
32
  .to eq(["Keep a blank line before and after `#{access_modifier}`."])
33
33
  end
34
34
 
35
+ it "ignores #{access_modifier} inside a method call" do
36
+ inspect_source(cop,
37
+ ['class Test',
38
+ ' def #{access_modifier}?',
39
+ " #{access_modifier}",
40
+ ' end',
41
+ 'end'])
42
+ expect(cop.offenses.size).to eq(0)
43
+ end
44
+
45
+ it "ignores #{access_modifier} deep inside a method call" do
46
+ inspect_source(cop,
47
+ ['class Test',
48
+ " def #{access_modifier}?",
49
+ ' if true',
50
+ " #{access_modifier}",
51
+ ' end',
52
+ ' end',
53
+ 'end'])
54
+ expect(cop.offenses.size).to eq(0)
55
+ end
56
+
57
+ it "ignores #{access_modifier} with a right-hand-side condition" do
58
+ inspect_source(cop,
59
+ ['class Test',
60
+ " def #{access_modifier}?",
61
+ " #{access_modifier} if true",
62
+ ' end',
63
+ 'end'])
64
+ expect(cop.offenses.size).to eq(0)
65
+ end
66
+
35
67
  it "autocorrects blank line before #{access_modifier}" do
36
68
  corrected = autocorrect_source(cop,
37
69
  ['class Test',
@@ -76,6 +108,52 @@ describe RuboCop::Cop::Style::EmptyLinesAroundAccessModifier do
76
108
  expect(cop.offenses).to be_empty
77
109
  end
78
110
 
111
+ context 'at the beginning of block' do
112
+ context 'for blocks defined with do' do
113
+ it 'accepts missing blank line' do
114
+ inspect_source(cop,
115
+ ['included do',
116
+ " #{access_modifier}",
117
+ '',
118
+ ' def test; end',
119
+ 'end'])
120
+ expect(cop.offenses).to be_empty
121
+ end
122
+
123
+ it 'accepts missing blank line with arguments' do
124
+ inspect_source(cop,
125
+ ['included do |foo|',
126
+ " #{access_modifier}",
127
+ '',
128
+ ' def test; end',
129
+ 'end'])
130
+ expect(cop.offenses).to be_empty
131
+ end
132
+ end
133
+
134
+ context 'for blocks defined with {}' do
135
+ it 'accepts missing blank line' do
136
+ inspect_source(cop,
137
+ ['included {',
138
+ " #{access_modifier}",
139
+ '',
140
+ ' def test; end',
141
+ '}'])
142
+ expect(cop.offenses).to be_empty
143
+ end
144
+
145
+ it 'accepts missing blank line with arguments' do
146
+ inspect_source(cop,
147
+ ['included { |foo|',
148
+ " #{access_modifier}",
149
+ '',
150
+ ' def test; end',
151
+ '}'])
152
+ expect(cop.offenses).to be_empty
153
+ end
154
+ end
155
+ end
156
+
79
157
  it 'accepts missing blank line when at the end of block' do
80
158
  inspect_source(cop,
81
159
  ['class Test',