rubocop 0.7.2 → 0.8.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 (184) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -1
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +4 -8
  5. data/bin/rubocop +2 -2
  6. data/config/default.yml +8 -0
  7. data/config/enabled.yml +21 -24
  8. data/lib/rubocop.rb +9 -7
  9. data/lib/rubocop/cli.rb +73 -52
  10. data/lib/rubocop/config.rb +8 -5
  11. data/lib/rubocop/cop/access_control.rb +41 -0
  12. data/lib/rubocop/cop/alias.rb +7 -5
  13. data/lib/rubocop/cop/align_parameters.rb +20 -96
  14. data/lib/rubocop/cop/and_or.rb +26 -0
  15. data/lib/rubocop/cop/ascii_comments.rb +3 -8
  16. data/lib/rubocop/cop/ascii_identifiers.rb +6 -5
  17. data/lib/rubocop/cop/avoid_class_vars.rb +5 -10
  18. data/lib/rubocop/cop/avoid_for.rb +7 -5
  19. data/lib/rubocop/cop/avoid_global_vars.rb +19 -7
  20. data/lib/rubocop/cop/avoid_perl_backrefs.rb +7 -10
  21. data/lib/rubocop/cop/avoid_perlisms.rb +11 -10
  22. data/lib/rubocop/cop/block_comments.rb +4 -6
  23. data/lib/rubocop/cop/blocks.rb +11 -47
  24. data/lib/rubocop/cop/case_indentation.rb +9 -31
  25. data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
  26. data/lib/rubocop/cop/class_methods.rb +5 -10
  27. data/lib/rubocop/cop/collection_methods.rb +16 -16
  28. data/lib/rubocop/cop/colon_method_call.rb +8 -32
  29. data/lib/rubocop/cop/constant_name.rb +24 -0
  30. data/lib/rubocop/cop/cop.rb +20 -78
  31. data/lib/rubocop/cop/def_parentheses.rb +43 -35
  32. data/lib/rubocop/cop/empty_line_between_defs.rb +11 -15
  33. data/lib/rubocop/cop/empty_lines.rb +20 -9
  34. data/lib/rubocop/cop/empty_literal.rb +47 -0
  35. data/lib/rubocop/cop/encoding.rb +3 -3
  36. data/lib/rubocop/cop/end_of_line.rb +3 -3
  37. data/lib/rubocop/cop/ensure_return.rb +6 -23
  38. data/lib/rubocop/cop/eval.rb +7 -10
  39. data/lib/rubocop/cop/favor_join.rb +9 -24
  40. data/lib/rubocop/cop/favor_modifier.rb +38 -48
  41. data/lib/rubocop/cop/favor_percent_r.rb +7 -7
  42. data/lib/rubocop/cop/favor_sprintf.rb +8 -24
  43. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
  44. data/lib/rubocop/cop/handle_exceptions.rb +7 -11
  45. data/lib/rubocop/cop/hash_syntax.rb +29 -14
  46. data/lib/rubocop/cop/if_then_else.rb +32 -29
  47. data/lib/rubocop/cop/leading_comment_space.rb +5 -8
  48. data/lib/rubocop/cop/line_continuation.rb +4 -7
  49. data/lib/rubocop/cop/line_length.rb +3 -3
  50. data/lib/rubocop/cop/loop.rb +33 -0
  51. data/lib/rubocop/cop/method_and_variable_snake_case.rb +42 -19
  52. data/lib/rubocop/cop/method_length.rb +34 -37
  53. data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
  54. data/lib/rubocop/cop/not.rb +10 -4
  55. data/lib/rubocop/cop/numeric_literals.rb +9 -7
  56. data/lib/rubocop/cop/offence.rb +1 -1
  57. data/lib/rubocop/cop/op_method.rb +12 -22
  58. data/lib/rubocop/cop/parameter_lists.rb +12 -6
  59. data/lib/rubocop/cop/parentheses_around_condition.rb +11 -11
  60. data/lib/rubocop/cop/percent_r.rb +7 -7
  61. data/lib/rubocop/cop/reduce_arguments.rb +13 -51
  62. data/lib/rubocop/cop/rescue_exception.rb +13 -29
  63. data/lib/rubocop/cop/rescue_modifier.rb +5 -8
  64. data/lib/rubocop/cop/semicolon.rb +15 -74
  65. data/lib/rubocop/cop/single_line_methods.rb +28 -44
  66. data/lib/rubocop/cop/space_after_comma_etc.rb +29 -9
  67. data/lib/rubocop/cop/space_after_control_keyword.rb +16 -15
  68. data/lib/rubocop/cop/string_literals.rb +9 -35
  69. data/lib/rubocop/cop/surrounding_space.rb +213 -112
  70. data/lib/rubocop/cop/symbol_array.rb +9 -7
  71. data/lib/rubocop/cop/symbol_name.rb +23 -0
  72. data/lib/rubocop/cop/syntax.rb +14 -7
  73. data/lib/rubocop/cop/tab.rb +3 -3
  74. data/lib/rubocop/cop/ternary_operator.rb +26 -24
  75. data/lib/rubocop/cop/trailing_whitespace.rb +3 -5
  76. data/lib/rubocop/cop/trivial_accessors.rb +18 -95
  77. data/lib/rubocop/cop/unless_else.rb +11 -7
  78. data/lib/rubocop/cop/util.rb +26 -0
  79. data/lib/rubocop/cop/variable_interpolation.rb +18 -10
  80. data/lib/rubocop/cop/when_then.rb +6 -17
  81. data/lib/rubocop/cop/word_array.rb +18 -19
  82. data/lib/rubocop/version.rb +1 -1
  83. data/rubocop.gemspec +1 -0
  84. data/spec/project_spec.rb +1 -1
  85. data/spec/rubocop/cli_spec.rb +16 -9
  86. data/spec/rubocop/config_spec.rb +13 -3
  87. data/spec/rubocop/cops/access_control_spec.rb +129 -0
  88. data/spec/rubocop/cops/alias_spec.rb +2 -6
  89. data/spec/rubocop/cops/align_parameters_spec.rb +58 -71
  90. data/spec/rubocop/cops/and_or_spec.rb +37 -0
  91. data/spec/rubocop/cops/ascii_comments_spec.rb +3 -4
  92. data/spec/rubocop/cops/ascii_identifiers_spec.rb +3 -4
  93. data/spec/rubocop/cops/avoid_class_vars_spec.rb +7 -2
  94. data/spec/rubocop/cops/avoid_for_spec.rb +1 -4
  95. data/spec/rubocop/cops/{avoid_global_vars.rb → avoid_global_vars_spec.rb} +4 -4
  96. data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +1 -1
  97. data/spec/rubocop/cops/avoid_perlisms_spec.rb +5 -5
  98. data/spec/rubocop/cops/block_comments_spec.rb +0 -4
  99. data/spec/rubocop/cops/blocks_spec.rb +33 -0
  100. data/spec/rubocop/cops/case_indentation_spec.rb +5 -5
  101. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
  102. data/spec/rubocop/cops/class_methods_spec.rb +4 -4
  103. data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
  104. data/spec/rubocop/cops/colon_method_call_spec.rb +11 -5
  105. data/spec/rubocop/cops/constant_name_spec.rb +42 -0
  106. data/spec/rubocop/cops/def_with_parentheses_spec.rb +13 -8
  107. data/spec/rubocop/cops/def_without_parentheses_spec.rb +11 -5
  108. data/spec/rubocop/cops/empty_line_between_defs_spec.rb +38 -38
  109. data/spec/rubocop/cops/empty_lines_spec.rb +15 -3
  110. data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
  111. data/spec/rubocop/cops/encoding_spec.rb +9 -9
  112. data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
  113. data/spec/rubocop/cops/ensure_return_spec.rb +1 -3
  114. data/spec/rubocop/cops/eval_spec.rb +8 -5
  115. data/spec/rubocop/cops/favor_join_spec.rb +1 -5
  116. data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
  117. data/spec/rubocop/cops/{favor_percent_r.rb → favor_percent_r_spec.rb} +6 -6
  118. data/spec/rubocop/cops/favor_sprintf_spec.rb +3 -9
  119. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +4 -4
  120. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +3 -3
  121. data/spec/rubocop/cops/handle_exceptions_spec.rb +1 -3
  122. data/spec/rubocop/cops/hash_syntax_spec.rb +11 -6
  123. data/spec/rubocop/cops/if_with_semicolon_spec.rb +7 -1
  124. data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -7
  125. data/spec/rubocop/cops/line_continuation_spec.rb +2 -2
  126. data/spec/rubocop/cops/line_length_spec.rb +2 -2
  127. data/spec/rubocop/cops/loop_spec.rb +31 -0
  128. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +38 -12
  129. data/spec/rubocop/cops/method_length_spec.rb +85 -85
  130. data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
  131. data/spec/rubocop/cops/new_lambda_literal_spec.rb +3 -3
  132. data/spec/rubocop/cops/not_spec.rb +1 -4
  133. data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
  134. data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
  135. data/spec/rubocop/cops/op_method_spec.rb +2 -9
  136. data/spec/rubocop/cops/parameter_lists_spec.rb +7 -7
  137. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +41 -44
  138. data/spec/rubocop/cops/percent_r_spec.rb +6 -6
  139. data/spec/rubocop/cops/reduce_arguments_spec.rb +4 -4
  140. data/spec/rubocop/cops/rescue_exception_spec.rb +48 -8
  141. data/spec/rubocop/cops/rescue_modifier_spec.rb +2 -5
  142. data/spec/rubocop/cops/semicolon_spec.rb +2 -30
  143. data/spec/rubocop/cops/single_line_methods_spec.rb +13 -13
  144. data/spec/rubocop/cops/space_after_colon_spec.rb +3 -3
  145. data/spec/rubocop/cops/space_after_comma_spec.rb +14 -2
  146. data/spec/rubocop/cops/space_after_control_keyword_spec.rb +42 -3
  147. data/spec/rubocop/cops/space_after_semicolon_spec.rb +2 -2
  148. data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
  149. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
  150. data/spec/rubocop/cops/space_around_operators_spec.rb +82 -27
  151. data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
  152. data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +14 -9
  153. data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
  154. data/spec/rubocop/cops/string_literals_spec.rb +17 -5
  155. data/spec/rubocop/cops/symbol_array_spec.rb +18 -2
  156. data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
  157. data/spec/rubocop/cops/syntax_spec.rb +25 -18
  158. data/spec/rubocop/cops/tab_spec.rb +2 -2
  159. data/spec/rubocop/cops/ternary_operator_spec.rb +13 -17
  160. data/spec/rubocop/cops/trailing_whitespace_spec.rb +3 -3
  161. data/spec/rubocop/cops/trivial_accessors_spec.rb +17 -20
  162. data/spec/rubocop/cops/unless_else_spec.rb +8 -8
  163. data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -5
  164. data/spec/rubocop/cops/when_then_spec.rb +14 -21
  165. data/spec/rubocop/cops/word_array_spec.rb +12 -4
  166. data/spec/spec_helper.rb +12 -4
  167. metadata +40 -31
  168. data/.document +0 -5
  169. data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
  170. data/lib/rubocop/cop/array_literal.rb +0 -61
  171. data/lib/rubocop/cop/brace_after_percent.rb +0 -32
  172. data/lib/rubocop/cop/grammar.rb +0 -138
  173. data/lib/rubocop/cop/hash_literal.rb +0 -61
  174. data/lib/rubocop/cop/percent_literals.rb +0 -25
  175. data/lib/rubocop/cop/symbol_snake_case.rb +0 -47
  176. data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
  177. data/spec/rubocop/cops/array_literal_spec.rb +0 -46
  178. data/spec/rubocop/cops/brace_after_percent_spec.rb +0 -33
  179. data/spec/rubocop/cops/grammar_spec.rb +0 -81
  180. data/spec/rubocop/cops/hash_literal_spec.rb +0 -46
  181. data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
  182. data/spec/rubocop/cops/percent_literals_spec.rb +0 -47
  183. data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
  184. data/spec/rubocop/cops/symbol_snake_case_spec.rb +0 -93
@@ -8,7 +8,7 @@ module Rubocop
8
8
  let(:olc) { OneLineConditional.new }
9
9
 
10
10
  it 'registers an offence for one line if/then/end' do
11
- inspect_source(olc, '', ['if cond then run else dont end'])
11
+ inspect_source(olc, ['if cond then run else dont end'])
12
12
  expect(olc.offences.map(&:message)).to eq([olc.error_message])
13
13
  end
14
14
  end
@@ -9,29 +9,26 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for arg not named other' do
11
11
  inspect_source(om,
12
- 'file.rb',
13
12
  ['def +(another)',
14
13
  ' another',
15
14
  'end'])
16
15
  expect(om.offences.size).to eq(1)
17
16
  expect(om.offences.map(&:message))
18
- .to eq([sprintf(OpMethod::ERROR_MESSAGE, '+')])
17
+ .to eq([sprintf(OpMethod::MSG, '+')])
19
18
  end
20
19
 
21
20
  it 'works properly even if the argument is not surrounded with braces' do
22
21
  inspect_source(om,
23
- 'file.rb',
24
22
  ['def + another',
25
23
  ' another',
26
24
  'end'])
27
25
  expect(om.offences.size).to eq(1)
28
26
  expect(om.offences.map(&:message))
29
- .to eq([sprintf(OpMethod::ERROR_MESSAGE, '+')])
27
+ .to eq([sprintf(OpMethod::MSG, '+')])
30
28
  end
31
29
 
32
30
  it 'does not register an offence for arg named other' do
33
31
  inspect_source(om,
34
- 'file.rb',
35
32
  ['def +(other)',
36
33
  ' other',
37
34
  'end'])
@@ -40,7 +37,6 @@ module Rubocop
40
37
 
41
38
  it 'does not register an offence for []' do
42
39
  inspect_source(om,
43
- 'file.rb',
44
40
  ['def [](index)',
45
41
  ' other',
46
42
  'end'])
@@ -49,7 +45,6 @@ module Rubocop
49
45
 
50
46
  it 'does not register an offence for []=' do
51
47
  inspect_source(om,
52
- 'file.rb',
53
48
  ['def []=(index, value)',
54
49
  ' other',
55
50
  'end'])
@@ -58,7 +53,6 @@ module Rubocop
58
53
 
59
54
  it 'does not register an offence for <<' do
60
55
  inspect_source(om,
61
- 'file.rb',
62
56
  ['def <<(cop)',
63
57
  ' other',
64
58
  'end'])
@@ -67,7 +61,6 @@ module Rubocop
67
61
 
68
62
  it 'does not register an offence for non binary operators' do
69
63
  inspect_source(om,
70
- 'file.rb',
71
64
  ['def -@', # Unary minus
72
65
  'end',
73
66
  '',
@@ -8,16 +8,16 @@ module Rubocop
8
8
  let(:list) { ParameterLists.new }
9
9
 
10
10
  it 'registers an offence for a method def with 5 parameters' do
11
- inspect_source(list, 'file.rb', ['def meth(a, b, c, d, e)',
12
- 'end'])
13
- expect(list.offences.map(&:message)).to eq(
14
- ['Avoid parameter lists longer than four parameters.'])
11
+ inspect_source(list, ['def meth(a, b, c, d, e)',
12
+ 'end'])
13
+ expect(list.messages).to eq(
14
+ ['Avoid parameter lists longer than 4 parameters.'])
15
15
  end
16
16
 
17
17
  it 'accepts a method def with 4 parameters' do
18
- inspect_source(list, 'file.rb', ['def meth(a, b, c, d)',
19
- 'end'])
20
- expect(list.offences.map(&:message)).to be_empty
18
+ inspect_source(list, ['def meth(a, b, c, d)',
19
+ 'end'])
20
+ expect(list.offences).to be_empty
21
21
  end
22
22
  end
23
23
  end
@@ -8,57 +8,54 @@ module Rubocop
8
8
  let(:pac) { ParenthesesAroundCondition.new }
9
9
 
10
10
  it 'registers an offence for parentheses around condition' do
11
- inspect_source(pac, 'file.rb', ['if (x > 10)',
12
- 'elsif (x < 3)',
13
- 'end',
14
- 'unless (x > 10)',
15
- 'end',
16
- 'while (x > 10)',
17
- 'end',
18
- 'until (x > 10)',
19
- 'end',
20
- 'x += 1 if (x < 10)',
21
- 'x += 1 unless (x < 10)',
22
- 'x += 1 while (x < 10)',
23
- 'x += 1 until (x < 10)',
24
- ])
25
- expect(pac.offences.map(&:message)).to eq(
26
- ["Don't use parentheses around the condition of an if/unless/" +
27
- 'while/until, unless the condition contains an assignment.'] * 9)
11
+ inspect_source(pac, ['if (x > 10)',
12
+ 'elsif (x < 3)',
13
+ 'end',
14
+ 'unless (x > 10)',
15
+ 'end',
16
+ 'while (x > 10)',
17
+ 'end',
18
+ 'until (x > 10)',
19
+ 'end',
20
+ 'x += 1 if (x < 10)',
21
+ 'x += 1 unless (x < 10)',
22
+ 'x += 1 while (x < 10)',
23
+ 'x += 1 until (x < 10)',
24
+ ])
25
+ expect(pac.offences.size).to eq(9)
28
26
  end
29
27
 
30
28
  it 'accepts condition without parentheses' do
31
- inspect_source(pac, 'file.rb', ['if x > 10',
32
- 'end',
33
- 'unless x > 10',
34
- 'end',
35
- 'while x > 10',
36
- 'end',
37
- 'until x > 10',
38
- 'end',
39
- 'x += 1 if x < 10',
40
- 'x += 1 unless x < 10',
41
- 'x += 1 while x < 10',
42
- 'x += 1 until x < 10',
43
- ])
44
- expect(pac.offences.map(&:message)).to be_empty
29
+ inspect_source(pac, ['if x > 10',
30
+ 'end',
31
+ 'unless x > 10',
32
+ 'end',
33
+ 'while x > 10',
34
+ 'end',
35
+ 'until x > 10',
36
+ 'end',
37
+ 'x += 1 if x < 10',
38
+ 'x += 1 unless x < 10',
39
+ 'x += 1 while x < 10',
40
+ 'x += 1 until x < 10',
41
+ ])
42
+ expect(pac.offences).to be_empty
45
43
  end
46
44
 
47
- # Parentheses are sometimes used to help the editor make nice
48
- # indentation of conditions spanning several lines.
49
- it 'accepts parentheses around multiline conditions' do
50
- inspect_source(pac, 'file.rb', ['if (@lex_state != EXPR_BEG &&',
51
- ' @lex_state != EXPR_FNAME &&',
52
- ' trans[1])',
53
- 'end'])
54
- expect(pac.offences.map(&:message)).to be_empty
45
+ it 'is not confused by leading brace in subexpression' do
46
+ inspect_source(pac, ['(a > b) && other ? one : two'])
47
+ expect(pac.offences).to be_empty
55
48
  end
56
49
 
57
- it 'accepts parentheses around assignment' do
58
- inspect_source(pac, 'file.rb', ['if (x = self.next_value)',
59
- 'end'])
60
- expect(pac.offences.map(&:message)).to be_empty
61
- end
50
+ # Parentheses are sometimes used to help the editor make nice
51
+ # indentation of conditions spanning several lines.
52
+ # it 'accepts parentheses around multiline conditions' do
53
+ # inspect_source(pac, ['if (@lex_state != EXPR_BEG &&',
54
+ # ' @lex_state != EXPR_FNAME &&',
55
+ # ' trans[1])',
56
+ # 'end'])
57
+ # expect(pac.offences.map(&:message)).to be_empty
58
+ # end
62
59
  end
63
60
  end
64
61
  end
@@ -8,20 +8,20 @@ module Rubocop
8
8
  let(:apr) { PercentR.new }
9
9
 
10
10
  it 'registers an offence for %r with zero or one slash in regexp' do
11
- inspect_source(apr, 'file.rb', ['x =~ %r(/home)',
12
- 'y =~ %r(etc)'])
11
+ inspect_source(apr, ['x =~ %r(/home)',
12
+ 'y =~ %r(etc)'])
13
13
  expect(apr.offences.map(&:message))
14
- .to eq([PercentR::ERROR_MESSAGE] * 2)
14
+ .to eq([PercentR::MSG] * 2)
15
15
  end
16
16
 
17
17
  it 'accepts %r with at least two slashes in regexp' do
18
- inspect_source(apr, 'file.rb', ['x =~ %r(/home/)',
19
- 'y =~ %r(/////)'])
18
+ inspect_source(apr, ['x =~ %r(/home/)',
19
+ 'y =~ %r(/////)'])
20
20
  expect(apr.offences.map(&:message)).to be_empty
21
21
  end
22
22
 
23
23
  it 'accepts slash delimiters for regexp' do
24
- inspect_source(apr, 'file.rb', ['x =~ /\/home/'])
24
+ inspect_source(apr, ['x =~ /\/home/'])
25
25
  expect(apr.offences.map(&:message)).to be_empty
26
26
  end
27
27
  end
@@ -8,7 +8,7 @@ module Rubocop
8
8
  let(:reduce_arguments) { ReduceArguments.new }
9
9
 
10
10
  it 'find wrong argument names in calls with different syntax' do
11
- inspect_source(reduce_arguments, '',
11
+ inspect_source(reduce_arguments,
12
12
  ['def m',
13
13
  ' [0, 1].reduce { |c, d| c + d }',
14
14
  ' [0, 1].reduce{ |c, d| c + d }',
@@ -23,7 +23,7 @@ module Rubocop
23
23
  end
24
24
 
25
25
  it 'allows calls with proper argument names' do
26
- inspect_source(reduce_arguments, '',
26
+ inspect_source(reduce_arguments,
27
27
  ['def m',
28
28
  ' [0, 1].reduce { |a, e| a + e }',
29
29
  ' [0, 1].reduce{ |a, e| a + e }',
@@ -36,7 +36,7 @@ module Rubocop
36
36
  end
37
37
 
38
38
  it 'ignores do..end blocks' do
39
- inspect_source(reduce_arguments, '',
39
+ inspect_source(reduce_arguments,
40
40
  ['def m',
41
41
  ' [0, 1].reduce do |c, d|',
42
42
  ' c + d',
@@ -46,7 +46,7 @@ module Rubocop
46
46
  end
47
47
 
48
48
  it 'ignores :reduce symbols' do
49
- inspect_source(reduce_arguments, '',
49
+ inspect_source(reduce_arguments,
50
50
  ['def m',
51
51
  ' call_method(:reduce) { |a, b| a + b}',
52
52
  'end'])
@@ -9,7 +9,6 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for rescue from Exception' do
11
11
  inspect_source(re,
12
- 'file.rb',
13
12
  ['begin',
14
13
  ' something',
15
14
  'rescue Exception',
@@ -17,12 +16,35 @@ module Rubocop
17
16
  'end'])
18
17
  expect(re.offences.size).to eq(1)
19
18
  expect(re.offences.map(&:message))
20
- .to eq([RescueException::ERROR_MESSAGE])
19
+ .to eq([RescueException::MSG])
20
+ end
21
+
22
+ it 'registers an offence for rescue with ::Exception' do
23
+ inspect_source(re,
24
+ ['begin',
25
+ ' something',
26
+ 'rescue ::Exception',
27
+ ' #do nothing',
28
+ 'end'])
29
+ expect(re.offences.size).to eq(1)
30
+ expect(re.offences.map(&:message))
31
+ .to eq([RescueException::MSG])
32
+ end
33
+
34
+ it 'registers an offence for rescue with StandardError, Exception' do
35
+ inspect_source(re,
36
+ ['begin',
37
+ ' something',
38
+ 'rescue StandardError, Exception',
39
+ ' #do nothing',
40
+ 'end'])
41
+ expect(re.offences.size).to eq(1)
42
+ expect(re.offences.map(&:message))
43
+ .to eq([RescueException::MSG])
21
44
  end
22
45
 
23
46
  it 'registers an offence for rescue with Exception => e' do
24
47
  inspect_source(re,
25
- 'file.rb',
26
48
  ['begin',
27
49
  ' something',
28
50
  'rescue Exception => e',
@@ -30,12 +52,33 @@ module Rubocop
30
52
  'end'])
31
53
  expect(re.offences.size).to eq(1)
32
54
  expect(re.offences.map(&:message))
33
- .to eq([RescueException::ERROR_MESSAGE])
55
+ .to eq([RescueException::MSG])
56
+ end
57
+
58
+ it 'does not register an offence for rescue with no class' do
59
+ inspect_source(re,
60
+ ['begin',
61
+ ' something',
62
+ ' return',
63
+ 'rescue',
64
+ ' file.close',
65
+ 'end'])
66
+ expect(re.offences).to be_empty
67
+ end
68
+
69
+ it 'does not register an offence for rescue with no class and => e' do
70
+ inspect_source(re,
71
+ ['begin',
72
+ ' something',
73
+ ' return',
74
+ 'rescue => e',
75
+ ' file.close',
76
+ 'end'])
77
+ expect(re.offences).to be_empty
34
78
  end
35
79
 
36
80
  it 'does not register an offence for rescue with other class' do
37
81
  inspect_source(re,
38
- 'file.rb',
39
82
  ['begin',
40
83
  ' something',
41
84
  ' return',
@@ -47,7 +90,6 @@ module Rubocop
47
90
 
48
91
  it 'does not register an offence for rescue with other classes' do
49
92
  inspect_source(re,
50
- 'file.rb',
51
93
  ['begin',
52
94
  ' something',
53
95
  ' return',
@@ -59,7 +101,6 @@ module Rubocop
59
101
 
60
102
  it 'does not register an offence for rescue with a module prefix' do
61
103
  inspect_source(re,
62
- 'file.rb',
63
104
  ['begin',
64
105
  ' something',
65
106
  ' return',
@@ -71,7 +112,6 @@ module Rubocop
71
112
 
72
113
  it 'does not crash when the splat operator is used in a rescue' do
73
114
  inspect_source(re,
74
- 'file.rb',
75
115
  ['ERRORS = [Exception]',
76
116
  'begin',
77
117
  ' a = 3 / 0',
@@ -9,25 +9,22 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for modifier rescue' do
11
11
  inspect_source(rm,
12
- 'file.rb',
13
12
  ['method rescue handle'])
14
13
  expect(rm.offences.size).to eq(1)
15
14
  expect(rm.offences.map(&:message))
16
- .to eq([RescueModifier::ERROR_MESSAGE])
15
+ .to eq([RescueModifier::MSG])
17
16
  end
18
17
 
19
18
  it 'handles more complex expression with modifier rescue' do
20
19
  inspect_source(rm,
21
- 'file.rb',
22
20
  ['method1 or method2 rescue handle'])
23
21
  expect(rm.offences.size).to eq(1)
24
22
  expect(rm.offences.map(&:message))
25
- .to eq([RescueModifier::ERROR_MESSAGE])
23
+ .to eq([RescueModifier::MSG])
26
24
  end
27
25
 
28
26
  it 'does not register an offence for normal rescue' do
29
27
  inspect_source(rm,
30
- 'file.rb',
31
28
  ['begin',
32
29
  ' test',
33
30
  'rescue',
@@ -15,62 +15,38 @@ module Rubocop
15
15
 
16
16
  it 'registers an offence for a single expression' do
17
17
  inspect_source(s,
18
- 'file.rb',
19
18
  ['puts "this is a test";'])
20
19
  expect(s.offences.size).to eq(1)
21
- expect(s.offences.map(&:message)).to eq([Semicolon::ERROR_MESSAGE])
20
+ expect(s.offences.map(&:message)).to eq([Semicolon::MSG])
22
21
  end
23
22
 
24
23
  it 'registers an offence for several expressions' do
25
24
  inspect_source(s,
26
- 'file.rb',
27
25
  ['puts "this is a test"; puts "So is this"'])
28
26
  expect(s.offences.size).to eq(1)
29
- expect(s.offences.map(&:message)).to eq([Semicolon::ERROR_MESSAGE])
27
+ expect(s.offences.map(&:message)).to eq([Semicolon::MSG])
30
28
  end
31
29
 
32
30
  it 'registers an offence for one line method with two statements' do
33
31
  inspect_source(s,
34
- 'file.rb',
35
32
  ['def foo(a) x(1); y(2); z(3); end'])
36
- expect(s.offences.size).to eq(2)
37
- end
38
-
39
- it 'registers an offence for semicolon before end if so configured' do
40
- Semicolon.config['AllowBeforeEndInOneLineMethods'] = false
41
- inspect_source(s,
42
- 'file.rb',
43
- ['def foo(a) z(3); end'])
44
33
  expect(s.offences.size).to eq(1)
45
34
  end
46
35
 
47
36
  it 'accepts semicolon before end if so configured' do
48
37
  inspect_source(s,
49
- 'file.rb',
50
38
  ['def foo(a) z(3); end'])
51
39
  expect(s.offences).to be_empty
52
40
  end
53
41
 
54
- it 'registers an offence for semicolon after params if so configured' do
55
- inspect_source(s,
56
- 'file.rb',
57
- ['def foo(a); y(2); z(3) end',
58
- 'def bar(a) y(2); z(3) end'])
59
- expect(s.offences.size).to eq(3)
60
- end
61
-
62
42
  it 'accepts semicolon after params if so configured' do
63
- Semicolon.config['AllowAfterParameterListInOneLineMethods'] = true
64
43
  inspect_source(s,
65
- 'file.rb',
66
44
  ['def foo(a); z(3) end'])
67
45
  expect(s.offences).to be_empty
68
46
  end
69
47
 
70
48
  it 'accepts one line method definitions' do
71
- Semicolon.config['AllowAfterParameterListInOneLineMethods'] = true
72
49
  inspect_source(s,
73
- 'file.rb',
74
50
  ['def foo1; x(3) end',
75
51
  'def initialize(*_); end',
76
52
  'def foo2() x(3); end',
@@ -80,7 +56,6 @@ module Rubocop
80
56
 
81
57
  it 'accepts one line empty class definitions' do
82
58
  inspect_source(s,
83
- 'file.rb',
84
59
  ['# Prefer a single-line format for class ...',
85
60
  'class Foo < Exception; end',
86
61
  '',
@@ -90,7 +65,6 @@ module Rubocop
90
65
 
91
66
  it 'accepts one line empty method definitions' do
92
67
  inspect_source(s,
93
- 'file.rb',
94
68
  ['# One exception to the rule are empty-body methods',
95
69
  'def no_op; end',
96
70
  '',
@@ -100,14 +74,12 @@ module Rubocop
100
74
 
101
75
  it 'accepts one line empty module definitions' do
102
76
  inspect_source(s,
103
- 'file.rb',
104
77
  ['module Foo; end'])
105
78
  expect(s.offences).to be_empty
106
79
  end
107
80
 
108
81
  it 'registers an offence for semicolon at the end no matter what' do
109
82
  inspect_source(s,
110
- 'file.rb',
111
83
  ['module Foo; end;'])
112
84
  expect(s.offences.size).to eq(1)
113
85
  end