rubocop 0.20.1 → 0.21.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +16 -4
  4. data/config/default.yml +37 -10
  5. data/config/enabled.yml +25 -7
  6. data/lib/rubocop.rb +15 -19
  7. data/lib/rubocop/cli.rb +2 -2
  8. data/lib/rubocop/config.rb +40 -3
  9. data/lib/rubocop/config_loader.rb +6 -37
  10. data/lib/rubocop/config_store.rb +0 -1
  11. data/lib/rubocop/cop/commissioner.rb +12 -9
  12. data/lib/rubocop/cop/cop.rb +17 -5
  13. data/lib/rubocop/cop/force.rb +41 -0
  14. data/lib/rubocop/cop/ignored_node.rb +10 -10
  15. data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
  16. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
  17. data/lib/rubocop/cop/lint/block_alignment.rb +2 -2
  18. data/lib/rubocop/cop/lint/condition_position.rb +2 -0
  19. data/lib/rubocop/cop/lint/debugger.rb +17 -3
  20. data/lib/rubocop/cop/lint/end_alignment.rb +3 -11
  21. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  22. data/lib/rubocop/cop/lint/rescue_exception.rb +11 -0
  23. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -6
  24. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +39 -0
  25. data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -0
  26. data/lib/rubocop/cop/lint/unused_method_argument.rb +52 -0
  27. data/lib/rubocop/cop/lint/useless_assignment.rb +6 -8
  28. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -0
  29. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  30. data/lib/rubocop/cop/lint/void.rb +1 -1
  31. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
  32. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +7 -3
  33. data/lib/rubocop/cop/mixin/check_assignment.rb +11 -0
  34. data/lib/rubocop/cop/mixin/check_methods.rb +12 -0
  35. data/lib/rubocop/cop/mixin/percent_literal.rb +26 -0
  36. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
  37. data/lib/rubocop/cop/mixin/string_help.rb +0 -4
  38. data/lib/rubocop/cop/rails/delegate.rb +109 -0
  39. data/lib/rubocop/cop/style/align_hash.rb +3 -3
  40. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  41. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  42. data/lib/rubocop/cop/style/dot_position.rb +1 -1
  43. data/lib/rubocop/cop/style/encoding.rb +44 -16
  44. data/lib/rubocop/cop/style/indentation_width.rb +29 -19
  45. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  46. data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
  47. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -21
  48. data/lib/rubocop/cop/style/predicate_name.rb +1 -1
  49. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  50. data/lib/rubocop/cop/style/redundant_begin.rb +18 -2
  51. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  52. data/lib/rubocop/cop/style/regexp_literal.rb +29 -37
  53. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
  54. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  55. data/lib/rubocop/cop/style/trailing_blank_lines.rb +37 -23
  56. data/lib/rubocop/cop/style/trailing_comma.rb +2 -3
  57. data/lib/rubocop/cop/style/trivial_accessors.rb +40 -4
  58. data/lib/rubocop/cop/style/unneeded_capital_w.rb +29 -0
  59. data/lib/rubocop/cop/team.rb +10 -2
  60. data/lib/rubocop/cop/util.rb +2 -2
  61. data/lib/rubocop/cop/{variable_inspector.rb → variable_force.rb} +45 -37
  62. data/lib/rubocop/cop/{variable_inspector → variable_force}/assignment.rb +1 -1
  63. data/lib/rubocop/cop/{variable_inspector → variable_force}/locatable.rb +1 -1
  64. data/lib/rubocop/cop/{variable_inspector → variable_force}/reference.rb +13 -1
  65. data/lib/rubocop/cop/{variable_inspector → variable_force}/scope.rb +9 -1
  66. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable.rb +14 -4
  67. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable_table.rb +1 -1
  68. data/lib/rubocop/file_inspector.rb +3 -1
  69. data/lib/rubocop/formatter/base_formatter.rb +1 -1
  70. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
  71. data/lib/rubocop/formatter/disabled_lines_formatter.rb +2 -2
  72. data/lib/rubocop/formatter/offense_count_formatter.rb +11 -10
  73. data/lib/rubocop/formatter/progress_formatter.rb +2 -2
  74. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  75. data/lib/rubocop/options.rb +74 -58
  76. data/lib/rubocop/path_util.rb +17 -2
  77. data/lib/rubocop/rake_task.rb +23 -5
  78. data/lib/rubocop/version.rb +1 -1
  79. data/relnotes/v0.21.0.md +45 -0
  80. data/rubocop-todo.yml +6 -6
  81. data/rubocop.gemspec +1 -1
  82. data/spec/rubocop/cli_spec.rb +170 -59
  83. data/spec/rubocop/config_spec.rb +48 -3
  84. data/spec/rubocop/config_store_spec.rb +3 -3
  85. data/spec/rubocop/cop/commissioner_spec.rb +9 -7
  86. data/spec/rubocop/cop/cop_spec.rb +0 -2
  87. data/spec/rubocop/cop/force_spec.rb +29 -0
  88. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
  89. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
  90. data/spec/rubocop/cop/lint/block_alignment_spec.rb +24 -24
  91. data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -5
  92. data/spec/rubocop/cop/lint/debugger_spec.rb +26 -9
  93. data/spec/rubocop/cop/lint/end_alignment_spec.rb +6 -3
  94. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +7 -6
  95. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +36 -0
  96. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
  97. data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +179 -0
  98. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +147 -0
  99. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +140 -0
  100. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +50 -48
  101. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +1 -1
  102. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +2 -0
  103. data/spec/rubocop/cop/rails/delegate_spec.rb +152 -0
  104. data/spec/rubocop/cop/style/encoding_spec.rb +131 -36
  105. data/spec/rubocop/cop/style/indentation_width_spec.rb +79 -0
  106. data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
  107. data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -13
  108. data/spec/rubocop/cop/style/string_literals_spec.rb +9 -3
  109. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +65 -25
  110. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +76 -0
  111. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +85 -0
  112. data/spec/rubocop/cop/team_spec.rb +43 -0
  113. data/spec/rubocop/cop/{variable_inspector → variable_force}/assignment_spec.rb +3 -3
  114. data/spec/rubocop/cop/{variable_inspector → variable_force}/locatable_spec.rb +3 -3
  115. data/spec/rubocop/cop/{variable_inspector → variable_force}/scope_spec.rb +30 -2
  116. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_spec.rb +12 -27
  117. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_table_spec.rb +1 -1
  118. data/spec/rubocop/cop/{variable_inspector_spec.rb → variable_force_spec.rb} +4 -8
  119. data/spec/rubocop/formatter/base_formatter_spec.rb +2 -2
  120. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +1 -1
  121. data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
  122. data/spec/rubocop/options_spec.rb +2 -2
  123. data/spec/rubocop/path_util_spec.rb +47 -14
  124. data/spec/spec_helper.rb +9 -3
  125. data/spec/support/file_helper.rb +2 -0
  126. metadata +43 -26
  127. data/lib/rubocop/cop/style/final_newline.rb +0 -29
  128. data/spec/rubocop/cop/style/final_newline_spec.rb +0 -30
@@ -78,7 +78,7 @@ describe Rubocop::Config do
78
78
  let(:hash) do
79
79
  {
80
80
  'AllCops' => {
81
- 'Include' => ['Gemfile', 'config/unicorn.rb.example']
81
+ 'Include' => ['**/Gemfile', 'config/unicorn.rb.example']
82
82
  }
83
83
  }
84
84
  end
@@ -101,6 +101,9 @@ describe Rubocop::Config do
101
101
  end
102
102
 
103
103
  describe '#file_to_exclude?' do
104
+ before { $stderr = StringIO.new }
105
+ after { $stderr = STDERR }
106
+
104
107
  let(:hash) do
105
108
  {
106
109
  'AllCops' => {
@@ -139,14 +142,14 @@ describe Rubocop::Config do
139
142
  let(:hash) do
140
143
  {
141
144
  'AllCops' => {
142
- 'Include' => ['Gemfile', 'config/unicorn.rb.example']
145
+ 'Include' => ['**/Gemfile', 'config/unicorn.rb.example']
143
146
  }
144
147
  }
145
148
  end
146
149
 
147
150
  it 'returns the Include value' do
148
151
  expect(patterns_to_include).to eq([
149
- 'Gemfile',
152
+ '**/Gemfile',
150
153
  'config/unicorn.rb.example'
151
154
  ])
152
155
  end
@@ -176,4 +179,46 @@ describe Rubocop::Config do
176
179
  end
177
180
  end
178
181
  end
182
+
183
+ describe '#deprecation_check' do
184
+ context 'when there is no AllCops configuration' do
185
+ let(:hash) { {} }
186
+
187
+ it 'does not yield' do
188
+ expect { |b| configuration.deprecation_check(&b) }.not_to yield_control
189
+ end
190
+ end
191
+
192
+ context 'when there is AllCops configuration' do
193
+ context 'if there are no Excludes or Includes keys' do
194
+ let(:hash) { { 'AllCops' => { 'Exclude' => [], 'Include' => [] } } }
195
+
196
+ it 'does not yield' do
197
+ expect do |b|
198
+ configuration.deprecation_check(&b)
199
+ end.not_to yield_control
200
+ end
201
+ end
202
+
203
+ context 'if there are is an Includes key' do
204
+ let(:hash) { { 'AllCops' => { 'Includes' => [] } } }
205
+
206
+ it 'yields' do
207
+ expect do |b|
208
+ configuration.deprecation_check(&b)
209
+ end.to yield_with_args(String)
210
+ end
211
+ end
212
+
213
+ context 'if there are is an Excludes key' do
214
+ let(:hash) { { 'AllCops' => { 'Excludes' => [] } } }
215
+
216
+ it 'yields' do
217
+ expect do |b|
218
+ configuration.deprecation_check(&b)
219
+ end.to yield_with_args(String)
220
+ end
221
+ end
222
+ end
223
+ end
179
224
  end
@@ -17,15 +17,15 @@ describe Rubocop::ConfigStore do
17
17
  allow(Rubocop::ConfigLoader)
18
18
  .to receive(:configuration_from_file) { |arg| arg }
19
19
  allow(Rubocop::ConfigLoader)
20
- .to receive(:load_file) { |arg| "#{arg} loaded" }
20
+ .to receive(:load_file) { |arg| Rubocop::Config.new(arg) }
21
21
  allow(Rubocop::ConfigLoader)
22
- .to receive(:merge_with_default) { |config, file| "merged #{config}" }
22
+ .to receive(:merge_with_default) { |config| "merged #{config}" }
23
23
  end
24
24
 
25
25
  describe '.for' do
26
26
  it 'always uses config specified in command line' do
27
27
  config_store.options_config = :options_config
28
- expect(config_store.for('file1')).to eq('merged options_config loaded')
28
+ expect(config_store.for('file1')).to eq('merged options_config')
29
29
  end
30
30
 
31
31
  context 'when no config specified in command line' do
@@ -6,11 +6,12 @@ require 'spec_helper'
6
6
  describe Rubocop::Cop::Commissioner do
7
7
  describe '#investigate' do
8
8
  let(:cop) { double(Rubocop::Cop, offenses: []).as_null_object }
9
+ let(:force) { double(Rubocop::Cop::Force).as_null_object }
9
10
 
10
11
  it 'returns all offenses found by the cops' do
11
12
  allow(cop).to receive(:offenses).and_return([1])
12
13
 
13
- commissioner = described_class.new([cop])
14
+ commissioner = described_class.new([cop], [])
14
15
  source = []
15
16
  processed_source = parse_source(source)
16
17
 
@@ -25,7 +26,7 @@ describe Rubocop::Cop::Commissioner do
25
26
  cops << double('cop C', offenses: %w(baz), relevant_file?: true)
26
27
  cops.each(&:as_null_object)
27
28
 
28
- commissioner = described_class.new(cops)
29
+ commissioner = described_class.new(cops, [])
29
30
  source = []
30
31
  processed_source = parse_source(source)
31
32
 
@@ -36,19 +37,20 @@ describe Rubocop::Cop::Commissioner do
36
37
  it 'traverses the AST and invoke cops specific callbacks' do
37
38
  expect(cop).to receive(:on_def)
38
39
 
39
- commissioner = described_class.new([cop])
40
+ commissioner = described_class.new([cop], [])
40
41
  source = ['def method', '1', 'end']
41
42
  processed_source = parse_source(source)
42
43
 
43
44
  commissioner.investigate(processed_source)
44
45
  end
45
46
 
46
- it 'passes the input params to all cops that implement their own #investigate method' do
47
+ it 'passes the input params to all cops/forces that implement their own #investigate method' do
47
48
  source = []
48
49
  processed_source = parse_source(source)
49
50
  expect(cop).to receive(:investigate).with(processed_source)
51
+ expect(force).to receive(:investigate).with(processed_source)
50
52
 
51
- commissioner = described_class.new([cop])
53
+ commissioner = described_class.new([cop], [force])
52
54
 
53
55
  commissioner.investigate(processed_source)
54
56
  end
@@ -56,7 +58,7 @@ describe Rubocop::Cop::Commissioner do
56
58
  it 'stores all errors raised by the cops' do
57
59
  allow(cop).to receive(:on_def) { fail RuntimeError }
58
60
 
59
- commissioner = described_class.new([cop])
61
+ commissioner = described_class.new([cop], [])
60
62
  source = ['def method', '1', 'end']
61
63
  processed_source = parse_source(source)
62
64
 
@@ -70,7 +72,7 @@ describe Rubocop::Cop::Commissioner do
70
72
  it 're-raises the exception received while processing' do
71
73
  allow(cop).to receive(:on_def) { fail RuntimeError }
72
74
 
73
- commissioner = described_class.new([cop], raise_error: true)
75
+ commissioner = described_class.new([cop], [], raise_error: true)
74
76
  source = ['def method', '1', 'end']
75
77
  processed_source = parse_source(source)
76
78
 
@@ -81,8 +81,6 @@ describe Rubocop::Cop::Cop do
81
81
  it('has types') { expect(subject.length).not_to eq(0) }
82
82
  it { should include :lint }
83
83
  it do
84
- pending 'Rails cops are usually removed after CLI start, ' \
85
- 'so CLI spec impacts this one'
86
84
  should include :rails
87
85
  end
88
86
  it { should include :style }
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Rubocop::Cop::Force do
6
+ subject(:force) { Rubocop::Cop::Force.new(cops) }
7
+ let(:cops) { [double('cop1'), double('cop2')] }
8
+
9
+ describe '.force_name' do
10
+ it 'returns the class name without namespace' do
11
+ expect(Rubocop::Cop::VariableForce.force_name).to eq('VariableForce')
12
+ end
13
+ end
14
+
15
+ describe '#run_hook' do
16
+ it 'invokes a hook in all cops' do
17
+ cops.each do |cop|
18
+ expect(cop).to receive(:some_hook).with(:foo, :bar)
19
+ end
20
+
21
+ force.run_hook(:some_hook, :foo, :bar)
22
+ end
23
+
24
+ it 'does not invoke a hook if the cop does not respond to the hook' do
25
+ expect(cops.last).to receive(:some_hook).with(:foo, :bar)
26
+ force.run_hook(:some_hook, :foo, :bar)
27
+ end
28
+ end
29
+ end
@@ -25,7 +25,7 @@ describe Rubocop::Cop::Lint::AmbiguousOperator do
25
25
  'Ambiguous splat operator. ' \
26
26
  "Parenthesize the method arguments if it's surely a splat " \
27
27
  'operator, ' \
28
- 'or add a whitespace to the right of the * if it should be a ' \
28
+ 'or add a whitespace to the right of the `*` if it should be a ' \
29
29
  'multiplication.'
30
30
  )
31
31
  expect(cop.highlights).to eq(['*'])
@@ -76,7 +76,7 @@ describe Rubocop::Cop::Lint::AmbiguousOperator do
76
76
  'Ambiguous block operator. ' \
77
77
  "Parenthesize the method arguments if it's surely a block " \
78
78
  'operator, ' \
79
- 'or add a whitespace to the right of the & if it should be a ' \
79
+ 'or add a whitespace to the right of the `&` if it should be a ' \
80
80
  'binary AND.'
81
81
  )
82
82
  expect(cop.highlights).to eq(['&'])
@@ -18,7 +18,7 @@ describe Rubocop::Cop::Lint::AmbiguousRegexpLiteral do
18
18
  expect(cop.offenses.first.message).to eq(
19
19
  'Ambiguous regexp literal. Parenthesize the method arguments ' \
20
20
  "if it's surely a regexp literal, or add a whitespace to the " \
21
- 'right of the / if it should be a division.'
21
+ 'right of the `/` if it should be a division.'
22
22
  )
23
23
  expect(cop.highlights).to eq(['/'])
24
24
  end
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
12
12
  ' end'
13
13
  ])
14
14
  expect(cop.messages)
15
- .to eq(['end at 2, 2 is not aligned with test do |ala| at 1, 0'])
15
+ .to eq(['`end` at 2, 2 is not aligned with `test do |ala|` at 1, 0'])
16
16
  end
17
17
 
18
18
  context 'when the block is a logical operand' do
@@ -43,7 +43,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
43
43
  ' end'
44
44
  ])
45
45
  expect(cop.messages)
46
- .to eq(['end at 2, 4 is not aligned with a = b = c = test do |ala| at 1, 0'])
46
+ .to eq(['`end` at 2, 4 is not aligned with `a = b = c = test do |ala|` at 1, 0'])
47
47
  end
48
48
 
49
49
  it 'accepts end aligned with the first variable' do
@@ -72,7 +72,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
72
72
  ' end'
73
73
  ])
74
74
  expect(cop.messages)
75
- .to eq(['end at 2, 2 is not aligned with variable = test do |ala| at 1, 0'])
75
+ .to eq(['`end` at 2, 2 is not aligned with `variable = test do |ala|` at 1, 0'])
76
76
  end
77
77
 
78
78
  context 'when the block is defined on the next line' do
@@ -94,8 +94,8 @@ describe Rubocop::Cop::Lint::BlockAlignment do
94
94
  'end'
95
95
  ])
96
96
  expect(cop.messages)
97
- .to eq(['end at 4, 0 is not aligned with a_long_method_that_dont_fit_on_the_line ' \
98
- 'do |v| at 2, 2'])
97
+ .to eq(['`end` at 4, 0 is not aligned with `a_long_method_that_dont_fit_on_the_line ' \
98
+ 'do |v|` at 2, 2'])
99
99
  end
100
100
  end
101
101
 
@@ -131,12 +131,12 @@ describe Rubocop::Cop::Lint::BlockAlignment do
131
131
  'end']
132
132
  inspect_source(cop, src)
133
133
  expect(cop.messages)
134
- .to eq(['end at 5, 8 is not aligned with bar.get_stuffs at 2, 2 or' \
135
- ' .reject do |stuff| at 3, 6',
136
- 'end at 7, 4 is not aligned with bar.get_stuffs at 2, 2 or' \
137
- ' end.select do |stuff| at 5, 8',
138
- 'end at 10, 8 is not aligned with bar.get_stuffs at 2, 2 or' \
139
- ' .select do |stuff| at 8, 6'])
134
+ .to eq(['`end` at 5, 8 is not aligned with `bar.get_stuffs` at 2, 2 or' \
135
+ ' `.reject do |stuff|` at 3, 6',
136
+ '`end` at 7, 4 is not aligned with `bar.get_stuffs` at 2, 2 or' \
137
+ ' `end.select do |stuff|` at 5, 8',
138
+ '`end` at 10, 8 is not aligned with `bar.get_stuffs` at 2, 2 or' \
139
+ ' `.select do |stuff|` at 8, 6'])
140
140
  end
141
141
 
142
142
  # Example from issue 393 of bbatsov/rubocop on github:
@@ -192,7 +192,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
192
192
  ' end']
193
193
  inspect_source(cop, src)
194
194
  expect(cop.messages)
195
- .to eq(['end at 4, 4 is not aligned with e, at 1, 0 or f = [5, 6].map do |i| at 2, 0'])
195
+ .to eq(['`end` at 4, 4 is not aligned with `e,` at 1, 0 or `f = [5, 6].map do |i|` at 2, 0'])
196
196
  end
197
197
  end
198
198
 
@@ -210,7 +210,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
210
210
  ' end'
211
211
  ])
212
212
  expect(cop.messages)
213
- .to eq(['end at 2, 2 is not aligned with @variable = test do |ala| at 1, 0'])
213
+ .to eq(['`end` at 2, 2 is not aligned with `@variable = test do |ala|` at 1, 0'])
214
214
  end
215
215
 
216
216
  it 'accepts end aligned with a class variable' do
@@ -227,7 +227,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
227
227
  ' end'
228
228
  ])
229
229
  expect(cop.messages)
230
- .to eq(['end at 2, 2 is not aligned with @@variable = test do |ala| at 1, 0'])
230
+ .to eq(['`end` at 2, 2 is not aligned with `@@variable = test do |ala|` at 1, 0'])
231
231
  end
232
232
 
233
233
  it 'accepts end aligned with a global variable' do
@@ -244,7 +244,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
244
244
  ' end'
245
245
  ])
246
246
  expect(cop.messages)
247
- .to eq(['end at 2, 2 is not aligned with $variable = test do |ala| at 1, 0'])
247
+ .to eq(['`end` at 2, 2 is not aligned with `$variable = test do |ala|` at 1, 0'])
248
248
  end
249
249
 
250
250
  it 'accepts end aligned with a constant' do
@@ -261,7 +261,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
261
261
  ' end'
262
262
  ])
263
263
  expect(cop.messages)
264
- .to eq(['end at 2, 2 is not aligned with Module::CONSTANT = test do |ala| at 1, 0'])
264
+ .to eq(['`end` at 2, 2 is not aligned with `Module::CONSTANT = test do |ala|` at 1, 0'])
265
265
  end
266
266
 
267
267
  it 'accepts end aligned with a method call' do
@@ -280,7 +280,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
280
280
  ' end'
281
281
  ])
282
282
  expect(cop.messages)
283
- .to eq(['end at 3, 2 is not aligned with parser.childs << lambda do |token| at 1, 0'])
283
+ .to eq(['`end` at 3, 2 is not aligned with `parser.childs << lambda do |token|` at 1, 0'])
284
284
  end
285
285
 
286
286
  it 'accepts end aligned with a method call with arguments' do
@@ -299,7 +299,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
299
299
  ' end'
300
300
  ])
301
301
  expect(cop.messages)
302
- .to eq(['end at 3, 2 is not aligned with @h[:f] = f.each_pair.map do |f, v| at 1, 0'])
302
+ .to eq(['`end` at 3, 2 is not aligned with `@h[:f] = f.each_pair.map do |f, v|` at 1, 0'])
303
303
  end
304
304
 
305
305
  it 'does not raise an error for nested block in a method call' do
@@ -325,8 +325,8 @@ describe Rubocop::Cop::Lint::BlockAlignment do
325
325
  ' end)'
326
326
  ])
327
327
  expect(cop.messages)
328
- .to eq(['end at 3, 2 is not aligned with arr.all? do |o| at 1, 7 or ' \
329
- 'expect(arr.all? do |o| at 1, 0'])
328
+ .to eq(['`end` at 3, 2 is not aligned with `arr.all? do |o|` at 1, 7 or ' \
329
+ '`expect(arr.all? do |o|` at 1, 0'])
330
330
  end
331
331
 
332
332
  it 'accepts end aligned with an op-asgn (+=, -=)' do
@@ -345,7 +345,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
345
345
  ' end'
346
346
  ])
347
347
  expect(cop.messages)
348
- .to eq(['end at 3, 2 is not aligned with rb at 1, 0'])
348
+ .to eq(['`end` at 3, 2 is not aligned with `rb` at 1, 0'])
349
349
  end
350
350
 
351
351
  it 'accepts end aligned with an and-asgn (&&=)' do
@@ -362,7 +362,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
362
362
  ' end'
363
363
  ])
364
364
  expect(cop.messages)
365
- .to eq(['end at 2, 2 is not aligned with variable &&= test do |ala| at 1, 0'])
365
+ .to eq(['`end` at 2, 2 is not aligned with `variable &&= test do |ala|` at 1, 0'])
366
366
  end
367
367
 
368
368
  it 'accepts end aligned with an or-asgn (||=)' do
@@ -379,7 +379,7 @@ describe Rubocop::Cop::Lint::BlockAlignment do
379
379
  ' end'
380
380
  ])
381
381
  expect(cop.messages)
382
- .to eq(['end at 2, 2 is not aligned with variable ||= test do |ala| at 1, 0'])
382
+ .to eq(['`end` at 2, 2 is not aligned with `variable ||= test do |ala|` at 1, 0'])
383
383
  end
384
384
 
385
385
  it 'accepts end aligned with a mass assignment' do
@@ -406,6 +406,6 @@ describe Rubocop::Cop::Lint::BlockAlignment do
406
406
  ' end'
407
407
  ])
408
408
  expect(cop.messages)
409
- .to eq(['end at 3, 2 is not aligned with var1, var2 at 1, 0'])
409
+ .to eq(['`end` at 3, 2 is not aligned with `var1, var2` at 1, 0'])
410
410
  end
411
411
  end
@@ -23,6 +23,13 @@ describe Rubocop::Cop::Lint::ConditionPosition do
23
23
  ])
24
24
  expect(cop.offenses).to be_empty
25
25
  end
26
+
27
+ it 'accepts condition on a different line for modifiers' do
28
+ inspect_source(cop,
29
+ ["do_something #{keyword}",
30
+ ' something && something_else'])
31
+ expect(cop.offenses).to be_empty
32
+ end
26
33
  end
27
34
 
28
35
  it 'registers an offense for elsif condition on the next line' do
@@ -41,9 +48,4 @@ describe Rubocop::Cop::Lint::ConditionPosition do
41
48
  inspect_source(cop, ['x ? a : b'])
42
49
  expect(cop.offenses).to be_empty
43
50
  end
44
-
45
- it 'handles modifier forms' do
46
- inspect_source(cop, ['x if something'])
47
- expect(cop.offenses).to be_empty
48
- end
49
51
  end
@@ -9,6 +9,16 @@ describe Rubocop::Cop::Lint::Debugger do
9
9
  src = ['debugger']
10
10
  inspect_source(cop, src)
11
11
  expect(cop.offenses.size).to eq(1)
12
+ expect(cop.messages).to eq(['Remove debugger entry point `debugger`.'])
13
+ expect(cop.highlights).to eq(['debugger'])
14
+ end
15
+
16
+ it 'reports an offense for a byebug call' do
17
+ src = ['byebug']
18
+ inspect_source(cop, src)
19
+ expect(cop.offenses.size).to eq(1)
20
+ expect(cop.messages).to eq(['Remove debugger entry point `byebug`.'])
21
+ expect(cop.highlights).to eq(['byebug'])
12
22
  end
13
23
 
14
24
  it 'reports an offense for pry bindings' do
@@ -16,6 +26,10 @@ describe Rubocop::Cop::Lint::Debugger do
16
26
  'binding.remote_pry']
17
27
  inspect_source(cop, src)
18
28
  expect(cop.offenses.size).to eq(2)
29
+ expect(cop.messages)
30
+ .to eq(['Remove debugger entry point `binding.pry`.',
31
+ 'Remove debugger entry point `binding.remote_pry`.'])
32
+ expect(cop.highlights).to eq(['binding.pry', 'binding.remote_pry'])
19
33
  end
20
34
 
21
35
  it 'does not report an offense for non-pry binding' do
@@ -24,16 +38,19 @@ describe Rubocop::Cop::Lint::Debugger do
24
38
  expect(cop.offenses).to be_empty
25
39
  end
26
40
 
27
- it 'does not report an offense for debugger in comments' do
28
- src = ['# debugger']
29
- inspect_source(cop, src)
30
- expect(cop.offenses).to be_empty
41
+ %w(debugger byebug).each do |comment|
42
+ it "does not report an offense for #{comment} in comments" do
43
+ src = ["# #{comment}"]
44
+ inspect_source(cop, src)
45
+ expect(cop.offenses).to be_empty
46
+ end
31
47
  end
32
48
 
33
- it 'does not report an offense for a debugger or pry method' do
34
- src = ['code.debugger',
35
- 'door.pry']
36
- inspect_source(cop, src)
37
- expect(cop.offenses).to be_empty
49
+ %w(debugger byebug pry).each do |method_name|
50
+ it "does not report an offense for a #{method_name} method" do
51
+ src = ["code.#{method_name}"]
52
+ inspect_source(cop, src)
53
+ expect(cop.offenses).to be_empty
54
+ end
38
55
  end
39
56
  end