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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Version
5
- STRING = '0.7.2'
5
+ STRING = '0.8.0'
6
6
  end
7
7
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.summary = 'Automatic Ruby code style checking tool.'
29
29
 
30
30
  s.add_runtime_dependency('rainbow', '>= 1.1.4')
31
+ s.add_runtime_dependency('parser', '~> 2.0.0.beta2')
31
32
  s.add_development_dependency('rake', '~> 10.0')
32
33
  s.add_development_dependency('rspec', '~> 2.13')
33
34
  s.add_development_dependency('yard', '~> 0.8')
@@ -11,7 +11,7 @@ describe 'RuboCop Project' do
11
11
  end
12
12
  end
13
13
 
14
- describe 'source codes' do
14
+ describe 'source codes', broken: true do
15
15
  before { $stdout = StringIO.new }
16
16
  after { $stdout = STDOUT }
17
17
 
@@ -176,17 +176,22 @@ module Rubocop
176
176
  end
177
177
 
178
178
  it 'runs just one cop if --only is passed' do
179
- create_file('example.rb', [
180
- 'x= 0 ',
181
- 'y '
182
- ])
183
- expect(cli.run(['--only', 'TrailingWhitespace', 'example.rb'])).to eq(1)
179
+ create_file('example.rb', ['if x== 0 ',
180
+ "\ty",
181
+ 'end'])
182
+ # IfUnlessModifier depends on the configuration of LineLength.
183
+ # That configuration might have been set by other spec examples
184
+ # so we reset it to emulate a start from scratch.
185
+ Cop::LineLength.config = nil
186
+
187
+ expect(cli.run(['--only', 'IfUnlessModifier', 'example.rb'])).to eq(1)
184
188
  expect($stdout.string)
185
189
  .to eq(['== example.rb ==',
186
- 'C: 1: Trailing whitespace detected.',
187
- 'C: 2: Trailing whitespace detected.',
190
+ 'C: 1: Favor modifier if/unless usage when you have a ' +
191
+ 'single-line body. Another good alternative is the usage of ' +
192
+ 'control flow &&/||.',
188
193
  '',
189
- '1 file inspected, 2 offences detected',
194
+ '1 file inspected, 1 offence detected',
190
195
  ''].join("\n"))
191
196
  end
192
197
 
@@ -400,6 +405,7 @@ module Rubocop
400
405
  end
401
406
 
402
407
  it 'registers an offence for a syntax error' do
408
+ pending
403
409
  create_file('example.rb', [
404
410
  '# encoding: utf-8',
405
411
  'class Test',
@@ -416,9 +422,10 @@ module Rubocop
416
422
  end
417
423
 
418
424
  it 'can process a file with an invalid UTF-8 byte sequence' do
425
+ pending
419
426
  create_file('example.rb', [
420
427
  '# encoding: utf-8',
421
- "# \xf9\x29"
428
+ "# #{'f9'.hex.chr}#{'29'.hex.chr}"
422
429
  ])
423
430
  expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
424
431
  end
@@ -208,7 +208,7 @@ describe Rubocop::Config do
208
208
  end
209
209
  end
210
210
 
211
- describe '#validate!', :isolated_environment do
211
+ describe '#validate', :isolated_environment do
212
212
  # TODO: Because Config.load_file now outputs the validation warning,
213
213
  # it is inserting text into the rspec test output here.
214
214
  # The next 2 lines should be removed eventually.
@@ -232,7 +232,7 @@ describe Rubocop::Config do
232
232
 
233
233
  it 'raises validation error' do
234
234
  expect do
235
- configuration.validate!
235
+ configuration.validate
236
236
  end.to raise_error(Rubocop::Config::ValidationError) do |error|
237
237
  expect(error.message).to start_with('unrecognized cop LyneLenth')
238
238
  end
@@ -250,7 +250,7 @@ describe Rubocop::Config do
250
250
 
251
251
  it 'raises validation error' do
252
252
  expect do
253
- configuration.validate!
253
+ configuration.validate
254
254
  end.to raise_error(Rubocop::Config::ValidationError) do |error|
255
255
  expect(error.message).to
256
256
  start_with('unrecognized parameter LineLength:Min')
@@ -396,4 +396,14 @@ describe Rubocop::Config do
396
396
  end
397
397
  end
398
398
  end
399
+
400
+ describe 'configuration for SymbolName' do
401
+ describe 'AllowCamelCase' do
402
+ it 'is enabled by default' do
403
+ default_config = Rubocop::Config.default_configuration
404
+ symbol_name_config = default_config.for_cop('SymbolName')
405
+ expect(symbol_name_config['AllowCamelCase']).to be_true
406
+ end
407
+ end
408
+ end
399
409
  end
@@ -0,0 +1,129 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ module Rubocop
6
+ module Cop
7
+ describe AccessControl do
8
+ let(:a) { AccessControl.new }
9
+
10
+ it 'registers an offence for misaligned private' do
11
+ inspect_source(a,
12
+ ['class Test',
13
+ '',
14
+ 'private',
15
+ '',
16
+ ' def test; end',
17
+ 'end'])
18
+ expect(a.offences.size).to eq(1)
19
+ expect(a.offences.map(&:message))
20
+ .to eq([AccessControl::INDENT_MSG])
21
+ end
22
+
23
+ it 'registers an offence for misaligned private in module' do
24
+ inspect_source(a,
25
+ ['module Test',
26
+ '',
27
+ 'private',
28
+ '',
29
+ ' def test; end',
30
+ 'end'])
31
+ expect(a.offences.size).to eq(1)
32
+ expect(a.offences.map(&:message))
33
+ .to eq([AccessControl::INDENT_MSG])
34
+ end
35
+
36
+ it 'registers an offence for misaligned private in singleton class' do
37
+ inspect_source(a,
38
+ ['class << self',
39
+ '',
40
+ 'private',
41
+ '',
42
+ ' def test; end',
43
+ 'end'])
44
+ expect(a.offences.size).to eq(1)
45
+ expect(a.offences.map(&:message))
46
+ .to eq([AccessControl::INDENT_MSG])
47
+ end
48
+
49
+ it 'registers an offence for misaligned protected' do
50
+ inspect_source(a,
51
+ ['class Test',
52
+ '',
53
+ 'protected',
54
+ '',
55
+ ' def test; end',
56
+ 'end'])
57
+ expect(a.offences.size).to eq(1)
58
+ expect(a.offences.map(&:message))
59
+ .to eq([AccessControl::INDENT_MSG])
60
+ end
61
+
62
+ it 'accepts properly indented private' do
63
+ inspect_source(a,
64
+ ['class Test',
65
+ '',
66
+ ' private',
67
+ '',
68
+ ' def test; end',
69
+ 'end'])
70
+ expect(a.offences).to be_empty
71
+ end
72
+
73
+ it 'accepts properly indented protected' do
74
+ inspect_source(a,
75
+ ['class Test',
76
+ '',
77
+ ' protected',
78
+ '',
79
+ ' def test; end',
80
+ 'end'])
81
+ expect(a.offences).to be_empty
82
+ end
83
+
84
+ it 'handles properly nested classes' do
85
+ inspect_source(a,
86
+ ['class Test',
87
+ '',
88
+ ' class Nested',
89
+ '',
90
+ ' private',
91
+ '',
92
+ ' def a; end',
93
+ ' end',
94
+ '',
95
+ ' protected',
96
+ '',
97
+ ' def test; end',
98
+ 'end'])
99
+ expect(a.offences.size).to eq(1)
100
+ expect(a.offences.map(&:message))
101
+ .to eq([AccessControl::INDENT_MSG])
102
+ end
103
+
104
+ it 'requires blank line before private/protected' do
105
+ inspect_source(a,
106
+ ['class Test',
107
+ ' protected',
108
+ '',
109
+ ' def test; end',
110
+ 'end'])
111
+ expect(a.offences.size).to eq(1)
112
+ expect(a.offences.map(&:message))
113
+ .to eq([AccessControl::BLANK_MSG])
114
+ end
115
+
116
+ it 'requires blank line after private/protected' do
117
+ inspect_source(a,
118
+ ['class Test',
119
+ '',
120
+ ' protected',
121
+ ' def test; end',
122
+ 'end'])
123
+ expect(a.offences.size).to eq(1)
124
+ expect(a.offences.map(&:message))
125
+ .to eq([AccessControl::BLANK_MSG])
126
+ end
127
+ end
128
+ end
129
+ end
@@ -9,32 +9,28 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for alias with symbol args' do
11
11
  inspect_source(a,
12
- 'file.rb',
13
12
  ['alias :ala :bala'])
14
13
  expect(a.offences.size).to eq(1)
15
14
  expect(a.offences.map(&:message))
16
- .to eq([Alias::ERROR_MESSAGE])
15
+ .to eq([Alias::MSG])
17
16
  end
18
17
 
19
18
  it 'registers an offence for alias with bareword args' do
20
19
  inspect_source(a,
21
- 'file.rb',
22
20
  ['alias ala bala'])
23
21
  expect(a.offences.size).to eq(1)
24
22
  expect(a.offences.map(&:message))
25
- .to eq([Alias::ERROR_MESSAGE])
23
+ .to eq([Alias::MSG])
26
24
  end
27
25
 
28
26
  it 'does not register an offence for alias_method' do
29
27
  inspect_source(a,
30
- 'file.rb',
31
28
  ['alias_method :ala, :bala'])
32
29
  expect(a.offences).to be_empty
33
30
  end
34
31
 
35
32
  it 'does not register an offence for :alias' do
36
33
  inspect_source(a,
37
- 'file.rb',
38
34
  ['[:alias, :ala, :bala]'])
39
35
  expect(a.offences).to be_empty
40
36
  end
@@ -8,43 +8,45 @@ module Rubocop
8
8
  let(:align) { AlignParameters.new }
9
9
 
10
10
  it 'registers an offence for parameters with single indent' do
11
- inspect_source(align, 'file.rb', ['function(a,',
12
- ' if b then c else d end)'])
13
- expect(align.offences.map(&:message)).to eq(
14
- ['Align the parameters of a method call if they span more than ' +
15
- 'one line.'])
11
+ inspect_source(align, ['function(a,',
12
+ ' if b then c else d end)'])
13
+ expect(align.offences.size).to eq(1)
16
14
  end
17
15
 
18
16
  it 'registers an offence for parameters with double indent' do
19
- inspect_source(align, 'file.rb', ['function(a,',
20
- ' if b then c else d end)'])
21
- expect(align.offences.map(&:message)).to eq(
22
- ['Align the parameters of a method call if they span more than ' +
23
- 'one line.'])
17
+ inspect_source(align, ['function(a,',
18
+ ' if b then c else d end)'])
19
+ expect(align.offences.size).to eq(1)
20
+ end
21
+
22
+ it 'accepts multiline []= method call' do
23
+ inspect_source(align, ['Test.config["something"] =',
24
+ ' true'])
25
+ expect(align.offences).to be_empty
24
26
  end
25
27
 
26
28
  it 'accepts correctly aligned parameters' do
27
- inspect_source(align, 'file.rb', ['function(a,',
28
- ' 0, 1,',
29
- ' (x + y),',
30
- ' if b then c else d end)'])
31
- expect(align.offences.map(&:message)).to be_empty
29
+ inspect_source(align, ['function(a,',
30
+ ' 0, 1,',
31
+ ' (x + y),',
32
+ ' if b then c else d end)'])
33
+ expect(align.offences).to be_empty
32
34
  end
33
35
 
34
36
  it 'accepts calls that only span one line' do
35
- inspect_source(align, 'file.rb', ['find(path, s, @special[sexp[0]])'])
36
- expect(align.offences.map(&:message)).to be_empty
37
+ inspect_source(align, ['find(path, s, @special[sexp[0]])'])
38
+ expect(align.offences).to be_empty
37
39
  end
38
40
 
39
41
  it "doesn't get confused by a symbol argument" do
40
- inspect_source(align, '',
42
+ inspect_source(align,
41
43
  ['add_offence(:convention, index,',
42
- ' ERROR_MESSAGE % kind)'])
43
- expect(align.offences.map(&:message)).to be_empty
44
+ ' MSG % kind)'])
45
+ expect(align.offences).to be_empty
44
46
  end
45
47
 
46
48
  it "doesn't get confused by splat operator" do
47
- inspect_source(align, '',
49
+ inspect_source(align,
48
50
  ['func1(*a,',
49
51
  ' *b,',
50
52
  ' c)',
@@ -59,7 +61,7 @@ module Rubocop
59
61
  end
60
62
 
61
63
  it "doesn't get confused by extra comma at the end" do
62
- inspect_source(align, '',
64
+ inspect_source(align,
63
65
  ['func1(a,',
64
66
  ' b,)'])
65
67
  expect(align.offences.map(&:to_s)).to eq(
@@ -68,52 +70,52 @@ module Rubocop
68
70
  end
69
71
 
70
72
  it 'can handle a correctly aligned string literal as first argument' do
71
- inspect_source(align, '',
73
+ inspect_source(align,
72
74
  ['add_offence(:convention, x,',
73
75
  ' a)'])
74
- expect(align.offences.map(&:message)).to be_empty
76
+ expect(align.offences).to be_empty
75
77
  end
76
78
 
77
79
  it 'can handle a string literal as other argument' do
78
- inspect_source(align, '',
80
+ inspect_source(align,
79
81
  ['add_offence(:convention,',
80
82
  ' "", a)'])
81
- expect(align.offences.map(&:message)).to be_empty
83
+ expect(align.offences).to be_empty
82
84
  end
83
85
 
84
86
  it "doesn't get confused by a line break inside a parameter" do
85
- inspect_source(align, '',
87
+ inspect_source(align,
86
88
  ['read(path, { headers: true,',
87
89
  ' converters: :numeric })'])
88
- expect(align.offences.map(&:message)).to be_empty
90
+ expect(align.offences).to be_empty
89
91
  end
90
92
 
91
93
  it "doesn't get confused by symbols with embedded expressions" do
92
- inspect_source(align, '',
94
+ inspect_source(align,
93
95
  ['send(:"#{name}_comments_path")'])
94
- expect(align.offences.map(&:message)).to be_empty
96
+ expect(align.offences).to be_empty
95
97
  end
96
98
 
97
99
  it "doesn't get confused by regexen with embedded expressions" do
98
- inspect_source(align, '',
100
+ inspect_source(align,
99
101
  ['a(/#{name}/)'])
100
- expect(align.offences.map(&:message)).to be_empty
102
+ expect(align.offences).to be_empty
101
103
  end
102
104
 
103
105
  it 'accepts braceless hashes' do
104
- inspect_source(align, '',
106
+ inspect_source(align,
105
107
  ['run(collection, :entry_name => label,',
106
108
  ' :paginator => paginator)'])
107
- expect(align.offences.map(&:message)).to be_empty
109
+ expect(align.offences).to be_empty
108
110
  end
109
111
 
110
112
  it 'accepts the first parameter being on a new row' do
111
- inspect_source(align, '',
113
+ inspect_source(align,
112
114
  [' match(',
113
115
  ' a,',
114
116
  ' b',
115
117
  ' )'])
116
- expect(align.offences.map(&:message)).to be_empty
118
+ expect(align.offences).to be_empty
117
119
  end
118
120
 
119
121
  it 'can handle heredoc strings' do
@@ -123,31 +125,31 @@ module Rubocop
123
125
  ' return value',
124
126
  ' end',
125
127
  ' EOS']
126
- inspect_source(align, '', src)
127
- expect(align.offences.map(&:message)).to be_empty
128
+ inspect_source(align, src)
129
+ expect(align.offences).to be_empty
128
130
  end
129
131
 
130
132
  it 'can handle a method call within a method call' do
131
- inspect_source(align, '',
133
+ inspect_source(align,
132
134
  ['a(a1,',
133
135
  ' b(b1,',
134
136
  ' b2),',
135
137
  ' a2)'])
136
- expect(align.offences.map(&:message)).to be_empty
138
+ expect(align.offences).to be_empty
137
139
  end
138
140
 
139
141
  it 'can handle a call embedded in a string' do
140
- inspect_source(align, '',
142
+ inspect_source(align,
141
143
  ['model("#{index(name)}", child)'])
142
- expect(align.offences.map(&:message)).to be_empty
144
+ expect(align.offences).to be_empty
143
145
  end
144
146
 
145
147
  it 'can handle do-end' do
146
- inspect_source(align, '',
148
+ inspect_source(align,
147
149
  [' run(lambda do |e|',
148
150
  " w = e['warden']",
149
151
  ' end)'])
150
- expect(align.offences.map(&:message)).to be_empty
152
+ expect(align.offences).to be_empty
151
153
  end
152
154
 
153
155
  it 'can handle a call with a block inside another call' do
@@ -155,55 +157,40 @@ module Rubocop
155
157
  ' exec_query("info(\'#{row[\'name\']}\')").map { |col|',
156
158
  " col['name']",
157
159
  ' })']
158
- inspect_source(align, '', src)
159
- expect(align.offences.map(&:message)).to be_empty
160
+ inspect_source(align, src)
161
+ expect(align.offences).to be_empty
160
162
  end
161
163
 
162
164
  it 'can handle a ternary condition with a block reference' do
163
165
  src = ['cond ? a : func(&b)']
164
- inspect_source(align, '', src)
165
- expect(align.offences.map(&:message)).to be_empty
166
+ inspect_source(align, src)
167
+ expect(align.offences).to be_empty
166
168
  end
167
169
 
168
170
  it 'can handle parentheses used with no parameters' do
169
171
  src = ['func()']
170
- inspect_source(align, '', src)
171
- expect(align.offences.map(&:message)).to be_empty
172
- end
173
-
174
- it 'can handle a multiline hash as first parameter' do
175
- src = ['assert_equal({',
176
- ' :space_before => "",',
177
- '}, state)']
178
- inspect_source(align, '', src)
179
- expect(align.offences.map(&:message)).to be_empty
172
+ inspect_source(align, src)
173
+ expect(align.offences).to be_empty
180
174
  end
181
175
 
182
176
  it 'can handle a multiline hash as second parameter' do
183
177
  src = ['tag(:input, {',
184
178
  ' :value => value',
185
179
  '})']
186
- inspect_source(align, '', src)
187
- expect(align.offences.map(&:message)).to be_empty
180
+ inspect_source(align, src)
181
+ expect(align.offences).to be_empty
188
182
  end
189
183
 
190
184
  it 'can handle method calls without parentheses' do
191
185
  src = ['a(b c, d)']
192
- inspect_source(align, '', src)
193
- expect(align.offences.map(&:message)).to be_empty
186
+ inspect_source(align, src)
187
+ expect(align.offences).to be_empty
194
188
  end
195
189
 
196
190
  it 'can handle other method calls without parentheses' do
197
191
  src = ['chars(Unicode.apply_mapping @wrapped_string, :uppercase)']
198
- inspect_source(align, '', src)
199
- expect(align.offences.map(&:message)).to be_empty
200
- end
201
-
202
- it "doesn't check alignment if tabs are used to indent" do
203
- src = ['a(b,',
204
- "\tc)"]
205
- inspect_source(align, '', src)
206
- expect(align.offences.map(&:message)).to be_empty
192
+ inspect_source(align, src)
193
+ expect(align.offences).to be_empty
207
194
  end
208
195
  end
209
196
  end