rubocop 0.26.1 → 0.27.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.rubocop_todo.yml +10 -6
  4. data/.travis.yml +2 -0
  5. data/CHANGELOG.md +30 -0
  6. data/README.md +9 -2
  7. data/assets/logo.png +0 -0
  8. data/assets/output.html.erb +68 -65
  9. data/config/default.yml +42 -7
  10. data/config/disabled.yml +5 -0
  11. data/config/enabled.yml +32 -7
  12. data/lib/rubocop.rb +10 -2
  13. data/lib/rubocop/comment_config.rb +11 -17
  14. data/lib/rubocop/config.rb +20 -16
  15. data/lib/rubocop/config_loader.rb +8 -12
  16. data/lib/rubocop/cop/cop.rb +13 -12
  17. data/lib/rubocop/cop/lint/block_alignment.rb +4 -6
  18. data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
  19. data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
  20. data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -3
  21. data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
  22. data/lib/rubocop/cop/metrics/abc_size.rb +27 -0
  23. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -4
  24. data/lib/rubocop/cop/metrics/class_length.rb +1 -1
  25. data/lib/rubocop/cop/metrics/line_length.rb +2 -5
  26. data/lib/rubocop/cop/metrics/method_length.rb +2 -2
  27. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +24 -15
  28. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +15 -2
  29. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +63 -0
  30. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  31. data/lib/rubocop/cop/mixin/if_node.rb +3 -1
  32. data/lib/rubocop/cop/mixin/method_complexity.rb +3 -3
  33. data/lib/rubocop/cop/mixin/{on_method.rb → on_method_def.rb} +3 -3
  34. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
  35. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  36. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
  37. data/lib/rubocop/cop/mixin/string_literals_help.rb +28 -0
  38. data/lib/rubocop/cop/rails/delegate.rb +2 -2
  39. data/lib/rubocop/cop/style/access_modifier_indentation.rb +2 -2
  40. data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
  41. data/lib/rubocop/cop/style/align_hash.rb +16 -12
  42. data/lib/rubocop/cop/style/align_parameters.rb +1 -1
  43. data/lib/rubocop/cop/style/and_or.rb +14 -6
  44. data/lib/rubocop/cop/style/array_join.rb +1 -1
  45. data/lib/rubocop/cop/style/block_comments.rb +16 -8
  46. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -30
  47. data/lib/rubocop/cop/style/case_indentation.rb +20 -12
  48. data/lib/rubocop/cop/style/collection_methods.rb +4 -4
  49. data/lib/rubocop/cop/style/colon_method_call.rb +9 -0
  50. data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
  51. data/lib/rubocop/cop/style/comment_indentation.rb +22 -22
  52. data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -2
  53. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
  54. data/lib/rubocop/cop/style/double_negation.rb +6 -1
  55. data/lib/rubocop/cop/style/else_alignment.rb +93 -0
  56. data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
  57. data/lib/rubocop/cop/style/empty_lines.rb +1 -1
  58. data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +34 -0
  59. data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +37 -0
  60. data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +30 -0
  61. data/lib/rubocop/cop/style/encoding.rb +1 -1
  62. data/lib/rubocop/cop/style/format_string.rb +4 -4
  63. data/lib/rubocop/cop/style/indent_array.rb +2 -2
  64. data/lib/rubocop/cop/style/indent_hash.rb +17 -12
  65. data/lib/rubocop/cop/style/indentation_width.rb +27 -19
  66. data/lib/rubocop/cop/style/method_call_parentheses.rb +3 -3
  67. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
  68. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -11
  69. data/lib/rubocop/cop/style/method_name.rb +1 -1
  70. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +174 -0
  71. data/lib/rubocop/cop/style/non_nil_check.rb +12 -15
  72. data/lib/rubocop/cop/style/not.rb +1 -1
  73. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +12 -17
  74. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  75. data/lib/rubocop/cop/style/predicate_name.rb +2 -2
  76. data/lib/rubocop/cop/style/redundant_begin.rb +2 -2
  77. data/lib/rubocop/cop/style/redundant_return.rb +3 -3
  78. data/lib/rubocop/cop/style/redundant_self.rb +3 -3
  79. data/lib/rubocop/cop/style/regexp_literal.rb +17 -13
  80. data/lib/rubocop/cop/style/rescue_modifier.rb +2 -2
  81. data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
  82. data/lib/rubocop/cop/style/space_after_method_name.rb +2 -2
  83. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +17 -11
  84. data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
  85. data/lib/rubocop/cop/style/space_inside_block_braces.rb +17 -14
  86. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +10 -6
  87. data/lib/rubocop/cop/style/string_literals.rb +13 -16
  88. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +41 -0
  89. data/lib/rubocop/cop/style/trailing_comma.rb +1 -3
  90. data/lib/rubocop/cop/style/trivial_accessors.rb +3 -3
  91. data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
  92. data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -2
  93. data/lib/rubocop/cop/style/word_array.rb +23 -19
  94. data/lib/rubocop/cop/team.rb +13 -26
  95. data/lib/rubocop/cop/util.rb +5 -0
  96. data/lib/rubocop/cop/variable_force/locatable.rb +7 -13
  97. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  98. data/lib/rubocop/formatter/formatter_set.rb +9 -1
  99. data/lib/rubocop/formatter/html_formatter.rb +83 -55
  100. data/lib/rubocop/formatter/simple_text_formatter.rb +2 -2
  101. data/lib/rubocop/formatter/text_util.rb +25 -0
  102. data/lib/rubocop/options.rb +14 -7
  103. data/lib/rubocop/path_util.rb +11 -7
  104. data/lib/rubocop/runner.rb +7 -2
  105. data/lib/rubocop/version.rb +1 -1
  106. data/relnotes/v0.27.0.md +77 -0
  107. data/rubocop.gemspec +1 -1
  108. data/spec/fixtures/html_formatter/expected.html +495 -0
  109. data/spec/fixtures/html_formatter/project/app/controllers/application_controller.rb +5 -0
  110. data/spec/fixtures/html_formatter/project/app/controllers/books_controller.rb +74 -0
  111. data/spec/fixtures/html_formatter/project/app/models/book.rb +5 -0
  112. data/spec/rubocop/cli_spec.rb +56 -13
  113. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +1 -1
  114. data/spec/rubocop/cop/metrics/abc_size_spec.rb +99 -0
  115. data/spec/rubocop/cop/rails/action_filter_spec.rb +1 -0
  116. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +23 -1
  117. data/spec/rubocop/cop/style/align_hash_spec.rb +13 -0
  118. data/spec/rubocop/cop/style/align_parameters_spec.rb +44 -33
  119. data/spec/rubocop/cop/style/blocks_spec.rb +8 -0
  120. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +9 -9
  121. data/spec/rubocop/cop/style/case_indentation_spec.rb +3 -2
  122. data/spec/rubocop/cop/style/colon_method_call_spec.rb +5 -0
  123. data/spec/rubocop/cop/style/comment_indentation_spec.rb +6 -1
  124. data/spec/rubocop/cop/style/else_alignment_spec.rb +437 -0
  125. data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +75 -0
  126. data/spec/rubocop/cop/style/{empty_lines_around_body_spec.rb → empty_lines_around_method_body_spec.rb} +9 -50
  127. data/spec/rubocop/cop/style/empty_lines_around_module_body_spec.rb +79 -0
  128. data/spec/rubocop/cop/style/file_name_spec.rb +1 -1
  129. data/spec/rubocop/cop/style/format_string_spec.rb +12 -0
  130. data/spec/rubocop/cop/style/indent_array_spec.rb +6 -1
  131. data/spec/rubocop/cop/style/indent_hash_spec.rb +2 -1
  132. data/spec/rubocop/cop/style/indentation_width_spec.rb +765 -722
  133. data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +414 -0
  134. data/spec/rubocop/cop/style/non_nil_check_spec.rb +86 -55
  135. data/spec/rubocop/cop/style/single_line_methods_spec.rb +5 -1
  136. data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +2 -1
  137. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +2 -1
  138. data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +63 -0
  139. data/spec/rubocop/cop/style/string_literals_spec.rb +2 -2
  140. data/spec/rubocop/cop/style/word_array_spec.rb +15 -1
  141. data/spec/rubocop/formatter/base_formatter_spec.rb +1 -1
  142. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +0 -1
  143. data/spec/rubocop/formatter/formatter_set_spec.rb +9 -0
  144. data/spec/rubocop/formatter/html_formatter_spec.rb +25 -122
  145. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +0 -1
  146. data/spec/rubocop/runner_spec.rb +1 -1
  147. data/spec/spec_helper.rb +12 -130
  148. data/spec/support/cop_helper.rb +72 -0
  149. data/spec/support/coverage.rb +15 -0
  150. data/spec/support/{offenses_matcher.rb → custom_matchers.rb} +28 -0
  151. data/spec/support/jruby_workaround.rb +15 -0
  152. data/spec/support/{isolated_environment.rb → shared_contexts.rb} +19 -0
  153. metadata +49 -14
  154. data/lib/rubocop/cop/style/empty_lines_around_body.rb +0 -75
  155. data/spec/support/shared_context.rb +0 -20
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RuboCop::Cop::Style::EmptyLinesAroundClassBody, :config do
6
+ subject(:cop) { described_class.new(config) }
7
+
8
+ context 'when EnforcedStyle is no_empty_lines' do
9
+ let(:cop_config) { { 'EnforcedStyle' => 'no_empty_lines' } }
10
+
11
+ it 'registers an offense for class body starting with a blank' do
12
+ inspect_source(cop,
13
+ ['class SomeClass',
14
+ '',
15
+ ' do_something',
16
+ 'end'])
17
+ expect(cop.messages)
18
+ .to eq(['Extra empty line detected at class body beginning.'])
19
+ end
20
+
21
+ it 'autocorrects class body containing only a blank' do
22
+ corrected = autocorrect_source(cop,
23
+ ['class SomeClass',
24
+ '',
25
+ 'end'])
26
+ expect(corrected).to eq ['class SomeClass',
27
+ 'end'].join("\n")
28
+ end
29
+
30
+ it 'registers an offense for class body ending with a blank' do
31
+ inspect_source(cop,
32
+ ['class SomeClass',
33
+ ' do_something',
34
+ '',
35
+ 'end'])
36
+ expect(cop.messages)
37
+ .to eq(['Extra empty line detected at class body end.'])
38
+ end
39
+ end
40
+
41
+ context 'when EnforcedStyle is empty_lines' do
42
+ let(:cop_config) { { 'EnforcedStyle' => 'empty_lines' } }
43
+
44
+ it 'registers an offense for class body not starting or ending with a ' \
45
+ 'blank' do
46
+ inspect_source(cop,
47
+ ['class SomeClass',
48
+ ' do_something',
49
+ 'end'])
50
+ expect(cop.messages).to eq(['Empty line missing at class body beginning.',
51
+ 'Empty line missing at class body end.'])
52
+ end
53
+
54
+ it 'autocorrects class body containing nothing' do
55
+ corrected = autocorrect_source(cop,
56
+ ['class SomeClass',
57
+ 'end'])
58
+ expect(corrected).to eq ['class SomeClass',
59
+ '',
60
+ 'end'].join("\n")
61
+ end
62
+
63
+ it 'autocorrects beginning and end' do
64
+ new_source = autocorrect_source(cop,
65
+ ['class SomeClass',
66
+ ' do_something',
67
+ 'end'])
68
+ expect(new_source).to eq(['class SomeClass',
69
+ '',
70
+ ' do_something',
71
+ '',
72
+ 'end'].join("\n"))
73
+ end
74
+ end
75
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RuboCop::Cop::Style::EmptyLinesAroundBody do
5
+ describe RuboCop::Cop::Style::EmptyLinesAroundMethodBody do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for method body starting with a blank' do
@@ -11,7 +11,8 @@ describe RuboCop::Cop::Style::EmptyLinesAroundBody do
11
11
  '',
12
12
  ' do_something',
13
13
  'end'])
14
- expect(cop.offenses.size).to eq(1)
14
+ expect(cop.messages)
15
+ .to eq(['Extra empty line detected at method body beginning.'])
15
16
  end
16
17
 
17
18
  # The cop only registers an offense if the extra line is completely emtpy. If
@@ -44,7 +45,8 @@ describe RuboCop::Cop::Style::EmptyLinesAroundBody do
44
45
  '',
45
46
  ' do_something',
46
47
  'end'])
47
- expect(cop.offenses.size).to eq(1)
48
+ expect(cop.messages)
49
+ .to eq(['Extra empty line detected at method body beginning.'])
48
50
  end
49
51
 
50
52
  it 'autocorrects class method body starting with a blank' do
@@ -64,7 +66,8 @@ describe RuboCop::Cop::Style::EmptyLinesAroundBody do
64
66
  ' do_something',
65
67
  '',
66
68
  'end'])
67
- expect(cop.offenses.size).to eq(1)
69
+ expect(cop.messages)
70
+ .to eq(['Extra empty line detected at method body end.'])
68
71
  end
69
72
 
70
73
  it 'registers an offense for class method body ending with a blank' do
@@ -73,52 +76,8 @@ describe RuboCop::Cop::Style::EmptyLinesAroundBody do
73
76
  ' do_something',
74
77
  '',
75
78
  'end'])
76
- expect(cop.offenses.size).to eq(1)
77
- end
78
-
79
- it 'registers an offense for class body starting with a blank' do
80
- inspect_source(cop,
81
- ['class SomeClass',
82
- '',
83
- ' do_something',
84
- 'end'])
85
- expect(cop.offenses.size).to eq(1)
86
- end
87
-
88
- it 'autocorrects class body containing only a blank' do
89
- corrected = autocorrect_source(cop,
90
- ['class SomeClass',
91
- '',
92
- 'end'])
93
- expect(corrected).to eq ['class SomeClass',
94
- 'end'].join("\n")
95
- end
96
-
97
- it 'registers an offense for module body starting with a blank' do
98
- inspect_source(cop,
99
- ['module SomeModule',
100
- '',
101
- ' do_something',
102
- 'end'])
103
- expect(cop.offenses.size).to eq(1)
104
- end
105
-
106
- it 'registers an offense for class body ending with a blank' do
107
- inspect_source(cop,
108
- ['class SomeClass',
109
- ' do_something',
110
- '',
111
- 'end'])
112
- expect(cop.offenses.size).to eq(1)
113
- end
114
-
115
- it 'registers an offense for module body ending with a blank' do
116
- inspect_source(cop,
117
- ['module SomeModule',
118
- ' do_something',
119
- '',
120
- 'end'])
121
- expect(cop.offenses.size).to eq(1)
79
+ expect(cop.messages)
80
+ .to eq(['Extra empty line detected at method body end.'])
122
81
  end
123
82
 
124
83
  it 'is not fooled by single line methods' do
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RuboCop::Cop::Style::EmptyLinesAroundModuleBody, :config do
6
+ subject(:cop) { described_class.new(config) }
7
+
8
+ context 'when EnforcedStyle is no_empty_lines' do
9
+ let(:cop_config) { { 'EnforcedStyle' => 'no_empty_lines' } }
10
+
11
+ it 'registers an offense for module body starting with a blank' do
12
+ inspect_source(cop,
13
+ ['module SomeModule',
14
+ '',
15
+ ' do_something',
16
+ 'end'])
17
+ expect(cop.messages)
18
+ .to eq(['Extra empty line detected at module body beginning.'])
19
+ end
20
+
21
+ it 'registers an offense for module body ending with a blank' do
22
+ inspect_source(cop,
23
+ ['module SomeModule',
24
+ ' do_something',
25
+ '',
26
+ 'end'])
27
+ expect(cop.messages)
28
+ .to eq(['Extra empty line detected at module body end.'])
29
+ end
30
+
31
+ it 'autocorrects beginning and end' do
32
+ new_source = autocorrect_source(cop,
33
+ ['module SomeModule',
34
+ '',
35
+ ' do_something',
36
+ '',
37
+ 'end'])
38
+ expect(new_source).to eq(['module SomeModule',
39
+ ' do_something',
40
+ 'end'].join("\n"))
41
+ end
42
+ end
43
+
44
+ context 'when EnforcedStyle is empty_lines' do
45
+ let(:cop_config) { { 'EnforcedStyle' => 'empty_lines' } }
46
+
47
+ it 'registers an offense for module body not starting or ending with a ' \
48
+ 'blank' do
49
+ inspect_source(cop,
50
+ ['module SomeModule',
51
+ ' do_something',
52
+ 'end'])
53
+ expect(cop.messages)
54
+ .to eq(['Empty line missing at module body beginning.',
55
+ 'Empty line missing at module body end.'])
56
+ end
57
+
58
+ it 'registers an offense for module body not ending with a blank' do
59
+ inspect_source(cop,
60
+ ['module SomeModule',
61
+ '',
62
+ ' do_something',
63
+ 'end'])
64
+ expect(cop.messages).to eq(['Empty line missing at module body end.'])
65
+ end
66
+
67
+ it 'autocorrects beginning and end' do
68
+ new_source = autocorrect_source(cop,
69
+ ['module SomeModule',
70
+ ' do_something',
71
+ 'end'])
72
+ expect(new_source).to eq(['module SomeModule',
73
+ '',
74
+ ' do_something',
75
+ '',
76
+ 'end'].join("\n"))
77
+ end
78
+ end
79
+ end
@@ -18,7 +18,7 @@ describe RuboCop::Cop::Style::FileName do
18
18
 
19
19
  before do
20
20
  allow(processed_source.buffer)
21
- .to receive(:name).and_return(filename)
21
+ .to receive(:name).and_return(filename)
22
22
  _investigate(cop, processed_source)
23
23
  end
24
24
 
@@ -139,6 +139,18 @@ describe RuboCop::Cop::Style::FormatString, :config do
139
139
  expect(cop.offenses).to be_empty
140
140
  end
141
141
 
142
+ it 'accepts format without arguments' do
143
+ inspect_source(cop,
144
+ ['format'])
145
+ expect(cop.offenses).to be_empty
146
+ end
147
+
148
+ it 'accepts sprintf without arguments' do
149
+ inspect_source(cop,
150
+ ['sprintf'])
151
+ expect(cop.offenses).to be_empty
152
+ end
153
+
142
154
  it 'accepts String#%' do
143
155
  inspect_source(cop,
144
156
  ['puts "%d" % 10'])
@@ -3,7 +3,12 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RuboCop::Cop::Style::IndentArray do
6
- subject(:cop) { described_class.new }
6
+ subject(:cop) { described_class.new(config) }
7
+ let(:config) do
8
+ RuboCop::Config
9
+ .new('Style/IndentationWidth' => { 'Width' => indentation_width })
10
+ end
11
+ let(:indentation_width) { 2 }
7
12
 
8
13
  it 'accepts multi-assignments' do
9
14
  inspect_source(cop, 'a, b = b, a')
@@ -10,7 +10,8 @@ describe RuboCop::Cop::Style::IndentHash do
10
10
  }
11
11
  RuboCop::Config.new('Style/AlignHash' => align_hash_config,
12
12
  'Style/IndentHash' =>
13
- cop_config.merge(supported_styles))
13
+ cop_config.merge(supported_styles),
14
+ 'Style/IndentationWidth' => { 'Width' => 2 })
14
15
  end
15
16
  let(:align_hash_config) do
16
17
  {
@@ -5,66 +5,25 @@ require 'spec_helper'
5
5
  describe RuboCop::Cop::Style::IndentationWidth do
6
6
  subject(:cop) { described_class.new(config) }
7
7
  let(:config) do
8
- RuboCop::Config.new('Lint/EndAlignment' => end_alignment_config)
8
+ RuboCop::Config.new('Style/IndentationWidth' => cop_config,
9
+ 'Lint/EndAlignment' => end_alignment_config)
9
10
  end
10
11
  let(:end_alignment_config) do
11
12
  { 'Enabled' => true, 'AlignWith' => 'variable' }
12
13
  end
13
14
 
14
- context 'with if statement' do
15
- it 'registers an offense for bad indentation of an if body' do
16
- inspect_source(cop,
17
- ['if cond',
18
- ' func',
19
- 'end'])
20
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
21
- expect(cop.highlights).to eq([' '])
22
- end
23
-
24
- it 'registers an offense for bad indentation of an else body' do
25
- inspect_source(cop,
26
- ['if cond',
27
- ' func1',
28
- 'else',
29
- ' func2',
30
- 'end'])
31
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
32
- expect(cop.highlights).to eq([' '])
33
- end
34
-
35
- it 'registers an offense for bad indentation of an elsif body' do
36
- inspect_source(cop,
37
- ['if a1',
38
- ' b1',
39
- 'elsif a2',
40
- ' b2',
41
- 'else',
42
- ' c',
43
- 'end'])
44
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
45
- end
46
-
47
- it 'registers offense for bad indentation of ternary inside else' do
48
- inspect_source(cop,
49
- ['if a',
50
- ' b',
51
- 'else',
52
- ' x ? y : z',
53
- 'end'])
54
- expect(cop.messages)
55
- .to eq(['Use 2 (not 5) spaces for indentation.'])
56
- expect(cop.highlights).to eq([' '])
57
- end
58
-
59
- it 'registers offense for bad indentation of modifier if in else' do
60
- inspect_source(cop,
61
- ['if a',
62
- ' b',
63
- 'else',
64
- ' x if y',
65
- 'end'])
66
- expect(cop.messages)
67
- .to eq(['Use 2 (not 3) spaces for indentation.'])
15
+ context 'with Width set to 4' do
16
+ let(:cop_config) { { 'Width' => 4 } }
17
+
18
+ context 'with if statement' do
19
+ it 'registers an offense for bad indentation of an if body' do
20
+ inspect_source(cop,
21
+ ['if cond',
22
+ ' func',
23
+ 'end'])
24
+ expect(cop.messages).to eq(['Use 4 (not 1) spaces for indentation.'])
25
+ expect(cop.highlights).to eq([' '])
26
+ end
68
27
  end
69
28
 
70
29
  describe '#autocorrect' do
@@ -80,764 +39,848 @@ describe RuboCop::Cop::Style::IndentationWidth do
80
39
  'end'])
81
40
  expect(corrected)
82
41
  .to eq ['if a1',
83
- ' b1',
42
+ ' b1',
84
43
  ' b1', # Will be corrected by IndentationConsistency.
85
44
  'elsif a2',
86
- ' b2',
45
+ ' b2',
87
46
  'else',
88
- ' c',
47
+ ' c',
89
48
  'end'].join("\n")
90
49
  end
50
+ end
51
+ end
91
52
 
92
- it 'does not correct in scopes that contain block comments' do
93
- corrected = autocorrect_source(cop,
94
- ['module Foo',
95
- 'class Bar',
96
- '=begin',
97
- 'This is a nice long',
98
- 'comment',
99
- 'which spans a few lines',
100
- '=end',
101
- 'def baz',
102
- 'do_something',
103
- 'end',
104
- 'end',
105
- 'end'])
106
- expect(corrected).to eq ['module Foo',
107
- # The class has a block comment within, so
108
- # it's not corrected.
109
- 'class Bar',
110
- '=begin',
111
- 'This is a nice long',
112
- 'comment',
113
- 'which spans a few lines',
114
- '=end',
115
- # The method has no block comment inside, so
116
- # it's corrected.
117
- ' def baz',
118
- # Method contents are also corrected.
119
- ' do_something',
120
- ' end',
121
- 'end',
122
- 'end'].join("\n")
123
- end
124
-
125
- it 'does not indent heredoc strings' do
126
- corrected = autocorrect_source(cop,
127
- ['module Foo',
128
- 'module Bar',
129
- ' SOMETHING = <<GOO',
130
- 'text',
131
- 'more text',
132
- 'foo',
133
- 'GOO',
134
- ' def baz',
135
- ' do_something("#{x}")',
136
- ' end',
137
- 'end',
138
- 'end'])
139
- expect(corrected).to eq ['module Foo',
140
- ' module Bar',
141
- ' SOMETHING = <<GOO',
142
- 'text',
143
- 'more text',
144
- 'foo',
145
- 'GOO',
146
- ' def baz',
147
- ' do_something("#{x}")',
148
- ' end',
149
- ' end',
150
- 'end'].join("\n")
151
- end
152
-
153
- it 'indents parenthesized expressions' do
154
- src = ['var1 = nil',
155
- 'array_list = []',
156
- 'if var1.attr1 != 0 || array_list.select{ |w|',
157
- ' (w.attr2 == var1.attr2)',
158
- ' }.blank?',
159
- ' array_list << var1',
160
- 'end']
161
- corrected = autocorrect_source(cop, src)
162
- expect(corrected)
163
- .to eq ['var1 = nil',
164
- 'array_list = []',
165
- 'if var1.attr1 != 0 || array_list.select{ |w|',
166
- ' (w.attr2 == var1.attr2)',
167
- ' }.blank?',
168
- ' array_list << var1',
169
- 'end'].join("\n")
53
+ context 'with Width set to 2' do
54
+ let(:cop_config) { { 'Width' => 2 } }
55
+
56
+ context 'with if statement' do
57
+ it 'registers an offense for bad indentation of an if body' do
58
+ inspect_source(cop,
59
+ ['if cond',
60
+ ' func',
61
+ 'end'])
62
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
63
+ expect(cop.highlights).to eq([' '])
170
64
  end
171
65
 
172
- it 'leaves rescue ; end unchanged' do
173
- src = ['if variable',
174
- ' begin',
175
- ' do_something',
176
- ' rescue ; end # consume any exception',
177
- 'end']
178
- corrected = autocorrect_source(cop, src)
179
- expect(corrected).to eq src.join("\n")
66
+ it 'registers an offense for bad indentation of an else body' do
67
+ inspect_source(cop,
68
+ ['if cond',
69
+ ' func1',
70
+ 'else',
71
+ ' func2',
72
+ 'end'])
73
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
74
+ expect(cop.highlights).to eq([' '])
180
75
  end
181
76
 
182
- it 'leaves block unchanged if block end is not on its own line' do
183
- src = ['a_function {',
184
- ' # a comment',
185
- ' result = AObject.find_by_attr(attr) if attr',
186
- ' result || AObject.make(',
187
- ' :attr => attr,',
188
- ' :attr2 => Other.get_value(),',
189
- ' :attr3 => Another.get_value()) }']
190
- corrected = autocorrect_source(cop, src)
191
- expect(corrected).to eq src.join("\n")
77
+ it 'registers an offense for bad indentation of an elsif body' do
78
+ inspect_source(cop,
79
+ ['if a1',
80
+ ' b1',
81
+ 'elsif a2',
82
+ ' b2',
83
+ 'else',
84
+ ' c',
85
+ 'end'])
86
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
192
87
  end
193
- end
194
88
 
195
- it 'accepts a one line if statement' do
196
- inspect_source(cop,
197
- ['if cond then func1 else func2 end'])
198
- expect(cop.offenses).to be_empty
199
- end
200
-
201
- it 'accepts a correctly aligned if/elsif/else/end' do
202
- inspect_source(cop,
203
- ['if a1',
204
- ' b1',
205
- 'elsif a2',
206
- ' b2',
207
- 'else',
208
- ' c',
209
- 'end'])
210
- expect(cop.offenses).to be_empty
211
- end
212
-
213
- it 'accepts a correctly aligned if/elsif/else/end as a method argument' do
214
- inspect_source(cop,
215
- ['foo(',
216
- ' if a1',
217
- ' b1',
218
- ' elsif a2',
219
- ' b2',
220
- ' else',
221
- ' c',
222
- ' end',
223
- ')'])
224
- expect(cop.offenses).to be_empty
225
- end
226
-
227
- it 'accepts if/elsif/else/end laid out as a table' do
228
- inspect_source(cop,
229
- ['if @io == $stdout then str << "$stdout"',
230
- 'elsif @io == $stdin then str << "$stdin"',
231
- 'elsif @io == $stderr then str << "$stderr"',
232
- 'else str << @io.class.to_s',
233
- 'end'])
234
- expect(cop.offenses).to be_empty
235
- end
236
-
237
- it 'accepts if/then/else/end laid out as another table' do
238
- inspect_source(cop,
239
- ["if File.exist?('config.save')",
240
- 'then ConfigTable.load',
241
- 'else ConfigTable.new',
242
- 'end'])
243
- expect(cop.offenses).to be_empty
244
- end
89
+ it 'registers offense for bad indentation of ternary inside else' do
90
+ inspect_source(cop,
91
+ ['if a',
92
+ ' b',
93
+ 'else',
94
+ ' x ? y : z',
95
+ 'end'])
96
+ expect(cop.messages)
97
+ .to eq(['Use 2 (not 5) spaces for indentation.'])
98
+ expect(cop.highlights).to eq([' '])
99
+ end
245
100
 
246
- it 'accepts an empty if' do
247
- inspect_source(cop,
248
- ['if a',
249
- 'else',
250
- 'end'])
251
- expect(cop.offenses).to be_empty
252
- end
101
+ it 'registers offense for bad indentation of modifier if in else' do
102
+ inspect_source(cop,
103
+ ['if a',
104
+ ' b',
105
+ 'else',
106
+ ' x if y',
107
+ 'end'])
108
+ expect(cop.messages)
109
+ .to eq(['Use 2 (not 3) spaces for indentation.'])
110
+ end
253
111
 
254
- context 'with assignment' do
255
- context 'when alignment style is variable' do
256
- context 'and end is aligned with variable' do
257
- it 'accepts an if with end aligned with setter' do
258
- inspect_source(cop,
259
- ['foo.bar = if baz',
260
- ' derp',
261
- 'end'])
262
- expect(cop.offenses).to be_empty
263
- end
112
+ describe '#autocorrect' do
113
+ it 'corrects bad indentation' do
114
+ corrected = autocorrect_source(cop,
115
+ ['if a1',
116
+ ' b1',
117
+ ' b1',
118
+ 'elsif a2',
119
+ ' b2',
120
+ 'else',
121
+ ' c',
122
+ 'end'])
123
+ expect(corrected)
124
+ .to eq ['if a1',
125
+ ' b1',
126
+ ' b1', # Will be corrected by IndentationConsistency.
127
+ 'elsif a2',
128
+ ' b2',
129
+ 'else',
130
+ ' c',
131
+ 'end'].join("\n")
132
+ end
264
133
 
265
- it 'accepts an if with end aligned with element assignment' do
266
- inspect_source(cop,
267
- ['foo[bar] = if baz',
268
- ' derp',
269
- 'end'])
270
- expect(cop.offenses).to be_empty
271
- end
134
+ it 'does not correct in scopes that contain block comments' do
135
+ corrected = autocorrect_source(cop,
136
+ ['module Foo',
137
+ 'class Bar',
138
+ '=begin',
139
+ 'This is a nice long',
140
+ 'comment',
141
+ 'which spans a few lines',
142
+ '=end',
143
+ 'def baz',
144
+ 'do_something',
145
+ 'end',
146
+ 'end',
147
+ 'end'])
148
+ expect(corrected).to eq ['module Foo',
149
+ # The class has a block comment within, so
150
+ # it's not corrected.
151
+ 'class Bar',
152
+ '=begin',
153
+ 'This is a nice long',
154
+ 'comment',
155
+ 'which spans a few lines',
156
+ '=end',
157
+ # The method has no block comment inside, so
158
+ # it's corrected.
159
+ ' def baz',
160
+ # Method contents are also corrected.
161
+ ' do_something',
162
+ ' end',
163
+ 'end',
164
+ 'end'].join("\n")
165
+ end
272
166
 
273
- it 'accepts an if with end aligned with variable' do
274
- inspect_source(cop,
275
- ['var = if a',
276
- ' 0',
277
- 'end',
278
- '@var = if a',
279
- ' 0',
280
- 'end',
281
- '$var = if a',
282
- ' 0',
283
- 'end',
284
- 'var ||= if a',
285
- ' 0',
286
- 'end',
287
- 'var &&= if a',
288
- ' 0',
289
- 'end',
290
- 'var -= if a',
291
- ' 0',
292
- 'end',
293
- 'VAR = if a',
294
- ' 0',
295
- 'end'])
296
- expect(cop.offenses).to be_empty
297
- end
167
+ it 'does not indent heredoc strings' do
168
+ corrected = autocorrect_source(cop,
169
+ ['module Foo',
170
+ 'module Bar',
171
+ ' SOMETHING = <<GOO',
172
+ 'text',
173
+ 'more text',
174
+ 'foo',
175
+ 'GOO',
176
+ ' def baz',
177
+ ' do_something("#{x}")',
178
+ ' end',
179
+ 'end',
180
+ 'end'])
181
+ expect(corrected).to eq ['module Foo',
182
+ ' module Bar',
183
+ ' SOMETHING = <<GOO',
184
+ 'text',
185
+ 'more text',
186
+ 'foo',
187
+ 'GOO',
188
+ ' def baz',
189
+ ' do_something("#{x}")',
190
+ ' end',
191
+ ' end',
192
+ 'end'].join("\n")
193
+ end
298
194
 
299
- it 'accepts an if/else' do
300
- inspect_source(cop,
301
- ['var = if a',
302
- ' 0',
303
- 'else',
304
- ' 1',
305
- 'end'])
306
- expect(cop.offenses).to be_empty
307
- end
195
+ it 'indents parenthesized expressions' do
196
+ src = ['var1 = nil',
197
+ 'array_list = []',
198
+ 'if var1.attr1 != 0 || array_list.select{ |w|',
199
+ ' (w.attr2 == var1.attr2)',
200
+ ' }.blank?',
201
+ ' array_list << var1',
202
+ 'end']
203
+ corrected = autocorrect_source(cop, src)
204
+ expect(corrected)
205
+ .to eq ['var1 = nil',
206
+ 'array_list = []',
207
+ 'if var1.attr1 != 0 || array_list.select{ |w|',
208
+ ' (w.attr2 == var1.attr2)',
209
+ ' }.blank?',
210
+ ' array_list << var1',
211
+ 'end'].join("\n")
212
+ end
308
213
 
309
- it 'accepts an if/else with chaining after the end' do
310
- inspect_source(cop,
311
- ['var = if a',
312
- ' 0',
313
- 'else',
314
- ' 1',
315
- 'end.abc.join("")'])
316
- expect(cop.offenses).to be_empty
317
- end
214
+ it 'leaves rescue ; end unchanged' do
215
+ src = ['if variable',
216
+ ' begin',
217
+ ' do_something',
218
+ ' rescue ; end # consume any exception',
219
+ 'end']
220
+ corrected = autocorrect_source(cop, src)
221
+ expect(corrected).to eq src.join("\n")
222
+ end
318
223
 
319
- it 'accepts an if/else with chaining with a block after the end' do
320
- inspect_source(cop,
321
- ['var = if a',
322
- ' 0',
323
- 'else',
324
- ' 1',
325
- 'end.abc.tap {}'])
326
- expect(cop.offenses).to be_empty
327
- end
224
+ it 'leaves block unchanged if block end is not on its own line' do
225
+ src = ['a_function {',
226
+ ' # a comment',
227
+ ' result = AObject.find_by_attr(attr) if attr',
228
+ ' result || AObject.make(',
229
+ ' :attr => attr,',
230
+ ' :attr2 => Other.get_value(),',
231
+ ' :attr3 => Another.get_value()) }']
232
+ corrected = autocorrect_source(cop, src)
233
+ expect(corrected).to eq src.join("\n")
328
234
  end
235
+ end
329
236
 
330
- context 'and end is aligned with keyword' do
331
- it 'registers an offense for an if with setter' do
332
- inspect_source(cop,
333
- ['foo.bar = if baz',
334
- ' derp',
335
- ' end'])
336
- expect(cop.messages)
337
- .to eq(['Use 2 (not 12) spaces for indentation.'])
338
- end
237
+ it 'accepts a one line if statement' do
238
+ inspect_source(cop,
239
+ ['if cond then func1 else func2 end'])
240
+ expect(cop.offenses).to be_empty
241
+ end
339
242
 
340
- it 'registers an offense for an if with element assignment' do
341
- inspect_source(cop,
342
- ['foo[bar] = if baz',
343
- ' derp',
344
- ' end'])
345
- expect(cop.messages)
346
- .to eq(['Use 2 (not 13) spaces for indentation.'])
347
- end
243
+ it 'accepts a correctly aligned if/elsif/else/end' do
244
+ inspect_source(cop,
245
+ ['if a1',
246
+ ' b1',
247
+ 'elsif a2',
248
+ ' b2',
249
+ 'else',
250
+ ' c',
251
+ 'end'])
252
+ expect(cop.offenses).to be_empty
253
+ end
348
254
 
349
- it 'registers an offense for an if' do
350
- inspect_source(cop,
351
- ['var = if a',
352
- ' 0',
353
- ' end'])
354
- expect(cop.messages)
355
- .to eq(['Use 2 (not 8) spaces for indentation.'])
356
- end
255
+ it 'accepts a correctly aligned if/elsif/else/end as a method argument' do
256
+ inspect_source(cop,
257
+ ['foo(',
258
+ ' if a1',
259
+ ' b1',
260
+ ' elsif a2',
261
+ ' b2',
262
+ ' else',
263
+ ' c',
264
+ ' end',
265
+ ')'])
266
+ expect(cop.offenses).to be_empty
267
+ end
357
268
 
358
- it 'registers an offense for a while' do
359
- inspect_source(cop,
360
- ['var = while a',
361
- ' b',
362
- ' end'])
363
- expect(cop.messages)
364
- .to eq(['Use 2 (not 8) spaces for indentation.'])
365
- end
269
+ it 'accepts if/elsif/else/end laid out as a table' do
270
+ inspect_source(cop,
271
+ ['if @io == $stdout then str << "$stdout"',
272
+ 'elsif @io == $stdin then str << "$stdin"',
273
+ 'elsif @io == $stderr then str << "$stderr"',
274
+ 'else str << @io.class.to_s',
275
+ 'end'])
276
+ expect(cop.offenses).to be_empty
277
+ end
366
278
 
367
- it 'registers an offense for an until' do
368
- inspect_source(cop,
369
- ['var = until a',
370
- ' b',
371
- ' end'])
372
- expect(cop.messages)
373
- .to eq(['Use 2 (not 8) spaces for indentation.'])
374
- end
375
- end
279
+ it 'accepts if/then/else/end laid out as another table' do
280
+ inspect_source(cop,
281
+ ["if File.exist?('config.save')",
282
+ 'then ConfigTable.load',
283
+ 'else ConfigTable.new',
284
+ 'end'])
285
+ expect(cop.offenses).to be_empty
376
286
  end
377
287
 
378
- shared_examples 'assignment and if with keyword alignment' do
379
- context 'and end is aligned with variable' do
380
- it 'registers an offense for an if' do
381
- inspect_source(cop,
382
- ['var = if a',
383
- ' 0',
384
- 'end'])
385
- expect(cop.messages)
386
- .to eq(['Use 2 (not -4) spaces for indentation.'])
387
- end
288
+ it 'accepts an empty if' do
289
+ inspect_source(cop,
290
+ ['if a',
291
+ 'else',
292
+ 'end'])
293
+ expect(cop.offenses).to be_empty
294
+ end
388
295
 
389
- it 'registers an offense for a while' do
390
- inspect_source(cop,
391
- ['var = while a',
392
- ' b',
393
- 'end'])
394
- expect(cop.messages)
395
- .to eq(['Use 2 (not -4) spaces for indentation.'])
296
+ context 'with assignment' do
297
+ context 'when alignment style is variable' do
298
+ context 'and end is aligned with variable' do
299
+ it 'accepts an if with end aligned with setter' do
300
+ inspect_source(cop,
301
+ ['foo.bar = if baz',
302
+ ' derp',
303
+ 'end'])
304
+ expect(cop.offenses).to be_empty
305
+ end
306
+
307
+ it 'accepts an if with end aligned with element assignment' do
308
+ inspect_source(cop,
309
+ ['foo[bar] = if baz',
310
+ ' derp',
311
+ 'end'])
312
+ expect(cop.offenses).to be_empty
313
+ end
314
+
315
+ it 'accepts an if with end aligned with variable' do
316
+ inspect_source(cop,
317
+ ['var = if a',
318
+ ' 0',
319
+ 'end',
320
+ '@var = if a',
321
+ ' 0',
322
+ 'end',
323
+ '$var = if a',
324
+ ' 0',
325
+ 'end',
326
+ 'var ||= if a',
327
+ ' 0',
328
+ 'end',
329
+ 'var &&= if a',
330
+ ' 0',
331
+ 'end',
332
+ 'var -= if a',
333
+ ' 0',
334
+ 'end',
335
+ 'VAR = if a',
336
+ ' 0',
337
+ 'end'])
338
+ expect(cop.offenses).to be_empty
339
+ end
340
+
341
+ it 'accepts an if/else' do
342
+ inspect_source(cop,
343
+ ['var = if a',
344
+ ' 0',
345
+ 'else',
346
+ ' 1',
347
+ 'end'])
348
+ expect(cop.offenses).to be_empty
349
+ end
350
+
351
+ it 'accepts an if/else with chaining after the end' do
352
+ inspect_source(cop,
353
+ ['var = if a',
354
+ ' 0',
355
+ 'else',
356
+ ' 1',
357
+ 'end.abc.join("")'])
358
+ expect(cop.offenses).to be_empty
359
+ end
360
+
361
+ it 'accepts an if/else with chaining with a block after the end' do
362
+ inspect_source(cop,
363
+ ['var = if a',
364
+ ' 0',
365
+ 'else',
366
+ ' 1',
367
+ 'end.abc.tap {}'])
368
+ expect(cop.offenses).to be_empty
369
+ end
396
370
  end
397
371
 
398
- it 'autocorrects bad indentation' do
399
- corrected = autocorrect_source(cop,
400
- ['var = if a',
401
- ' b',
402
- 'end',
403
- '',
404
- 'var = while a',
405
- ' b',
406
- 'end'])
407
- expect(corrected).to eq ['var = if a',
408
- ' b',
409
- 'end', # Not this cop's job to fix end.
410
- '',
411
- 'var = while a',
412
- ' b',
413
- 'end'].join("\n")
372
+ context 'and end is aligned with keyword' do
373
+ it 'registers an offense for an if with setter' do
374
+ inspect_source(cop,
375
+ ['foo.bar = if baz',
376
+ ' derp',
377
+ ' end'])
378
+ expect(cop.messages)
379
+ .to eq(['Use 2 (not 12) spaces for indentation.'])
380
+ end
381
+
382
+ it 'registers an offense for an if with element assignment' do
383
+ inspect_source(cop,
384
+ ['foo[bar] = if baz',
385
+ ' derp',
386
+ ' end'])
387
+ expect(cop.messages)
388
+ .to eq(['Use 2 (not 13) spaces for indentation.'])
389
+ end
390
+
391
+ it 'registers an offense for an if' do
392
+ inspect_source(cop,
393
+ ['var = if a',
394
+ ' 0',
395
+ ' end'])
396
+ expect(cop.messages)
397
+ .to eq(['Use 2 (not 8) spaces for indentation.'])
398
+ end
399
+
400
+ it 'registers an offense for a while' do
401
+ inspect_source(cop,
402
+ ['var = while a',
403
+ ' b',
404
+ ' end'])
405
+ expect(cop.messages)
406
+ .to eq(['Use 2 (not 8) spaces for indentation.'])
407
+ end
408
+
409
+ it 'registers an offense for an until' do
410
+ inspect_source(cop,
411
+ ['var = until a',
412
+ ' b',
413
+ ' end'])
414
+ expect(cop.messages)
415
+ .to eq(['Use 2 (not 8) spaces for indentation.'])
416
+ end
414
417
  end
415
418
  end
416
419
 
417
- context 'and end is aligned with keyword' do
418
- it 'accepts an if in assignment' do
419
- inspect_source(cop,
420
- ['var = if a',
421
- ' 0',
422
- ' end'])
423
- expect(cop.offenses).to be_empty
420
+ shared_examples 'assignment and if with keyword alignment' do
421
+ context 'and end is aligned with variable' do
422
+ it 'registers an offense for an if' do
423
+ inspect_source(cop,
424
+ ['var = if a',
425
+ ' 0',
426
+ 'end'])
427
+ expect(cop.messages)
428
+ .to eq(['Use 2 (not -4) spaces for indentation.'])
429
+ end
430
+
431
+ it 'registers an offense for a while' do
432
+ inspect_source(cop,
433
+ ['var = while a',
434
+ ' b',
435
+ 'end'])
436
+ expect(cop.messages)
437
+ .to eq(['Use 2 (not -4) spaces for indentation.'])
438
+ end
439
+
440
+ it 'autocorrects bad indentation' do
441
+ corrected = autocorrect_source(cop,
442
+ ['var = if a',
443
+ ' b',
444
+ 'end',
445
+ '',
446
+ 'var = while a',
447
+ ' b',
448
+ 'end'])
449
+ expect(corrected).to eq ['var = if a',
450
+ ' b',
451
+ 'end', # Not this cop's job to fix end.
452
+ '',
453
+ 'var = while a',
454
+ ' b',
455
+ 'end'].join("\n")
456
+ end
424
457
  end
425
458
 
426
- it 'accepts an if/else in assignment' do
427
- inspect_source(cop,
428
- ['var = if a',
429
- ' 0',
430
- ' else',
431
- ' 1',
432
- ' end'])
433
- expect(cop.offenses).to be_empty
459
+ context 'and end is aligned with keyword' do
460
+ it 'accepts an if in assignment' do
461
+ inspect_source(cop,
462
+ ['var = if a',
463
+ ' 0',
464
+ ' end'])
465
+ expect(cop.offenses).to be_empty
466
+ end
467
+
468
+ it 'accepts an if/else in assignment' do
469
+ inspect_source(cop,
470
+ ['var = if a',
471
+ ' 0',
472
+ ' else',
473
+ ' 1',
474
+ ' end'])
475
+ expect(cop.offenses).to be_empty
476
+ end
477
+
478
+ it 'accepts an if/else in assignment on next line' do
479
+ inspect_source(cop,
480
+ ['var =',
481
+ ' if a',
482
+ ' 0',
483
+ ' else',
484
+ ' 1',
485
+ ' end'])
486
+ expect(cop.offenses).to be_empty
487
+ end
488
+
489
+ it 'accepts a while in assignment' do
490
+ inspect_source(cop,
491
+ ['var = while a',
492
+ ' b',
493
+ ' end'])
494
+ expect(cop.offenses).to be_empty
495
+ end
496
+
497
+ it 'accepts an until in assignment' do
498
+ inspect_source(cop,
499
+ ['var = until a',
500
+ ' b',
501
+ ' end'])
502
+ expect(cop.offenses).to be_empty
503
+ end
434
504
  end
505
+ end
435
506
 
436
- it 'accepts an if/else in assignment on next line' do
437
- inspect_source(cop,
438
- ['var =',
439
- ' if a',
440
- ' 0',
441
- ' else',
442
- ' 1',
443
- ' end'])
444
- expect(cop.offenses).to be_empty
507
+ context 'when alignment style is keyword by choice' do
508
+ let(:end_alignment_config) do
509
+ { 'Enabled' => true, 'AlignWith' => 'keyword' }
445
510
  end
446
511
 
447
- it 'accepts a while in assignment' do
448
- inspect_source(cop,
449
- ['var = while a',
450
- ' b',
451
- ' end'])
452
- expect(cop.offenses).to be_empty
453
- end
512
+ include_examples 'assignment and if with keyword alignment'
513
+ end
454
514
 
455
- it 'accepts an until in assignment' do
456
- inspect_source(cop,
457
- ['var = until a',
458
- ' b',
459
- ' end'])
460
- expect(cop.offenses).to be_empty
515
+ context 'when alignment style is keyword by default' do
516
+ let(:end_alignment_config) do
517
+ { 'Enabled' => false, 'AlignWith' => 'variable' }
461
518
  end
462
- end
463
- end
464
519
 
465
- context 'when alignment style is keyword by choice' do
466
- let(:end_alignment_config) do
467
- { 'Enabled' => true, 'AlignWith' => 'keyword' }
520
+ include_examples 'assignment and if with keyword alignment'
468
521
  end
469
-
470
- include_examples 'assignment and if with keyword alignment'
471
522
  end
472
523
 
473
- context 'when alignment style is keyword by default' do
474
- let(:end_alignment_config) do
475
- { 'Enabled' => false, 'AlignWith' => 'variable' }
476
- end
477
-
478
- include_examples 'assignment and if with keyword alignment'
524
+ it 'accepts an if/else branches with rescue clauses' do
525
+ # Because of how the rescue clauses come out of Parser, these are
526
+ # special and need to be tested.
527
+ inspect_source(cop,
528
+ ['if a',
529
+ ' a rescue nil',
530
+ 'else',
531
+ ' a rescue nil',
532
+ 'end'])
533
+ expect(cop.offenses).to be_empty
479
534
  end
480
535
  end
481
536
 
482
- it 'accepts an if/else branches with rescue clauses' do
483
- # Because of how the rescue clauses come out of Parser, these are
484
- # special and need to be tested.
485
- inspect_source(cop,
486
- ['if a',
487
- ' a rescue nil',
488
- 'else',
489
- ' a rescue nil',
490
- 'end'])
491
- expect(cop.offenses).to be_empty
492
- end
493
- end
494
-
495
- context 'with unless' do
496
- it 'registers an offense for bad indentation of an unless body' do
497
- inspect_source(cop,
498
- ['unless cond',
499
- ' func',
500
- 'end'])
501
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
502
- end
537
+ context 'with unless' do
538
+ it 'registers an offense for bad indentation of an unless body' do
539
+ inspect_source(cop,
540
+ ['unless cond',
541
+ ' func',
542
+ 'end'])
543
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
544
+ end
503
545
 
504
- it 'accepts an empty unless' do
505
- inspect_source(cop,
506
- ['unless a',
507
- 'else',
508
- 'end'])
509
- expect(cop.offenses).to be_empty
546
+ it 'accepts an empty unless' do
547
+ inspect_source(cop,
548
+ ['unless a',
549
+ 'else',
550
+ 'end'])
551
+ expect(cop.offenses).to be_empty
552
+ end
510
553
  end
511
- end
512
554
 
513
- context 'with case' do
514
- it 'registers an offense for bad indentation in a case/when body' do
515
- inspect_source(cop,
516
- ['case a',
517
- 'when b',
518
- ' c',
519
- 'end'])
520
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
521
- end
555
+ context 'with case' do
556
+ it 'registers an offense for bad indentation in a case/when body' do
557
+ inspect_source(cop,
558
+ ['case a',
559
+ 'when b',
560
+ ' c',
561
+ 'end'])
562
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
563
+ end
522
564
 
523
- it 'registers an offense for bad indentation in a case/else body' do
524
- inspect_source(cop,
525
- ['case a',
526
- 'when b',
527
- ' c',
528
- 'when d',
529
- ' e',
530
- 'else',
531
- ' f',
532
- 'end'])
533
- expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
534
- end
565
+ it 'registers an offense for bad indentation in a case/else body' do
566
+ inspect_source(cop,
567
+ ['case a',
568
+ 'when b',
569
+ ' c',
570
+ 'when d',
571
+ ' e',
572
+ 'else',
573
+ ' f',
574
+ 'end'])
575
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
576
+ end
535
577
 
536
- it 'accepts correctly indented case/when/else' do
537
- inspect_source(cop,
538
- ['case a',
539
- 'when b',
540
- ' c',
541
- ' c',
542
- 'when d',
543
- 'else',
544
- ' f',
545
- 'end'])
546
- expect(cop.offenses).to be_empty
547
- end
578
+ it 'accepts correctly indented case/when/else' do
579
+ inspect_source(cop,
580
+ ['case a',
581
+ 'when b',
582
+ ' c',
583
+ ' c',
584
+ 'when d',
585
+ 'else',
586
+ ' f',
587
+ 'end'])
588
+ expect(cop.offenses).to be_empty
589
+ end
548
590
 
549
- it 'accepts aligned values in when clause' do
550
- inspect_source(cop,
551
- ['case superclass',
552
- 'when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,',
553
- ' /\A(Struct|OStruct)\.new/,',
554
- ' /\ADelegateClass\((.+?)\)\s*\Z/,',
555
- ' /\A(#{NAMESPACEMATCH})\(/',
556
- ' $1',
557
- 'when "self"',
558
- ' namespace.path',
559
- 'end'])
560
- expect(cop.offenses).to be_empty
561
- end
591
+ it 'accepts aligned values in when clause' do
592
+ inspect_source(cop,
593
+ ['case superclass',
594
+ 'when /\A(#{NAMESPACEMATCH})(?:\s|\Z)/,',
595
+ ' /\A(Struct|OStruct)\.new/,',
596
+ ' /\ADelegateClass\((.+?)\)\s*\Z/,',
597
+ ' /\A(#{NAMESPACEMATCH})\(/',
598
+ ' $1',
599
+ 'when "self"',
600
+ ' namespace.path',
601
+ 'end'])
602
+ expect(cop.offenses).to be_empty
603
+ end
562
604
 
563
- it 'accepts case/when/else laid out as a table' do
564
- inspect_source(cop,
565
- ['case sexp.loc.keyword.source',
566
- "when 'if' then cond, body, _else = *sexp",
567
- "when 'unless' then cond, _else, body = *sexp",
568
- 'else cond, body = *sexp',
569
- 'end'])
570
- expect(cop.offenses).to be_empty
571
- end
605
+ it 'accepts case/when/else laid out as a table' do
606
+ inspect_source(cop,
607
+ ['case sexp.loc.keyword.source',
608
+ "when 'if' then cond, body, _else = *sexp",
609
+ "when 'unless' then cond, _else, body = *sexp",
610
+ 'else cond, body = *sexp',
611
+ 'end'])
612
+ expect(cop.offenses).to be_empty
613
+ end
572
614
 
573
- it 'accepts case/when/else with then beginning a line' do
574
- inspect_source(cop,
575
- ['case sexp.loc.keyword.source',
576
- "when 'if'",
577
- 'then cond, body, _else = *sexp',
578
- 'end'])
579
- expect(cop.offenses).to be_empty
580
- end
615
+ it 'accepts case/when/else with then beginning a line' do
616
+ inspect_source(cop,
617
+ ['case sexp.loc.keyword.source',
618
+ "when 'if'",
619
+ 'then cond, body, _else = *sexp',
620
+ 'end'])
621
+ expect(cop.offenses).to be_empty
622
+ end
581
623
 
582
- it 'accepts indented when/else plus indented body' do
583
- # "Indent when as deep as case" is the job of another cop.
584
- inspect_source(cop,
585
- ['case code_type',
586
- " when 'ruby', 'sql', 'plain'",
587
- ' code_type',
588
- " when 'erb'",
589
- " 'ruby; html-script: true'",
590
- ' when "html"',
591
- " 'xml'",
592
- ' else',
593
- " 'plain'",
594
- 'end'])
595
- expect(cop.offenses).to be_empty
624
+ it 'accepts indented when/else plus indented body' do
625
+ # "Indent when as deep as case" is the job of another cop.
626
+ inspect_source(cop,
627
+ ['case code_type',
628
+ " when 'ruby', 'sql', 'plain'",
629
+ ' code_type',
630
+ " when 'erb'",
631
+ " 'ruby; html-script: true'",
632
+ ' when "html"',
633
+ " 'xml'",
634
+ ' else',
635
+ " 'plain'",
636
+ 'end'])
637
+ expect(cop.offenses).to be_empty
638
+ end
596
639
  end
597
- end
598
640
 
599
- context 'with while/until' do
600
- it 'registers an offense for bad indentation of a while body' do
601
- inspect_source(cop,
602
- ['while cond',
603
- ' func',
604
- 'end'])
605
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
606
- end
641
+ context 'with while/until' do
642
+ it 'registers an offense for bad indentation of a while body' do
643
+ inspect_source(cop,
644
+ ['while cond',
645
+ ' func',
646
+ 'end'])
647
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
648
+ end
607
649
 
608
- it 'registers an offense for bad indentation of begin/end/while' do
609
- inspect_source(cop,
610
- ['something = begin',
611
- ' func1',
612
- ' func2',
613
- 'end while cond'])
614
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
615
- end
650
+ it 'registers an offense for bad indentation of begin/end/while' do
651
+ inspect_source(cop,
652
+ ['something = begin',
653
+ ' func1',
654
+ ' func2',
655
+ 'end while cond'])
656
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
657
+ end
616
658
 
617
- it 'registers an offense for bad indentation of an until body' do
618
- inspect_source(cop,
619
- ['until cond',
620
- ' func',
621
- 'end'])
622
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
623
- end
659
+ it 'registers an offense for bad indentation of an until body' do
660
+ inspect_source(cop,
661
+ ['until cond',
662
+ ' func',
663
+ 'end'])
664
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
665
+ end
624
666
 
625
- it 'accepts an empty while' do
626
- inspect_source(cop,
627
- ['while a',
628
- 'end'])
629
- expect(cop.offenses).to be_empty
667
+ it 'accepts an empty while' do
668
+ inspect_source(cop,
669
+ ['while a',
670
+ 'end'])
671
+ expect(cop.offenses).to be_empty
672
+ end
630
673
  end
631
- end
632
674
 
633
- context 'with for' do
634
- it 'registers an offense for bad indentation of a for body' do
635
- inspect_source(cop,
636
- ['for var in 1..10',
637
- ' func',
638
- 'end'])
639
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
640
- end
675
+ context 'with for' do
676
+ it 'registers an offense for bad indentation of a for body' do
677
+ inspect_source(cop,
678
+ ['for var in 1..10',
679
+ ' func',
680
+ 'end'])
681
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
682
+ end
641
683
 
642
- it 'accepts an empty for' do
643
- inspect_source(cop,
644
- ['for var in 1..10',
645
- 'end'])
646
- expect(cop.offenses).to be_empty
684
+ it 'accepts an empty for' do
685
+ inspect_source(cop,
686
+ ['for var in 1..10',
687
+ 'end'])
688
+ expect(cop.offenses).to be_empty
689
+ end
647
690
  end
648
- end
649
691
 
650
- context 'with def/defs' do
651
- it 'registers an offense for bad indentation of a def body' do
652
- inspect_source(cop,
653
- ['def test',
654
- ' func1',
655
- ' func2', # No offense registered for this.
656
- 'end'])
657
- expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
658
- end
692
+ context 'with def/defs' do
693
+ it 'registers an offense for bad indentation of a def body' do
694
+ inspect_source(cop,
695
+ ['def test',
696
+ ' func1',
697
+ ' func2', # No offense registered for this.
698
+ 'end'])
699
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
700
+ end
659
701
 
660
- it 'registers an offense for bad indentation of a defs body' do
661
- inspect_source(cop,
662
- ['def self.test',
663
- ' func',
664
- 'end'])
665
- expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
666
- end
702
+ it 'registers an offense for bad indentation of a defs body' do
703
+ inspect_source(cop,
704
+ ['def self.test',
705
+ ' func',
706
+ 'end'])
707
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
708
+ end
667
709
 
668
- it 'accepts an empty def body' do
669
- inspect_source(cop,
670
- ['def test',
671
- 'end'])
672
- expect(cop.offenses).to be_empty
673
- end
710
+ it 'accepts an empty def body' do
711
+ inspect_source(cop,
712
+ ['def test',
713
+ 'end'])
714
+ expect(cop.offenses).to be_empty
715
+ end
674
716
 
675
- it 'accepts an empty defs body' do
676
- inspect_source(cop,
677
- ['def self.test',
678
- 'end'])
679
- expect(cop.offenses).to be_empty
680
- end
717
+ it 'accepts an empty defs body' do
718
+ inspect_source(cop,
719
+ ['def self.test',
720
+ 'end'])
721
+ expect(cop.offenses).to be_empty
722
+ end
681
723
 
682
- if RUBY_VERSION >= '2.1'
683
- context 'when modifier and def are on the same line' do
684
- it 'accepts a correctly aligned body' do
685
- inspect_source(cop,
686
- ['private def test',
687
- ' something',
688
- 'end'])
689
- expect(cop.offenses).to be_empty
690
- end
724
+ if RUBY_VERSION >= '2.1'
725
+ context 'when modifier and def are on the same line' do
726
+ it 'accepts a correctly aligned body' do
727
+ inspect_source(cop,
728
+ ['private def test',
729
+ ' something',
730
+ 'end'])
731
+ expect(cop.offenses).to be_empty
732
+ end
691
733
 
692
- it 'registers an offense for bad indentation of a def body' do
693
- inspect_source(cop,
694
- ['private def test',
695
- ' something',
696
- ' end'])
697
- expect(cop.messages)
698
- .to eq(['Use 2 (not 10) spaces for indentation.'])
734
+ it 'registers an offense for bad indentation of a def body' do
735
+ inspect_source(cop,
736
+ ['private def test',
737
+ ' something',
738
+ ' end'])
739
+ expect(cop.messages)
740
+ .to eq(['Use 2 (not 10) spaces for indentation.'])
741
+ end
699
742
  end
700
743
  end
701
744
  end
702
- end
703
745
 
704
- context 'with class' do
705
- it 'registers an offense for bad indentation of a class body' do
706
- inspect_source(cop,
707
- ['class Test',
708
- ' def func',
709
- ' end',
710
- 'end'])
711
- expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
712
- end
746
+ context 'with class' do
747
+ it 'registers an offense for bad indentation of a class body' do
748
+ inspect_source(cop,
749
+ ['class Test',
750
+ ' def func',
751
+ ' end',
752
+ 'end'])
753
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
754
+ end
713
755
 
714
- it 'accepts an empty class body' do
715
- inspect_source(cop,
716
- ['class Test',
717
- 'end'])
718
- expect(cop.offenses).to be_empty
719
- end
756
+ it 'accepts an empty class body' do
757
+ inspect_source(cop,
758
+ ['class Test',
759
+ 'end'])
760
+ expect(cop.offenses).to be_empty
761
+ end
720
762
 
721
- it 'accepts indented public, protected, and private' do
722
- inspect_source(cop,
723
- ['class Test',
724
- ' public',
725
- '',
726
- ' def e',
727
- ' end',
728
- '',
729
- ' protected',
730
- '',
731
- ' def f',
732
- ' end',
733
- '',
734
- ' private',
735
- '',
736
- ' def g',
737
- ' end',
738
- 'end'])
739
- expect(cop.offenses).to be_empty
763
+ it 'accepts indented public, protected, and private' do
764
+ inspect_source(cop,
765
+ ['class Test',
766
+ ' public',
767
+ '',
768
+ ' def e',
769
+ ' end',
770
+ '',
771
+ ' protected',
772
+ '',
773
+ ' def f',
774
+ ' end',
775
+ '',
776
+ ' private',
777
+ '',
778
+ ' def g',
779
+ ' end',
780
+ 'end'])
781
+ expect(cop.offenses).to be_empty
782
+ end
740
783
  end
741
- end
742
784
 
743
- context 'with module' do
744
- it 'registers an offense for bad indentation of a module body' do
745
- inspect_source(cop,
746
- ['module Test',
747
- ' def func',
748
- ' end',
749
- 'end'])
750
- expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
751
- end
785
+ context 'with module' do
786
+ it 'registers an offense for bad indentation of a module body' do
787
+ inspect_source(cop,
788
+ ['module Test',
789
+ ' def func',
790
+ ' end',
791
+ 'end'])
792
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
793
+ end
752
794
 
753
- it 'accepts an empty module body' do
754
- inspect_source(cop,
755
- ['module Test',
756
- 'end'])
757
- expect(cop.offenses).to be_empty
795
+ it 'accepts an empty module body' do
796
+ inspect_source(cop,
797
+ ['module Test',
798
+ 'end'])
799
+ expect(cop.offenses).to be_empty
800
+ end
758
801
  end
759
- end
760
802
 
761
- context 'with begin/rescue/else/ensure/end' do
762
- it 'registers an offense for bad indentation of bodies' do
763
- inspect_source(cop,
764
- ['def my_func',
765
- " puts 'do something outside block'",
766
- ' begin',
767
- " puts 'do something error prone'",
768
- ' rescue SomeException, SomeOther => e',
769
- " puts 'wrongly intended error handling'",
770
- ' rescue',
771
- " puts 'wrongly intended error handling'",
772
- ' else',
773
- " puts 'wrongly intended normal case handling'",
774
- ' ensure',
775
- " puts 'wrongly intended common handling'",
776
- ' end',
777
- 'end'])
778
- expect(cop.messages).to eq(['Use 2 (not 0) spaces for indentation.',
779
- 'Use 2 (not 1) spaces for indentation.',
780
- 'Use 2 (not 1) spaces for indentation.',
781
- 'Use 2 (not 3) spaces for indentation.',
782
- 'Use 2 (not 4) spaces for indentation.'])
803
+ context 'with begin/rescue/else/ensure/end' do
804
+ it 'registers an offense for bad indentation of bodies' do
805
+ inspect_source(cop,
806
+ ['def my_func',
807
+ " puts 'do something outside block'",
808
+ ' begin',
809
+ " puts 'do something error prone'",
810
+ ' rescue SomeException, SomeOther => e',
811
+ " puts 'wrongly intended error handling'",
812
+ ' rescue',
813
+ " puts 'wrongly intended error handling'",
814
+ ' else',
815
+ " puts 'wrongly intended normal case handling'",
816
+ ' ensure',
817
+ " puts 'wrongly intended common handling'",
818
+ ' end',
819
+ 'end'])
820
+ expect(cop.messages).to eq(['Use 2 (not 0) spaces for indentation.',
821
+ 'Use 2 (not 1) spaces for indentation.',
822
+ 'Use 2 (not 1) spaces for indentation.',
823
+ 'Use 2 (not 3) spaces for indentation.',
824
+ 'Use 2 (not 4) spaces for indentation.'])
825
+ end
783
826
  end
784
- end
785
827
 
786
- context 'with def/rescue/end' do
787
- it 'registers an offense for bad indentation of bodies' do
788
- inspect_source(cop,
789
- ['def my_func',
790
- " puts 'do something error prone'",
791
- 'rescue SomeException',
792
- " puts 'wrongly intended error handling'",
793
- 'rescue',
794
- " puts 'wrongly intended error handling'",
795
- 'end'])
796
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.',
797
- 'Use 2 (not 1) spaces for indentation.'])
828
+ context 'with def/rescue/end' do
829
+ it 'registers an offense for bad indentation of bodies' do
830
+ inspect_source(cop,
831
+ ['def my_func',
832
+ " puts 'do something error prone'",
833
+ 'rescue SomeException',
834
+ " puts 'wrongly intended error handling'",
835
+ 'rescue',
836
+ " puts 'wrongly intended error handling'",
837
+ 'end'])
838
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.',
839
+ 'Use 2 (not 1) spaces for indentation.'])
840
+ end
798
841
  end
799
- end
800
842
 
801
- context 'with block' do
802
- it 'registers an offense for bad indentation of a do/end body' do
803
- inspect_source(cop,
804
- ['a = func do',
805
- ' b',
806
- 'end'])
807
- expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
808
- end
843
+ context 'with block' do
844
+ it 'registers an offense for bad indentation of a do/end body' do
845
+ inspect_source(cop,
846
+ ['a = func do',
847
+ ' b',
848
+ 'end'])
849
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
850
+ end
809
851
 
810
- it 'registers an offense for bad indentation of a {} body' do
811
- inspect_source(cop,
812
- ['func {',
813
- ' b',
814
- '}'])
815
- expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
816
- end
852
+ it 'registers an offense for bad indentation of a {} body' do
853
+ inspect_source(cop,
854
+ ['func {',
855
+ ' b',
856
+ '}'])
857
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
858
+ end
817
859
 
818
- it 'accepts a correctly indented block body' do
819
- inspect_source(cop,
820
- ['a = func do',
821
- ' b',
822
- 'end'])
823
- expect(cop.offenses).to be_empty
824
- end
860
+ it 'accepts a correctly indented block body' do
861
+ inspect_source(cop,
862
+ ['a = func do',
863
+ ' b',
864
+ 'end'])
865
+ expect(cop.offenses).to be_empty
866
+ end
825
867
 
826
- it 'accepts an empty block body' do
827
- inspect_source(cop,
828
- ['a = func do',
829
- 'end'])
830
- expect(cop.offenses).to be_empty
831
- end
868
+ it 'accepts an empty block body' do
869
+ inspect_source(cop,
870
+ ['a = func do',
871
+ 'end'])
872
+ expect(cop.offenses).to be_empty
873
+ end
832
874
 
833
- # The cop uses the block end/} as the base for indentation, so if it's not
834
- # on its own line, all bets are off.
835
- it 'accepts badly indented code if block end is not on separate line' do
836
- inspect_source(cop,
837
- ['foo {',
838
- 'def baz',
839
- 'end }'])
840
- expect(cop.offenses).to be_empty
875
+ # The cop uses the block end/} as the base for indentation, so if it's not
876
+ # on its own line, all bets are off.
877
+ it 'accepts badly indented code if block end is not on separate line' do
878
+ inspect_source(cop,
879
+ ['foo {',
880
+ 'def baz',
881
+ 'end }'])
882
+ expect(cop.offenses).to be_empty
883
+ end
841
884
  end
842
885
  end
843
886
  end