rubocop 0.25.0 → 0.26.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +37 -0
  4. data/README.md +2 -2
  5. data/assets/output.html.erb +190 -0
  6. data/config/default.yml +14 -2
  7. data/config/disabled.yml +7 -0
  8. data/config/enabled.yml +132 -5
  9. data/lib/rubocop.rb +5 -0
  10. data/lib/rubocop/cop/commissioner.rb +4 -10
  11. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
  12. data/lib/rubocop/cop/lint/end_in_method.rb +3 -8
  13. data/lib/rubocop/cop/lint/ensure_return.rb +2 -2
  14. data/lib/rubocop/cop/lint/space_before_first_arg.rb +8 -1
  15. data/lib/rubocop/cop/lint/useless_assignment.rb +35 -0
  16. data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -3
  17. data/lib/rubocop/cop/metrics/block_nesting.rb +3 -3
  18. data/lib/rubocop/cop/metrics/class_length.rb +1 -2
  19. data/lib/rubocop/cop/mixin/access_modifier_node.rb +5 -1
  20. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
  21. data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
  22. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -4
  23. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -3
  24. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  25. data/lib/rubocop/cop/rails/validation.rb +25 -2
  26. data/lib/rubocop/cop/style/alias.rb +1 -1
  27. data/lib/rubocop/cop/style/and_or.rb +12 -2
  28. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -12
  29. data/lib/rubocop/cop/style/documentation.rb +1 -1
  30. data/lib/rubocop/cop/style/dot_position.rb +20 -0
  31. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +5 -1
  32. data/lib/rubocop/cop/style/encoding.rb +4 -4
  33. data/lib/rubocop/cop/style/format_string.rb +12 -2
  34. data/lib/rubocop/cop/style/if_unless_modifier.rb +8 -11
  35. data/lib/rubocop/cop/style/infinite_loop.rb +57 -0
  36. data/lib/rubocop/cop/style/multiline_block_chain.rb +15 -16
  37. data/lib/rubocop/cop/style/multiline_if_then.rb +10 -0
  38. data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -3
  39. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -1
  40. data/lib/rubocop/cop/style/predicate_name.rb +23 -5
  41. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  42. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  43. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +4 -8
  44. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +9 -11
  45. data/lib/rubocop/cop/style/space_inside_range_literal.rb +58 -0
  46. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  47. data/lib/rubocop/cop/style/symbol_proc.rb +71 -0
  48. data/lib/rubocop/cop/style/tab.rb +11 -3
  49. data/lib/rubocop/cop/style/unneeded_capital_w.rb +6 -2
  50. data/lib/rubocop/cop/style/variable_name.rb +4 -14
  51. data/lib/rubocop/cop/style/while_until_modifier.rb +12 -8
  52. data/lib/rubocop/cop/variable_force.rb +17 -30
  53. data/lib/rubocop/cop/variable_force/assignment.rb +15 -23
  54. data/lib/rubocop/cop/variable_force/locatable.rb +29 -8
  55. data/lib/rubocop/cop/variable_force/scope.rb +34 -23
  56. data/lib/rubocop/cop/variable_force/variable.rb +7 -10
  57. data/lib/rubocop/formatter/disabled_config_formatter.rb +3 -2
  58. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  59. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  60. data/lib/rubocop/formatter/html_formatter.rb +90 -0
  61. data/lib/rubocop/formatter/progress_formatter.rb +1 -1
  62. data/lib/rubocop/options.rb +1 -0
  63. data/lib/rubocop/processed_source.rb +10 -1
  64. data/lib/rubocop/string_util.rb +153 -0
  65. data/lib/rubocop/target_finder.rb +1 -1
  66. data/lib/rubocop/version.rb +1 -1
  67. data/relnotes/v0.26.0.md +89 -0
  68. data/rubocop.gemspec +1 -0
  69. data/spec/rubocop/cli_spec.rb +60 -34
  70. data/spec/rubocop/config_loader_spec.rb +19 -15
  71. data/spec/rubocop/cop/commissioner_spec.rb +2 -2
  72. data/spec/rubocop/cop/lint/block_alignment_spec.rb +74 -58
  73. data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +7 -0
  74. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +173 -0
  75. data/spec/rubocop/cop/rails/validation_spec.rb +9 -2
  76. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +26 -0
  77. data/spec/rubocop/cop/style/and_or_spec.rb +52 -61
  78. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +26 -8
  79. data/spec/rubocop/cop/style/case_indentation_spec.rb +8 -8
  80. data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +6 -2
  81. data/spec/rubocop/cop/style/dot_position_spec.rb +39 -0
  82. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +12 -2
  83. data/spec/rubocop/cop/style/encoding_spec.rb +16 -28
  84. data/spec/rubocop/cop/style/format_string_spec.rb +12 -0
  85. data/spec/rubocop/cop/style/infinite_loop_spec.rb +48 -0
  86. data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +3 -1
  87. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +9 -0
  88. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +21 -1
  89. data/spec/rubocop/cop/style/predicate_name_spec.rb +44 -13
  90. data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
  91. data/spec/rubocop/cop/style/space_inside_range_literal_spec.rb +52 -0
  92. data/spec/rubocop/cop/style/symbol_proc_spec.rb +76 -0
  93. data/spec/rubocop/cop/style/tab_spec.rb +30 -0
  94. data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -1
  95. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +18 -5
  96. data/spec/rubocop/cop/style/variable_name_spec.rb +5 -5
  97. data/spec/rubocop/cop/style/when_then_spec.rb +3 -1
  98. data/spec/rubocop/cop/style/while_until_do_spec.rb +4 -2
  99. data/spec/rubocop/cop/util_spec.rb +1 -9
  100. data/spec/rubocop/cop/variable_force/assignment_spec.rb +2 -15
  101. data/spec/rubocop/cop/variable_force/locatable_spec.rb +2 -37
  102. data/spec/rubocop/cop/variable_force/scope_spec.rb +156 -49
  103. data/spec/rubocop/cop/variable_force/variable_spec.rb +2 -1
  104. data/spec/rubocop/cop/variable_force_spec.rb +2 -1
  105. data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +2 -1
  106. data/spec/rubocop/formatter/html_formatter_spec.rb +145 -0
  107. data/spec/rubocop/formatter/simple_text_formatter_spec.rb +18 -6
  108. data/spec/rubocop/options_spec.rb +1 -0
  109. data/spec/rubocop/path_util_spec.rb +6 -4
  110. data/spec/rubocop/processed_source_spec.rb +17 -1
  111. data/spec/rubocop/string_util_spec.rb +46 -0
  112. metadata +33 -4
  113. data/spec/support/ast_helper.rb +0 -15
@@ -5,15 +5,22 @@ require 'spec_helper'
5
5
  describe RuboCop::Cop::Rails::Validation do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
- described_class::BLACKLIST.each do |validation|
8
+ described_class::BLACKLIST.each_with_index do |validation, number|
9
9
  it "registers an offense for #{validation}" do
10
10
  inspect_source(cop,
11
11
  ["#{validation} :name"])
12
12
  expect(cop.offenses.size).to eq(1)
13
13
  end
14
+
15
+ it "outputs the correct message for #{validation}" do
16
+ inspect_source(cop,
17
+ ["#{validation} :name"])
18
+ expect(cop.offenses.first.message)
19
+ .to include(described_class::WHITELIST[number])
20
+ end
14
21
  end
15
22
 
16
- it 'accepts sexy validations' do
23
+ it 'accepts new style validations' do
17
24
  inspect_source(cop,
18
25
  ['validates :name'])
19
26
  expect(cop.offenses).to be_empty
@@ -36,6 +36,21 @@ describe RuboCop::Cop::Style::AccessModifierIndentation, :config do
36
36
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
37
37
  end
38
38
 
39
+ it 'registers an offense for misaligned module_function in module' do
40
+ inspect_source(cop,
41
+ ['module Test',
42
+ '',
43
+ ' module_function',
44
+ '',
45
+ ' def test; end',
46
+ 'end'])
47
+ expect(cop.offenses.size).to eq(1)
48
+ expect(cop.messages)
49
+ .to eq(['Indent access modifiers like `module_function`.'])
50
+ # Not aligned according to `indent` or `outdent` style:
51
+ expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
52
+ end
53
+
39
54
  it 'registers an offense for correct + opposite alignment' do
40
55
  inspect_source(cop,
41
56
  ['module Test',
@@ -232,6 +247,17 @@ describe RuboCop::Cop::Style::AccessModifierIndentation, :config do
232
247
  expect(cop.messages).to eq([indent_msg])
233
248
  end
234
249
 
250
+ it 'registers offense for module fn indented to method depth in a module' do
251
+ inspect_source(cop,
252
+ ['module Test',
253
+ '',
254
+ ' module_function',
255
+ '',
256
+ ' def test; end',
257
+ 'end'])
258
+ expect(cop.offenses.size).to eq(1)
259
+ end
260
+
235
261
  it 'registers offense for private indented to method depth in singleton' \
236
262
  'class' do
237
263
  inspect_source(cop,
@@ -11,65 +11,57 @@ describe RuboCop::Cop::Style::AndOr, :config do
11
11
  subject(:cop) { described_class.new(config) }
12
12
  let(:cop_config) { cop_config }
13
13
 
14
- it 'does not warn on short-circuit (and)' do
15
- inspect_source(cop,
16
- ['x = a + b and return x'])
17
- expect(cop.offenses.size).to eq(0)
18
- end
19
-
20
- it 'does not warn on short-circuit (or)' do
21
- inspect_source(cop,
22
- ['x = a + b or return x'])
23
- expect(cop.offenses.size).to eq(0)
24
- end
25
-
26
- it 'does warn on non short-circuit (and)' do
27
- inspect_source(cop,
28
- ['x = a + b if a and b'])
29
- expect(cop.offenses.size).to eq(1)
30
- expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
14
+ %w(and or).each do |operator|
15
+ it "accepts \"#{operator}\" outside of conditional" do
16
+ inspect_source(cop,
17
+ ["x = a + b #{operator} return x"])
18
+ expect(cop.offenses).to be_empty
19
+ end
20
+
21
+ {
22
+ 'if' => 'if %{conditional}; %{body}; end',
23
+ 'while' => 'while %{conditional}; %{body}; end',
24
+ 'until' => 'until %{conditional}; %{body}; end',
25
+ 'post-conditional while' => 'begin; %{body}; end while %{conditional}',
26
+ 'post-conditional until' => 'begin; %{body}; end until %{conditional}'
27
+ }.each do |type, snippet_format|
28
+ it "registers an offense for \"#{operator}\" in #{type} conditional" do
29
+ elements = {
30
+ conditional: "a #{operator} b",
31
+ body: 'do_something'
32
+ }
33
+ source = format(snippet_format, elements)
34
+
35
+ inspect_source(cop, source)
36
+ expect(cop.offenses.size).to eq(1)
37
+ end
38
+
39
+ it "accepts \"#{operator}\" in #{type} body" do
40
+ elements = {
41
+ conditional: 'some_condition',
42
+ body: "do_something #{operator} return"
43
+ }
44
+ source = format(snippet_format, elements)
45
+
46
+ inspect_source(cop, source)
47
+ expect(cop.offenses).to be_empty
48
+ end
49
+ end
50
+ end
51
+
52
+ %w(&& ||).each do |operator|
53
+ it "accepts #{operator} inside of conditional" do
54
+ inspect_source(cop,
55
+ ["test if a #{operator} b"])
56
+ expect(cop.offenses).to be_empty
57
+ end
58
+
59
+ it "accepts #{operator} outside of conditional" do
60
+ inspect_source(cop,
61
+ ["x = a #{operator} b"])
62
+ expect(cop.offenses).to be_empty
63
+ end
31
64
  end
32
-
33
- it 'does warn on non short-circuit (or)' do
34
- inspect_source(cop,
35
- ['x = a + b if a or b'])
36
- expect(cop.offenses.size).to eq(1)
37
- expect(cop.messages).to eq(['Use `||` instead of `or`.'])
38
- end
39
-
40
- it 'does warn on non short-circuit (and) (unless)' do
41
- inspect_source(cop,
42
- ['x = a + b unless a and b'])
43
- expect(cop.offenses.size).to eq(1)
44
- expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
45
- end
46
-
47
- it 'does warn on non short-circuit (or) (unless)' do
48
- inspect_source(cop,
49
- ['x = a + b unless a or b'])
50
- expect(cop.offenses.size).to eq(1)
51
- expect(cop.messages).to eq(['Use `||` instead of `or`.'])
52
- end
53
-
54
- it 'should handle boolean returning methods correctly' do
55
- inspect_source(cop,
56
- ['1 if (not true) or false'])
57
- expect(cop.offenses.size).to eq(1)
58
- expect(cop.messages).to eq(['Use `||` instead of `or`.'])
59
- end
60
-
61
- it 'should handle recursion' do
62
- inspect_source(cop,
63
- ['1 if (true and false) || (false or true)'])
64
- expect(cop.offenses.size).to eq(2)
65
- end
66
-
67
- it 'should handle recursion' do
68
- inspect_source(cop,
69
- ['1 if (true or false) && (false and true)'])
70
- expect(cop.offenses.size).to eq(2)
71
- end
72
-
73
65
  end
74
66
 
75
67
  context 'when style is always' do
@@ -80,14 +72,14 @@ describe RuboCop::Cop::Style::AndOr, :config do
80
72
  subject(:cop) { described_class.new(config) }
81
73
  let(:cop_config) { cop_config }
82
74
 
83
- it 'registers an offense for OR' do
75
+ it 'registers an offense for "or"' do
84
76
  inspect_source(cop,
85
77
  ['test if a or b'])
86
78
  expect(cop.offenses.size).to eq(1)
87
79
  expect(cop.messages).to eq(['Use `||` instead of `or`.'])
88
80
  end
89
81
 
90
- it 'registers an offense for AND' do
82
+ it 'registers an offense for "and"' do
91
83
  inspect_source(cop,
92
84
  ['test if a and b'])
93
85
  expect(cop.offenses.size).to eq(1)
@@ -254,6 +246,5 @@ describe RuboCop::Cop::Style::AndOr, :config do
254
246
  new_source = autocorrect_source(cop, 'b and method a,b')
255
247
  expect(new_source).to eq('b && method(a,b)')
256
248
  end
257
-
258
249
  end
259
250
  end
@@ -137,32 +137,49 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
137
137
  describe 'auto-corrects' do
138
138
  it 'one non-hash parameter followed by a hash parameter with braces' do
139
139
  corrected = autocorrect_source(cop, ['where(1, { y: 2 })'])
140
- expect(corrected).to eq 'where(1, y: 2 )'
140
+ expect(corrected).to eq 'where(1, y: 2)'
141
141
  end
142
142
 
143
143
  it 'one object method hash parameter with braces' do
144
144
  corrected = autocorrect_source(cop, ['x.func({ y: "z" })'])
145
- expect(corrected).to eq 'x.func( y: "z" )'
145
+ expect(corrected).to eq 'x.func(y: "z")'
146
146
  end
147
147
 
148
148
  it 'one hash parameter with braces' do
149
149
  corrected = autocorrect_source(cop, ['where({ x: 1 })'])
150
- expect(corrected).to eq 'where( x: 1 )'
150
+ expect(corrected).to eq 'where(x: 1)'
151
151
  end
152
152
 
153
153
  it 'one hash parameter with braces and separators' do
154
- corrected = autocorrect_source(cop, ["where( \n { x: 1 } )"])
155
- expect(corrected).to eq "where( \n x: 1 )"
154
+ corrected = autocorrect_source(cop, ['where( ',
155
+ ' { x: 1 } )'])
156
+ expect(corrected).to eq(['where( ',
157
+ ' x: 1 )'].join("\n"))
156
158
  end
157
159
 
158
160
  it 'one hash parameter with braces and multiple keys' do
159
161
  corrected = autocorrect_source(cop, ['where({ x: 1, foo: "bar" })'])
160
- expect(corrected).to eq 'where( x: 1, foo: "bar" )'
162
+ expect(corrected).to eq 'where(x: 1, foo: "bar")'
163
+ end
164
+
165
+ it 'one hash parameter with braces and extra leading whitespace' do
166
+ corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
167
+ expect(corrected).to eq 'where(x: 1, y: 2)'
168
+ end
169
+
170
+ it 'one hash parameter with braces and extra trailing whitespace' do
171
+ corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
172
+ expect(corrected).to eq 'where(x: 1, y: 2)'
161
173
  end
162
174
 
163
175
  it 'one hash parameter with braces and a trailing comma' do
164
176
  corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
165
- expect(corrected).to eq 'where( x: 1, y: 2 )'
177
+ expect(corrected).to eq 'where(x: 1, y: 2)'
178
+ end
179
+
180
+ it 'one hash parameter with braces and trailing comma and whitespace' do
181
+ corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
182
+ expect(corrected).to eq 'where(x: 1, y: 2)'
166
183
  end
167
184
  end
168
185
  end
@@ -212,7 +229,8 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
212
229
  end
213
230
 
214
231
  it 'one hash parameter with braces and separators around it' do
215
- inspect_source(cop, ["where( \t { x: 1 \n } )"])
232
+ inspect_source(cop, ["where( \t { x: 1 ",
233
+ ' } )'])
216
234
  expect(cop.messages).to be_empty
217
235
  expect(cop.highlights).to be_empty
218
236
  end
@@ -28,7 +28,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
28
28
  expect(cop.offenses).to be_empty
29
29
  end
30
30
 
31
- it 'registers on offense for an assignment indented as end' do
31
+ it 'registers an offense for an assignment indented as end' do
32
32
  source = ['output = case variable',
33
33
  "when 'value1'",
34
34
  " 'output1'",
@@ -41,7 +41,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
41
41
  'end')
42
42
  end
43
43
 
44
- it 'registers on offense for an assignment indented some other way' do
44
+ it 'registers an offense for an assignment indented some other way' do
45
45
  source = ['output = case variable',
46
46
  " when 'value1'",
47
47
  " 'output1'",
@@ -53,7 +53,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
53
53
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
54
54
  end
55
55
 
56
- it 'registers on offense for correct + opposite' do
56
+ it 'registers an offense for correct + opposite' do
57
57
  source = ['output = case variable',
58
58
  " when 'value1'",
59
59
  " 'output1'",
@@ -166,7 +166,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
166
166
  expect(cop.offenses).to be_empty
167
167
  end
168
168
 
169
- it 'registers on offense for an assignment indented some other way' do
169
+ it 'registers an offense for an assignment indented some other way' do
170
170
  source = ['output = case variable',
171
171
  " when 'value1'",
172
172
  " 'output1'",
@@ -191,7 +191,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
191
191
  expect(cop.offenses).to be_empty
192
192
  end
193
193
 
194
- it "registers an offense for a when clause that's equally indented " \
194
+ it "registers an offense for a when clause that's equally indented " \
195
195
  'with case' do
196
196
  source = ['y = case a',
197
197
  ' when 0 then break',
@@ -230,7 +230,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
230
230
  expect(cop.offenses).to be_empty
231
231
  end
232
232
 
233
- it 'registers on offense for an assignment indented some other way' do
233
+ it 'registers an offense for an assignment indented some other way' do
234
234
  source = ['output = case variable',
235
235
  " when 'value1'",
236
236
  " 'output1'",
@@ -260,7 +260,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
260
260
  expect(cop.offenses).to be_empty
261
261
  end
262
262
 
263
- it 'registers on offense for an assignment indented as case' do
263
+ it 'registers an offense for an assignment indented as case' do
264
264
  source = ['output = case variable',
265
265
  " when 'value1'",
266
266
  " 'output1'",
@@ -274,7 +274,7 @@ describe RuboCop::Cop::Style::CaseIndentation do
274
274
  'case')
275
275
  end
276
276
 
277
- it 'registers on offense for an assignment indented some other way' do
277
+ it 'registers an offense for an assignment indented some other way' do
278
278
  source = ['output = case variable',
279
279
  " when 'value1'",
280
280
  " 'output1'",
@@ -33,7 +33,11 @@ describe RuboCop::Cop::Style::DefWithParentheses do
33
33
  end
34
34
 
35
35
  it 'auto-removes unneeded parens' do
36
- new_source = autocorrect_source(cop, "def test();\nsomething\nend")
37
- expect(new_source).to eq("def test;\nsomething\nend")
36
+ new_source = autocorrect_source(cop, ['def test();',
37
+ 'something',
38
+ 'end'])
39
+ expect(new_source).to eq(['def test;',
40
+ 'something',
41
+ 'end'].join("\n"))
38
42
  end
39
43
  end
@@ -45,6 +45,31 @@ describe RuboCop::Cop::Style::DotPosition, :config do
45
45
  inspect_source(cop, ['something.method_name'])
46
46
  expect(cop.offenses).to be_empty
47
47
  end
48
+
49
+ it 'auto-corrects trailing dot in multi-line call' do
50
+ new_source = autocorrect_source(cop, ['something.',
51
+ ' method_name'])
52
+ expect(new_source).to eq(['something',
53
+ ' .method_name'].join("\n"))
54
+ end
55
+
56
+ it 'auto-corrects trailing dot in multi-line call without selector' do
57
+ new_source = autocorrect_source(cop, ['something.',
58
+ ' (1)'])
59
+ expect(new_source).to eq(['something',
60
+ ' .(1)'].join("\n"))
61
+ end
62
+
63
+ it 'auto-corrects correct + opposite style' do
64
+ new_source = autocorrect_source(cop, ['something',
65
+ ' .method_name',
66
+ 'something.',
67
+ ' method_name'])
68
+ expect(new_source).to eq(['something',
69
+ ' .method_name',
70
+ 'something',
71
+ ' .method_name'].join("\n"))
72
+ end
48
73
  end
49
74
 
50
75
  context 'Trailing dots style' do
@@ -87,5 +112,19 @@ describe RuboCop::Cop::Style::DotPosition, :config do
87
112
  'compact.join("\n")'])
88
113
  expect(cop.offenses).to be_empty
89
114
  end
115
+
116
+ it 'auto-corrects leading dot in multi-line call' do
117
+ new_source = autocorrect_source(cop, ['something',
118
+ ' .method_name'])
119
+ expect(new_source).to eq(['something.',
120
+ ' method_name'].join("\n"))
121
+ end
122
+
123
+ it 'auto-corrects leading dot in multi-line call without selector' do
124
+ new_source = autocorrect_source(cop, ['something',
125
+ ' .(1)'])
126
+ expect(new_source).to eq(['something.',
127
+ ' (1)'].join("\n"))
128
+ end
90
129
  end
91
130
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe RuboCop::Cop::Style::EmptyLinesAroundAccessModifier do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
- %w(private protected public).each do |access_modifier|
8
+ %w(private protected public module_function).each do |access_modifier|
9
9
  it "requires blank line before #{access_modifier}" do
10
10
  inspect_source(cop,
11
11
  ['class Test',
@@ -19,7 +19,7 @@ describe RuboCop::Cop::Style::EmptyLinesAroundAccessModifier do
19
19
  .to eq(["Keep a blank line before and after `#{access_modifier}`."])
20
20
  end
21
21
 
22
- it 'requires blank line after #{access_modifier}' do
22
+ it "requires blank line after #{access_modifier}" do
23
23
  inspect_source(cop,
24
24
  ['class Test',
25
25
  ' something',
@@ -76,6 +76,16 @@ describe RuboCop::Cop::Style::EmptyLinesAroundAccessModifier do
76
76
  expect(cop.offenses).to be_empty
77
77
  end
78
78
 
79
+ it 'accepts missing blank line when at the end of block' do
80
+ inspect_source(cop,
81
+ ['class Test',
82
+ ' def test; end',
83
+ '',
84
+ " #{access_modifier}",
85
+ 'end'])
86
+ expect(cop.offenses).to be_empty
87
+ end
88
+
79
89
  it 'recognizes blank lines with DOS style line endings' do
80
90
  inspect_source(cop,
81
91
  ["class Test\r",
@@ -11,14 +11,14 @@ describe RuboCop::Cop::Style::Encoding, :config do
11
11
  end
12
12
 
13
13
  it 'registers no offense when no encoding present but only ASCII ' \
14
- 'characters', ruby: 1.9 do
14
+ 'characters' do
15
15
  inspect_source(cop, ['def foo() end'])
16
16
 
17
17
  expect(cop.offenses).to be_empty
18
18
  end
19
19
 
20
20
  it 'registers an offense when there is no encoding present but non ' \
21
- 'ASCII characters', ruby: 1.9 do
21
+ 'ASCII characters' do
22
22
  inspect_source(cop, ['def foo() \'ä\' end'])
23
23
 
24
24
  expect(cop.offenses.size).to eq(1)
@@ -27,7 +27,7 @@ describe RuboCop::Cop::Style::Encoding, :config do
27
27
  end
28
28
 
29
29
  it 'registers an offense when encoding present but only ASCII ' \
30
- 'characters', ruby: 1.9 do
30
+ 'characters' do
31
31
  inspect_source(cop, ['# encoding: utf-8',
32
32
  'def foo() end'])
33
33
 
@@ -36,20 +36,20 @@ describe RuboCop::Cop::Style::Encoding, :config do
36
36
  ['Unnecessary utf-8 encoding comment.'])
37
37
  end
38
38
 
39
- it 'accepts an empty file', ruby: 1.9 do
39
+ it 'accepts an empty file' do
40
40
  inspect_source(cop, '')
41
41
 
42
42
  expect(cop.offenses).to be_empty
43
43
  end
44
44
 
45
- it 'accepts encoding on first line', ruby: 1.9 do
45
+ it 'accepts encoding on first line' do
46
46
  inspect_source(cop, ['# encoding: utf-8',
47
47
  'def foo() \'ä\' end'])
48
48
 
49
49
  expect(cop.offenses).to be_empty
50
50
  end
51
51
 
52
- it 'accepts encoding on second line when shebang present', ruby: 1.9 do
52
+ it 'accepts encoding on second line when shebang present' do
53
53
  inspect_source(cop, ['#!/usr/bin/env ruby',
54
54
  '# encoding: utf-8',
55
55
  'def foo() \'ä\' end'])
@@ -57,7 +57,7 @@ describe RuboCop::Cop::Style::Encoding, :config do
57
57
  expect(cop.messages).to be_empty
58
58
  end
59
59
 
60
- it 'books an offense when encoding is in the wrong place', ruby: 1.9 do
60
+ it 'books an offense when encoding is in the wrong place' do
61
61
  inspect_source(cop, ['def foo() \'ä\' end',
62
62
  '# encoding: utf-8'])
63
63
 
@@ -66,20 +66,14 @@ describe RuboCop::Cop::Style::Encoding, :config do
66
66
  ['Missing utf-8 encoding comment.'])
67
67
  end
68
68
 
69
- it 'does not register an offense on Ruby 2.0', ruby: 2.0 do
70
- inspect_source(cop, ['def foo() \'ä\' end'])
71
-
72
- expect(cop.offenses).to be_empty
73
- end
74
-
75
- it 'accepts encoding inserted by magic_encoding gem', ruby: 1.9 do
69
+ it 'accepts encoding inserted by magic_encoding gem' do
76
70
  inspect_source(cop, ['# -*- encoding : utf-8 -*-',
77
71
  'def foo() \'ä\' end'])
78
72
 
79
73
  expect(cop.messages).to be_empty
80
74
  end
81
75
 
82
- it 'accepts vim-style encoding comments', ruby: 1.9 do
76
+ it 'accepts vim-style encoding comments' do
83
77
  inspect_source(cop, ['# vim:fileencoding=utf-8',
84
78
  'def foo() \'ä\' end'])
85
79
  expect(cop.messages).to be_empty
@@ -91,7 +85,7 @@ describe RuboCop::Cop::Style::Encoding, :config do
91
85
  { 'EnforcedStyle' => 'always' }
92
86
  end
93
87
 
94
- it 'registers an offense when no encoding present', ruby: 1.9 do
88
+ it 'registers an offense when no encoding present' do
95
89
  inspect_source(cop, ['def foo() end'])
96
90
 
97
91
  expect(cop.offenses.size).to eq(1)
@@ -99,20 +93,20 @@ describe RuboCop::Cop::Style::Encoding, :config do
99
93
  ['Missing utf-8 encoding comment.'])
100
94
  end
101
95
 
102
- it 'accepts an empty file', ruby: 1.9 do
96
+ it 'accepts an empty file' do
103
97
  inspect_source(cop, '')
104
98
 
105
99
  expect(cop.offenses).to be_empty
106
100
  end
107
101
 
108
- it 'accepts encoding on first line', ruby: 1.9 do
102
+ it 'accepts encoding on first line' do
109
103
  inspect_source(cop, ['# encoding: utf-8',
110
104
  'def foo() end'])
111
105
 
112
106
  expect(cop.offenses).to be_empty
113
107
  end
114
108
 
115
- it 'accepts encoding on second line when shebang present', ruby: 1.9 do
109
+ it 'accepts encoding on second line when shebang present' do
116
110
  inspect_source(cop, ['#!/usr/bin/env ruby',
117
111
  '# encoding: utf-8',
118
112
  'def foo() end'])
@@ -120,7 +114,7 @@ describe RuboCop::Cop::Style::Encoding, :config do
120
114
  expect(cop.messages).to be_empty
121
115
  end
122
116
 
123
- it 'books an offense when encoding is in the wrong place', ruby: 1.9 do
117
+ it 'books an offense when encoding is in the wrong place' do
124
118
  inspect_source(cop, ['def foo() end',
125
119
  '# encoding: utf-8'])
126
120
 
@@ -129,20 +123,14 @@ describe RuboCop::Cop::Style::Encoding, :config do
129
123
  ['Missing utf-8 encoding comment.'])
130
124
  end
131
125
 
132
- it 'does not register an offense on Ruby 2.0', ruby: 2.0 do
133
- inspect_source(cop, ['def foo() end'])
134
-
135
- expect(cop.offenses).to be_empty
136
- end
137
-
138
- it 'accepts encoding inserted by magic_encoding gem', ruby: 1.9 do
126
+ it 'accepts encoding inserted by magic_encoding gem' do
139
127
  inspect_source(cop, ['# -*- encoding : utf-8 -*-',
140
128
  'def foo() end'])
141
129
 
142
130
  expect(cop.messages).to be_empty
143
131
  end
144
132
 
145
- it 'accepts vim-style encoding comments', ruby: 1.9 do
133
+ it 'accepts vim-style encoding comments' do
146
134
  inspect_source(cop, ['# vim:fileencoding=utf-8',
147
135
  'def foo() end'])
148
136
  expect(cop.messages).to be_empty