rubocop 0.28.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +7 -7
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +59 -0
  5. data/README.md +62 -28
  6. data/config/default.yml +31 -0
  7. data/config/disabled.yml +1 -1
  8. data/config/enabled.yml +17 -0
  9. data/lib/rubocop.rb +4 -0
  10. data/lib/rubocop/cli.rb +1 -1
  11. data/lib/rubocop/config.rb +12 -8
  12. data/lib/rubocop/config_loader.rb +20 -10
  13. data/lib/rubocop/cop/cop.rb +13 -7
  14. data/lib/rubocop/cop/corrector.rb +10 -10
  15. data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -1
  16. data/lib/rubocop/cop/lint/block_alignment.rb +9 -2
  17. data/lib/rubocop/cop/lint/debugger.rb +13 -1
  18. data/lib/rubocop/cop/lint/duplicate_methods.rb +104 -0
  19. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  20. data/lib/rubocop/cop/lint/require_parentheses.rb +3 -3
  21. data/lib/rubocop/cop/mixin/access_modifier_node.rb +27 -0
  22. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +0 -4
  23. data/lib/rubocop/cop/rails/delegate.rb +4 -5
  24. data/lib/rubocop/cop/rails/read_write_attribute.rb +33 -0
  25. data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -7
  26. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +4 -2
  27. data/lib/rubocop/cop/style/class_methods.rb +25 -9
  28. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +7 -1
  29. data/lib/rubocop/cop/style/empty_literal.rb +25 -10
  30. data/lib/rubocop/cop/style/even_odd.rb +32 -14
  31. data/lib/rubocop/cop/style/first_parameter_indentation.rb +106 -0
  32. data/lib/rubocop/cop/style/format_string.rb +2 -2
  33. data/lib/rubocop/cop/style/global_vars.rb +1 -5
  34. data/lib/rubocop/cop/style/hash_syntax.rb +0 -4
  35. data/lib/rubocop/cop/style/indentation_consistency.rb +5 -5
  36. data/lib/rubocop/cop/style/indentation_width.rb +13 -14
  37. data/lib/rubocop/cop/style/lambda.rb +48 -2
  38. data/lib/rubocop/cop/style/line_end_concatenation.rb +43 -47
  39. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -3
  40. data/lib/rubocop/cop/style/module_function.rb +3 -3
  41. data/lib/rubocop/cop/style/multiline_block_layout.rb +65 -17
  42. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +2 -1
  43. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  44. data/lib/rubocop/cop/style/redundant_exception.rb +12 -0
  45. data/lib/rubocop/cop/style/self_assignment.rb +27 -0
  46. data/lib/rubocop/cop/style/semicolon.rb +2 -1
  47. data/lib/rubocop/cop/style/space_around_block_parameters.rb +92 -0
  48. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +0 -8
  49. data/lib/rubocop/cop/style/struct_inheritance.rb +42 -0
  50. data/lib/rubocop/cop/style/trivial_accessors.rb +10 -4
  51. data/lib/rubocop/cop/util.rb +32 -7
  52. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -15
  53. data/lib/rubocop/options.rb +28 -41
  54. data/lib/rubocop/processed_source.rb +6 -0
  55. data/lib/rubocop/rake_task.rb +6 -3
  56. data/lib/rubocop/runner.rb +55 -15
  57. data/lib/rubocop/version.rb +1 -1
  58. data/relnotes/v0.29.0.md +116 -0
  59. data/rubocop.gemspec +3 -3
  60. data/spec/rubocop/cli_spec.rb +329 -25
  61. data/spec/rubocop/config_loader_spec.rb +20 -0
  62. data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +27 -3
  63. data/spec/rubocop/cop/lint/block_alignment_spec.rb +3 -4
  64. data/spec/rubocop/cop/lint/condition_position_spec.rb +1 -1
  65. data/spec/rubocop/cop/lint/debugger_spec.rb +20 -7
  66. data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +189 -0
  67. data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +1 -1
  68. data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
  69. data/spec/rubocop/cop/lint/eval_spec.rb +4 -4
  70. data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +18 -0
  71. data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +2 -2
  72. data/spec/rubocop/cop/lint/loop_spec.rb +4 -4
  73. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +7 -7
  74. data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +5 -4
  75. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +3 -9
  76. data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
  77. data/spec/rubocop/cop/lint/void_spec.rb +1 -1
  78. data/spec/rubocop/cop/metrics/abc_size_spec.rb +10 -0
  79. data/spec/rubocop/cop/metrics/line_length_spec.rb +2 -2
  80. data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +2 -2
  81. data/spec/rubocop/cop/rails/action_filter_spec.rb +6 -12
  82. data/spec/rubocop/cop/rails/default_scope_spec.rb +5 -5
  83. data/spec/rubocop/cop/rails/delegate_spec.rb +8 -0
  84. data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
  85. data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +119 -8
  86. data/spec/rubocop/cop/rails/scope_args_spec.rb +3 -3
  87. data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
  88. data/spec/rubocop/cop/style/alias_spec.rb +5 -5
  89. data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
  90. data/spec/rubocop/cop/style/align_parameters_spec.rb +8 -8
  91. data/spec/rubocop/cop/style/and_or_spec.rb +15 -30
  92. data/spec/rubocop/cop/style/array_join_spec.rb +4 -4
  93. data/spec/rubocop/cop/style/ascii_comments_spec.rb +1 -2
  94. data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
  95. data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
  96. data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
  97. data/spec/rubocop/cop/style/block_end_newline_spec.rb +1 -1
  98. data/spec/rubocop/cop/style/blocks_spec.rb +2 -2
  99. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +38 -33
  100. data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
  101. data/spec/rubocop/cop/style/character_literal_spec.rb +4 -4
  102. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +4 -2
  103. data/spec/rubocop/cop/style/class_methods_spec.rb +12 -0
  104. data/spec/rubocop/cop/style/class_vars_spec.rb +2 -2
  105. data/spec/rubocop/cop/style/collection_methods_spec.rb +4 -4
  106. data/spec/rubocop/cop/style/colon_method_call_spec.rb +8 -8
  107. data/spec/rubocop/cop/style/comment_annotation_spec.rb +10 -10
  108. data/spec/rubocop/cop/style/constant_name_spec.rb +7 -7
  109. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
  110. data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +4 -4
  111. data/spec/rubocop/cop/style/dot_position_spec.rb +8 -6
  112. data/spec/rubocop/cop/style/each_with_object_spec.rb +2 -2
  113. data/spec/rubocop/cop/style/else_alignment_spec.rb +2 -4
  114. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +78 -0
  115. data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +60 -0
  116. data/spec/rubocop/cop/style/empty_lines_spec.rb +3 -3
  117. data/spec/rubocop/cop/style/empty_literal_spec.rb +29 -12
  118. data/spec/rubocop/cop/style/encoding_spec.rb +3 -3
  119. data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
  120. data/spec/rubocop/cop/style/end_of_line_spec.rb +2 -2
  121. data/spec/rubocop/cop/style/even_odd_spec.rb +109 -20
  122. data/spec/rubocop/cop/style/extra_spacing_spec.rb +3 -3
  123. data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +293 -0
  124. data/spec/rubocop/cop/style/for_spec.rb +2 -2
  125. data/spec/rubocop/cop/style/format_string_spec.rb +45 -21
  126. data/spec/rubocop/cop/style/global_vars_spec.rb +4 -4
  127. data/spec/rubocop/cop/style/guard_clause_spec.rb +17 -0
  128. data/spec/rubocop/cop/style/hash_syntax_spec.rb +15 -15
  129. data/spec/rubocop/cop/{metrics → style}/if_unless_modifier_spec.rb +2 -2
  130. data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +2 -2
  131. data/spec/rubocop/cop/style/indent_array_spec.rb +3 -6
  132. data/spec/rubocop/cop/style/indent_hash_spec.rb +4 -4
  133. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +1 -2
  134. data/spec/rubocop/cop/style/indentation_width_spec.rb +1 -2
  135. data/spec/rubocop/cop/style/infinite_loop_spec.rb +1 -1
  136. data/spec/rubocop/cop/style/lambda_call_spec.rb +4 -4
  137. data/spec/rubocop/cop/style/lambda_spec.rb +37 -2
  138. data/spec/rubocop/cop/style/leading_comment_space_spec.rb +7 -12
  139. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +41 -1
  140. data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +4 -4
  141. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +3 -3
  142. data/spec/rubocop/cop/style/method_name_spec.rb +1 -1
  143. data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +61 -0
  144. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -3
  145. data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +8 -0
  146. data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +1 -1
  147. data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +1 -1
  148. data/spec/rubocop/cop/style/next_spec.rb +16 -0
  149. data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -5
  150. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
  151. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +22 -4
  152. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +31 -31
  153. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +12 -12
  154. data/spec/rubocop/cop/style/perl_backrefs_spec.rb +3 -3
  155. data/spec/rubocop/cop/style/proc_spec.rb +3 -3
  156. data/spec/rubocop/cop/style/raise_args_spec.rb +9 -9
  157. data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
  158. data/spec/rubocop/cop/style/redundant_exception_spec.rb +36 -4
  159. data/spec/rubocop/cop/style/redundant_self_spec.rb +89 -45
  160. data/spec/rubocop/cop/style/regexp_literal_spec.rb +9 -9
  161. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
  162. data/spec/rubocop/cop/style/self_assignment_spec.rb +16 -10
  163. data/spec/rubocop/cop/style/semicolon_spec.rb +9 -9
  164. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -2
  165. data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +1 -1
  166. data/spec/rubocop/cop/style/space_after_colon_spec.rb +5 -5
  167. data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
  168. data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +4 -4
  169. data/spec/rubocop/cop/style/space_after_not_spec.rb +2 -2
  170. data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +2 -2
  171. data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +150 -0
  172. data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +18 -9
  173. data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -21
  174. data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +4 -4
  175. data/spec/rubocop/cop/style/space_before_comma_spec.rb +4 -4
  176. data/spec/rubocop/cop/style/space_before_comment_spec.rb +3 -3
  177. data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +2 -2
  178. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +33 -24
  179. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +2 -2
  180. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +9 -9
  181. data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
  182. data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -6
  183. data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +3 -3
  184. data/spec/rubocop/cop/style/string_literals_spec.rb +16 -16
  185. data/spec/rubocop/cop/style/struct_inheritance_spec.rb +44 -0
  186. data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
  187. data/spec/rubocop/cop/style/symbol_proc_spec.rb +12 -12
  188. data/spec/rubocop/cop/style/tab_spec.rb +4 -4
  189. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +2 -2
  190. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -2
  191. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +16 -0
  192. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +11 -22
  193. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +7 -7
  194. data/spec/rubocop/cop/style/while_until_do_spec.rb +2 -2
  195. data/spec/rubocop/cop/{metrics → style}/while_until_modifier_spec.rb +2 -2
  196. data/spec/rubocop/cop/style/word_array_spec.rb +11 -11
  197. data/spec/rubocop/cop/util_spec.rb +51 -0
  198. data/spec/rubocop/cop/variable_force/reference_spec.rb +19 -0
  199. data/spec/rubocop/cop/variable_force/variable_table_spec.rb +7 -0
  200. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +7 -8
  201. data/spec/rubocop/formatter/text_util_spec.rb +55 -0
  202. data/spec/rubocop/options_spec.rb +26 -20
  203. data/spec/rubocop/rake_task_spec.rb +122 -0
  204. data/spec/rubocop/runner_spec.rb +37 -2
  205. data/spec/rubocop/token_spec.rb +5 -1
  206. data/spec/spec_helper.rb +5 -2
  207. data/spec/support/cop_helper.rb +3 -0
  208. data/spec/support/cops/class_must_be_a_module_cop.rb +19 -0
  209. data/spec/support/cops/module_must_be_a_class_cop.rb +19 -0
  210. data/spec/support/custom_matchers.rb +1 -1
  211. metadata +35 -12
@@ -7,12 +7,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
7
7
 
8
8
  shared_examples 'accepts quote characters' do
9
9
  it 'accepts single quotes' do
10
- inspect_source(cop, ["'hi'"])
10
+ inspect_source(cop, "'hi'")
11
11
  expect(cop.offenses).to be_empty
12
12
  end
13
13
 
14
14
  it 'accepts double quotes' do
15
- inspect_source(cop, ['"hi"'])
15
+ inspect_source(cop, '"hi"')
16
16
  expect(cop.offenses).to be_empty
17
17
  end
18
18
  end
@@ -20,12 +20,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
20
20
  shared_examples 'accepts any q string with backslash t' do
21
21
  context 'with special characters' do
22
22
  it 'accepts %q' do
23
- inspect_source(cop, ['%q(\t)'])
23
+ inspect_source(cop, '%q(\t)')
24
24
  expect(cop.offenses).to be_empty
25
25
  end
26
26
 
27
27
  it 'accepts %Q' do
28
- inspect_source(cop, ['%Q(\t)'])
28
+ inspect_source(cop, '%Q(\t)')
29
29
  expect(cop.offenses).to be_empty
30
30
  end
31
31
  end
@@ -36,12 +36,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
36
36
 
37
37
  context 'without interpolation' do
38
38
  it 'accepts %q' do
39
- inspect_source(cop, ['%q(hi)'])
39
+ inspect_source(cop, '%q(hi)')
40
40
  expect(cop.offenses).to be_empty
41
41
  end
42
42
 
43
43
  it 'registers offense for %Q' do
44
- inspect_source(cop, ['%Q(hi)'])
44
+ inspect_source(cop, '%Q(hi)')
45
45
  expect(cop.messages)
46
46
  .to eq(['Do not use `%Q` unless interpolation is needed. Use `%q`.'])
47
47
  expect(cop.highlights).to eq(['%Q('])
@@ -58,13 +58,13 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
58
58
 
59
59
  context 'with interpolation' do
60
60
  it 'accepts %Q' do
61
- inspect_source(cop, ['%Q(#{1 + 2})'])
61
+ inspect_source(cop, '%Q(#{1 + 2})')
62
62
  expect(cop.offenses).to be_empty
63
63
  end
64
64
 
65
65
  it 'accepts %q' do
66
66
  # This is most probably a mistake, but not this cop's responsibility.
67
- inspect_source(cop, ['%q(#{1 + 2})'])
67
+ inspect_source(cop, '%q(#{1 + 2})')
68
68
  expect(cop.offenses).to be_empty
69
69
  end
70
70
 
@@ -77,13 +77,13 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
77
77
 
78
78
  context 'without interpolation' do
79
79
  it 'registers offense for %q' do
80
- inspect_source(cop, ['%q(hi)'])
80
+ inspect_source(cop, '%q(hi)')
81
81
  expect(cop.messages).to eq(['Use `%Q` instead of `%q`.'])
82
82
  expect(cop.highlights).to eq(['%q('])
83
83
  end
84
84
 
85
85
  it 'accepts %Q' do
86
- inspect_source(cop, ['%Q(hi)'])
86
+ inspect_source(cop, '%Q(hi)')
87
87
  expect(cop.offenses).to be_empty
88
88
  end
89
89
 
@@ -98,7 +98,7 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
98
98
 
99
99
  context 'with interpolation' do
100
100
  it 'accepts %Q' do
101
- inspect_source(cop, ['%Q(#{1 + 2})'])
101
+ inspect_source(cop, '%Q(#{1 + 2})')
102
102
  expect(cop.offenses).to be_empty
103
103
  end
104
104
 
@@ -106,7 +106,7 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
106
106
  # It's strange if interpolation syntax appears inside a static string,
107
107
  # but we can't be sure if it's a mistake or not. Changing it to %Q
108
108
  # would alter semantics, so we leave it as it is.
109
- inspect_source(cop, ['%q(#{1 + 2})'])
109
+ inspect_source(cop, '%q(#{1 + 2})')
110
110
  expect(cop.offenses).to be_empty
111
111
  end
112
112
 
@@ -6,17 +6,17 @@ describe RuboCop::Cop::Style::PerlBackrefs do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for $1' do
9
- inspect_source(cop, ['puts $1'])
9
+ inspect_source(cop, 'puts $1')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
13
13
  it 'auto-corrects $1 to Regexp.last_match[1]' do
14
14
  new_source = autocorrect_source(cop, '$1')
15
- expect(new_source).to eq('Regexp.last_match[1]')
15
+ expect(new_source).to eq('Regexp.last_match(1)')
16
16
  end
17
17
 
18
18
  it 'auto-corrects #$1 to #{Regexp.last_match[1]}' do
19
19
  new_source = autocorrect_source(cop, '"#$1"')
20
- expect(new_source).to eq('"#{Regexp.last_match[1]}"')
20
+ expect(new_source).to eq('"#{Regexp.last_match(1)}"')
21
21
  end
22
22
  end
@@ -6,17 +6,17 @@ describe RuboCop::Cop::Style::Proc do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for a Proc.new call' do
9
- inspect_source(cop, ['f = Proc.new { |x| puts x }'])
9
+ inspect_source(cop, 'f = Proc.new { |x| puts x }')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
13
13
  it 'accepts the proc method' do
14
- inspect_source(cop, ['f = proc { |x| puts x }'])
14
+ inspect_source(cop, 'f = proc { |x| puts x }')
15
15
  expect(cop.offenses).to be_empty
16
16
  end
17
17
 
18
18
  it 'accepts the Proc.new call outside of block' do
19
- inspect_source(cop, ['p = Proc.new'])
19
+ inspect_source(cop, 'p = Proc.new')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
@@ -9,7 +9,7 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
9
9
  let(:cop_config) { { 'EnforcedStyle' => 'compact' } }
10
10
 
11
11
  it 'reports an offense for a raise with 2 args' do
12
- inspect_source(cop, ['raise RuntimeError, msg'])
12
+ inspect_source(cop, 'raise RuntimeError, msg')
13
13
  expect(cop.offenses.size).to eq(1)
14
14
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'exploded')
15
15
  end
@@ -27,17 +27,17 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
27
27
  end
28
28
 
29
29
  it 'reports an offense for a raise with 3 args' do
30
- inspect_source(cop, ['raise RuntimeError, msg, caller'])
30
+ inspect_source(cop, 'raise RuntimeError, msg, caller')
31
31
  expect(cop.offenses.size).to eq(1)
32
32
  end
33
33
 
34
34
  it 'accepts a raise with msg argument' do
35
- inspect_source(cop, ['raise msg'])
35
+ inspect_source(cop, 'raise msg')
36
36
  expect(cop.offenses).to be_empty
37
37
  end
38
38
 
39
39
  it 'accepts a raise with an exception argument' do
40
- inspect_source(cop, ['raise Ex.new(msg)'])
40
+ inspect_source(cop, 'raise Ex.new(msg)')
41
41
  expect(cop.offenses).to be_empty
42
42
  end
43
43
  end
@@ -46,7 +46,7 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
46
46
  let(:cop_config) { { 'EnforcedStyle' => 'exploded' } }
47
47
 
48
48
  it 'reports an offense for a raise with exception object' do
49
- inspect_source(cop, ['raise Ex.new(msg)'])
49
+ inspect_source(cop, 'raise Ex.new(msg)')
50
50
  expect(cop.offenses.size).to eq(1)
51
51
  expect(cop.messages)
52
52
  .to eq(['Provide an exception class and message ' \
@@ -65,22 +65,22 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
65
65
  end
66
66
 
67
67
  it 'accepts exception constructor with more than 1 argument' do
68
- inspect_source(cop, ['raise RuntimeError.new(a1, a2, a3)'])
68
+ inspect_source(cop, 'raise RuntimeError.new(a1, a2, a3)')
69
69
  expect(cop.offenses).to be_empty
70
70
  end
71
71
 
72
72
  it 'accepts a raise with 3 args' do
73
- inspect_source(cop, ['raise RuntimeError, msg, caller'])
73
+ inspect_source(cop, 'raise RuntimeError, msg, caller')
74
74
  expect(cop.offenses).to be_empty
75
75
  end
76
76
 
77
77
  it 'accepts a raise with 2 args' do
78
- inspect_source(cop, ['raise RuntimeError, msg'])
78
+ inspect_source(cop, 'raise RuntimeError, msg')
79
79
  expect(cop.offenses).to be_empty
80
80
  end
81
81
 
82
82
  it 'accepts a raise with msg argument' do
83
- inspect_source(cop, ['raise msg'])
83
+ inspect_source(cop, 'raise msg')
84
84
  expect(cop.offenses).to be_empty
85
85
  end
86
86
  end
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::RedundantBegin do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'reports an offense for single line def with redundant begin block' do
9
- src = [' def func; begin; x; y; rescue; z end end']
9
+ src = ' def func; begin; x; y; rescue; z end end'
10
10
  inspect_source(cop, src)
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
@@ -6,22 +6,54 @@ describe RuboCop::Cop::Style::RedundantException do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'reports an offense for a raise with RuntimeError' do
9
- inspect_source(cop, ['raise RuntimeError, msg'])
9
+ inspect_source(cop, 'raise RuntimeError, msg')
10
10
  expect(cop.offenses.size).to eq(1)
11
11
  end
12
12
 
13
13
  it 'reports an offense for a fail with RuntimeError' do
14
- inspect_source(cop, ['fail RuntimeError, msg'])
14
+ inspect_source(cop, 'fail RuntimeError, msg')
15
15
  expect(cop.offenses.size).to eq(1)
16
16
  end
17
17
 
18
18
  it 'accepts a raise with RuntimeError if it does not have 2 args' do
19
- inspect_source(cop, ['raise RuntimeError, msg, caller'])
19
+ inspect_source(cop, 'raise RuntimeError, msg, caller')
20
20
  expect(cop.offenses).to be_empty
21
21
  end
22
22
 
23
23
  it 'accepts a fail with RuntimeError if it does not have 2 args' do
24
- inspect_source(cop, ['fail RuntimeError, msg, caller'])
24
+ inspect_source(cop, 'fail RuntimeError, msg, caller')
25
25
  expect(cop.offenses).to be_empty
26
26
  end
27
+
28
+ it 'auto-corrects a raise by removing RuntimeError' do
29
+ src = 'raise RuntimeError, msg'
30
+ result_src = 'raise msg'
31
+ new_src = autocorrect_source(cop, src)
32
+ expect(new_src).to eq(result_src)
33
+ end
34
+
35
+ it 'auto-corrects a fil by removing RuntimeError' do
36
+ src = 'fail RuntimeError, msg'
37
+ result_src = 'fail msg'
38
+ new_src = autocorrect_source(cop, src)
39
+ expect(new_src).to eq(result_src)
40
+ end
41
+
42
+ it 'does not modify raise w/ RuntimeError if it does not have 2 args' do
43
+ src = 'raise runtimeError, msg, caller'
44
+ new_src = autocorrect_source(cop, src)
45
+ expect(new_src).to eq(src)
46
+ end
47
+
48
+ it 'does not modify fail w/ RuntimeError if it does not have 2 args' do
49
+ src = 'fail RuntimeError, msg, caller'
50
+ new_src = autocorrect_source(cop, src)
51
+ expect(new_src).to eq(src)
52
+ end
53
+
54
+ it 'does not modify rescue w/ non redundant error' do
55
+ src = 'fail OtherError, msg'
56
+ new_src = autocorrect_source(cop, src)
57
+ expect(new_src).to eq(src)
58
+ end
27
59
  end
@@ -6,43 +6,43 @@ describe RuboCop::Cop::Style::RedundantSelf do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'reports an offense a self receiver on an rvalue' do
9
- src = ['a = self.b']
9
+ src = 'a = self.b'
10
10
  inspect_source(cop, src)
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  end
13
13
 
14
14
  it 'accepts a self receiver on an lvalue of an assignment' do
15
- src = ['self.a = b']
15
+ src = 'self.a = b'
16
16
  inspect_source(cop, src)
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
 
20
20
  it 'accepts a self receiver on an lvalue of an or-assignment' do
21
- src = ['self.logger ||= Rails.logger']
21
+ src = 'self.logger ||= Rails.logger'
22
22
  inspect_source(cop, src)
23
23
  expect(cop.offenses).to be_empty
24
24
  end
25
25
 
26
26
  it 'accepts a self receiver on an lvalue of an and-assignment' do
27
- src = ['self.flag &&= value']
27
+ src = 'self.flag &&= value'
28
28
  inspect_source(cop, src)
29
29
  expect(cop.offenses).to be_empty
30
30
  end
31
31
 
32
32
  it 'accepts a self receiver on an lvalue of a plus-assignment' do
33
- src = ['self.sum += 10']
33
+ src = 'self.sum += 10'
34
34
  inspect_source(cop, src)
35
35
  expect(cop.offenses).to be_empty
36
36
  end
37
37
 
38
38
  it 'accepts a self receiver with the square bracket operator' do
39
- src = ['self[a]']
39
+ src = 'self[a]'
40
40
  inspect_source(cop, src)
41
41
  expect(cop.offenses).to be_empty
42
42
  end
43
43
 
44
44
  it 'accepts a self receiver with the double less-than operator' do
45
- src = ['self << a']
45
+ src = 'self << a'
46
46
  inspect_source(cop, src)
47
47
  expect(cop.offenses).to be_empty
48
48
  end
@@ -89,54 +89,98 @@ describe RuboCop::Cop::Style::RedundantSelf do
89
89
  expect(cop.offenses).to be_empty
90
90
  end
91
91
 
92
- it 'accepts a self receiver used to distinguish from blockarg' do
93
- src = ['def requested_specs(&groups)',
94
- ' some_method(self.groups)',
95
- 'end'
96
- ]
97
- inspect_source(cop, src)
98
- expect(cop.offenses).to be_empty
99
- end
100
-
101
- it 'accepts a self receiver used to distinguish from argument' do
102
- src = ['def requested_specs(groups)',
103
- ' some_method(self.groups)',
104
- 'end'
105
- ]
106
- inspect_source(cop, src)
107
- expect(cop.offenses).to be_empty
92
+ describe 'instance methods' do
93
+ it 'accepts a self receiver used to distinguish from blockarg' do
94
+ src = ['def requested_specs(&groups)',
95
+ ' some_method(self.groups)',
96
+ 'end'
97
+ ]
98
+ inspect_source(cop, src)
99
+ expect(cop.offenses).to be_empty
100
+ end
101
+
102
+ it 'accepts a self receiver used to distinguish from argument' do
103
+ src = ['def requested_specs(groups)',
104
+ ' some_method(self.groups)',
105
+ 'end'
106
+ ]
107
+ inspect_source(cop, src)
108
+ expect(cop.offenses).to be_empty
109
+ end
110
+
111
+ it 'accepts a self receiver used to distinguish from argument' do
112
+ src = ['def requested_specs(final = true)',
113
+ ' something if self.final != final',
114
+ 'end'
115
+ ]
116
+ inspect_source(cop, src)
117
+ expect(cop.offenses).to be_empty
118
+ end
119
+
120
+ it 'accepts a self receiver used to distinguish from local variable' do
121
+ src = ['def requested_specs',
122
+ ' @requested_specs ||= begin',
123
+ ' groups = self.groups - Bundler.settings.without',
124
+ ' groups.map! { |g| g.to_sym }',
125
+ ' specs_for(groups)',
126
+ ' end',
127
+ 'end'
128
+ ]
129
+ inspect_source(cop, src)
130
+ expect(cop.offenses).to be_empty
131
+ end
108
132
  end
109
133
 
110
- it 'accepts a self receiver used to distinguish from argument' do
111
- src = ['def requested_specs(final = true)',
112
- ' something if self.final != final',
113
- 'end'
114
- ]
115
- inspect_source(cop, src)
116
- expect(cop.offenses).to be_empty
117
- end
118
-
119
- it 'accepts a self receiver used to distinguish from local variable' do
120
- src = ['def requested_specs',
121
- ' @requested_specs ||= begin',
122
- ' groups = self.groups - Bundler.settings.without',
123
- ' groups.map! { |g| g.to_sym }',
124
- ' specs_for(groups)',
125
- ' end',
126
- 'end'
127
- ]
128
- inspect_source(cop, src)
129
- expect(cop.offenses).to be_empty
134
+ describe 'class methods' do
135
+ it 'accepts a self receiver used to distinguish from blockarg' do
136
+ src = ['def self.requested_specs(&groups)',
137
+ ' some_method(self.groups)',
138
+ 'end'
139
+ ]
140
+ inspect_source(cop, src)
141
+ expect(cop.offenses).to be_empty
142
+ end
143
+
144
+ it 'accepts a self receiver used to distinguish from argument' do
145
+ src = ['def self.requested_specs(groups)',
146
+ ' some_method(self.groups)',
147
+ 'end'
148
+ ]
149
+ inspect_source(cop, src)
150
+ expect(cop.offenses).to be_empty
151
+ end
152
+
153
+ it 'accepts a self receiver used to distinguish from argument' do
154
+ src = ['def self.requested_specs(final = true)',
155
+ ' something if self.final != final',
156
+ 'end'
157
+ ]
158
+ inspect_source(cop, src)
159
+ expect(cop.offenses).to be_empty
160
+ end
161
+
162
+ it 'accepts a self receiver used to distinguish from local variable' do
163
+ src = ['def self.requested_specs',
164
+ ' @requested_specs ||= begin',
165
+ ' groups = self.groups - Bundler.settings.without',
166
+ ' groups.map! { |g| g.to_sym }',
167
+ ' specs_for(groups)',
168
+ ' end',
169
+ 'end'
170
+ ]
171
+ inspect_source(cop, src)
172
+ expect(cop.offenses).to be_empty
173
+ end
130
174
  end
131
175
 
132
176
  it 'accepts a self receiver used to distinguish from constant' do
133
- src = ['self.Foo']
177
+ src = 'self.Foo'
134
178
  inspect_source(cop, src)
135
179
  expect(cop.offenses).to be_empty
136
180
  end
137
181
 
138
182
  it 'auto-corrects by removing redundant self' do
139
- new_source = autocorrect_source(cop, ['self.x'])
183
+ new_source = autocorrect_source(cop, 'self.x')
140
184
  expect(new_source).to eq('x')
141
185
  end
142
186
  end