rubocop 0.19.1 → 0.20.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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +60 -1
  4. data/CONTRIBUTING.md +2 -1
  5. data/README.md +9 -7
  6. data/config/default.yml +3 -3
  7. data/config/disabled.yml +4 -0
  8. data/config/enabled.yml +45 -21
  9. data/lib/rubocop.rb +30 -9
  10. data/lib/rubocop/cli.rb +1 -1
  11. data/lib/rubocop/comment_config.rb +4 -2
  12. data/lib/rubocop/config.rb +16 -22
  13. data/lib/rubocop/config_loader.rb +29 -26
  14. data/lib/rubocop/cop/commissioner.rb +1 -1
  15. data/lib/rubocop/cop/cop.rb +6 -6
  16. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
  17. data/lib/rubocop/cop/lint/condition_position.rb +1 -1
  18. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  19. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +9 -7
  20. data/lib/rubocop/cop/lint/else_layout.rb +1 -1
  21. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  22. data/lib/rubocop/cop/lint/empty_interpolation.rb +22 -0
  23. data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
  24. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  25. data/lib/rubocop/cop/lint/eval.rb +1 -1
  26. data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
  27. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +9 -0
  28. data/lib/rubocop/cop/lint/loop.rb +2 -2
  29. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  30. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  31. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
  32. data/lib/rubocop/cop/lint/space_before_first_arg.rb +36 -0
  33. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +14 -2
  34. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -0
  35. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  36. data/lib/rubocop/cop/lint/void.rb +3 -3
  37. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  38. data/lib/rubocop/cop/offense.rb +3 -21
  39. data/lib/rubocop/cop/rails/action_filter.rb +1 -1
  40. data/lib/rubocop/cop/rails/default_scope.rb +1 -1
  41. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  42. data/lib/rubocop/cop/rails/read_write_attribute.rb +43 -0
  43. data/lib/rubocop/cop/rails/scope_args.rb +1 -1
  44. data/lib/rubocop/cop/rails/validation.rb +1 -1
  45. data/lib/rubocop/cop/severity.rb +76 -0
  46. data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
  47. data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
  48. data/lib/rubocop/cop/style/alias.rb +1 -1
  49. data/lib/rubocop/cop/style/align_hash.rb +1 -1
  50. data/lib/rubocop/cop/style/and_or.rb +1 -1
  51. data/lib/rubocop/cop/style/{favor_join.rb → array_join.rb} +2 -2
  52. data/lib/rubocop/cop/style/begin_block.rb +1 -1
  53. data/lib/rubocop/cop/style/block_nesting.rb +12 -8
  54. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
  55. data/lib/rubocop/cop/style/case_equality.rb +1 -1
  56. data/lib/rubocop/cop/style/case_indentation.rb +5 -5
  57. data/lib/rubocop/cop/style/class_methods.rb +19 -3
  58. data/lib/rubocop/cop/style/class_vars.rb +1 -1
  59. data/lib/rubocop/cop/style/collection_methods.rb +17 -7
  60. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  61. data/lib/rubocop/cop/style/{def_parentheses.rb → def_with_parentheses.rb} +0 -0
  62. data/lib/rubocop/cop/style/{hash_methods.rb → deprecated_hash_methods.rb} +5 -4
  63. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  64. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
  65. data/lib/rubocop/cop/style/end_block.rb +1 -1
  66. data/lib/rubocop/cop/style/even_odd.rb +2 -2
  67. data/lib/rubocop/cop/style/file_name.rb +1 -1
  68. data/lib/rubocop/cop/style/for.rb +2 -2
  69. data/lib/rubocop/cop/style/format_string.rb +1 -1
  70. data/lib/rubocop/cop/style/guard_clause.rb +69 -0
  71. data/lib/rubocop/cop/style/hash_syntax.rb +6 -10
  72. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  73. data/lib/rubocop/cop/style/lambda.rb +2 -2
  74. data/lib/rubocop/cop/style/line_end_concatenation.rb +16 -9
  75. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  76. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -2
  77. data/lib/rubocop/cop/style/negated_if.rb +37 -0
  78. data/lib/rubocop/cop/style/negated_while.rb +33 -0
  79. data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
  80. data/lib/rubocop/cop/style/nil_comparison.rb +14 -10
  81. data/lib/rubocop/cop/style/non_nil_check.rb +70 -0
  82. data/lib/rubocop/cop/style/not.rb +25 -1
  83. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  84. data/lib/rubocop/cop/style/op_method.rb +4 -4
  85. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  86. data/lib/rubocop/cop/style/predicate_name.rb +1 -1
  87. data/lib/rubocop/cop/style/proc.rb +1 -1
  88. data/lib/rubocop/cop/style/raise_args.rb +3 -2
  89. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  90. data/lib/rubocop/cop/style/self_assignment.rb +2 -2
  91. data/lib/rubocop/cop/style/signal_exception.rb +6 -3
  92. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  93. data/lib/rubocop/cop/style/single_line_methods.rb +6 -5
  94. data/lib/rubocop/cop/style/single_space_before_first_arg.rb +41 -0
  95. data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
  96. data/lib/rubocop/cop/style/special_global_vars.rb +8 -8
  97. data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
  98. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  99. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  100. data/lib/rubocop/cop/style/variable_interpolation.rb +10 -5
  101. data/lib/rubocop/cop/style/when_then.rb +1 -1
  102. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  103. data/lib/rubocop/cop/style/word_array.rb +1 -1
  104. data/lib/rubocop/cop/team.rb +12 -13
  105. data/lib/rubocop/cop/util.rb +4 -0
  106. data/lib/rubocop/cop/variable_inspector/locatable.rb +1 -1
  107. data/lib/rubocop/cop/variable_inspector/variable_table.rb +1 -1
  108. data/lib/rubocop/file_inspector.rb +46 -10
  109. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  110. data/lib/rubocop/formatter/disabled_lines_formatter.rb +56 -0
  111. data/lib/rubocop/formatter/emacs_style_formatter.rb +1 -1
  112. data/lib/rubocop/formatter/formatter_set.rb +2 -1
  113. data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -4
  114. data/lib/rubocop/formatter/json_formatter.rb +3 -7
  115. data/lib/rubocop/formatter/progress_formatter.rb +1 -3
  116. data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
  117. data/lib/rubocop/options.rb +29 -10
  118. data/lib/rubocop/path_util.rb +2 -1
  119. data/lib/rubocop/processed_source.rb +8 -0
  120. data/lib/rubocop/target_finder.rb +33 -12
  121. data/lib/rubocop/version.rb +1 -1
  122. data/relnotes/v0.20.0.md +69 -0
  123. data/rubocop-todo.yml +2 -2
  124. data/spec/rubocop/cli_spec.rb +269 -94
  125. data/spec/rubocop/config_loader_spec.rb +14 -14
  126. data/spec/rubocop/config_spec.rb +8 -8
  127. data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +11 -6
  128. data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +18 -0
  129. data/spec/rubocop/cop/lint/eval_spec.rb +2 -4
  130. data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +10 -0
  131. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +0 -8
  132. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
  133. data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +48 -0
  134. data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +10 -0
  135. data/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +154 -0
  136. data/spec/rubocop/cop/offense_spec.rb +1 -1
  137. data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +19 -0
  138. data/spec/rubocop/cop/severity_spec.rb +113 -0
  139. data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +10 -10
  140. data/spec/rubocop/cop/style/alias_spec.rb +2 -2
  141. data/spec/rubocop/cop/style/and_or_spec.rb +2 -2
  142. data/spec/rubocop/cop/style/{favor_join_spec.rb → array_join_spec.rb} +1 -3
  143. data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -4
  144. data/spec/rubocop/cop/style/case_equality_spec.rb +1 -0
  145. data/spec/rubocop/cop/style/case_indentation_spec.rb +12 -9
  146. data/spec/rubocop/cop/style/class_methods_spec.rb +23 -0
  147. data/spec/rubocop/cop/style/collection_methods_spec.rb +2 -2
  148. data/spec/rubocop/cop/style/{hash_methods_spec.rb → deprecated_hash_methods_spec.rb} +3 -3
  149. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +2 -2
  150. data/spec/rubocop/cop/style/even_odd_spec.rb +8 -8
  151. data/spec/rubocop/cop/style/file_name_spec.rb +55 -42
  152. data/spec/rubocop/cop/style/for_spec.rb +4 -4
  153. data/spec/rubocop/cop/style/format_string_spec.rb +10 -10
  154. data/spec/rubocop/cop/style/guard_clause_spec.rb +77 -0
  155. data/spec/rubocop/cop/style/hash_syntax_spec.rb +4 -2
  156. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +4 -4
  157. data/spec/rubocop/cop/style/lambda_spec.rb +2 -2
  158. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +21 -0
  159. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -1
  160. data/spec/rubocop/cop/style/{favor_unless_over_negated_if_spec.rb → negated_if_spec.rb} +8 -3
  161. data/spec/rubocop/cop/style/{favor_until_over_negated_while_spec.rb → negated_while_spec.rb} +8 -3
  162. data/spec/rubocop/cop/style/nil_comparison_spec.rb +7 -13
  163. data/spec/rubocop/cop/style/non_nil_check_spec.rb +35 -0
  164. data/spec/rubocop/cop/style/not_spec.rb +11 -0
  165. data/spec/rubocop/cop/style/numeric_literals_spec.rb +0 -2
  166. data/spec/rubocop/cop/style/op_method_spec.rb +10 -2
  167. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +2 -2
  168. data/spec/rubocop/cop/style/predicate_name_spec.rb +2 -1
  169. data/spec/rubocop/cop/style/raise_args_spec.rb +5 -0
  170. data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
  171. data/spec/rubocop/cop/style/self_assignment_spec.rb +4 -4
  172. data/spec/rubocop/cop/style/signal_exception_spec.rb +24 -0
  173. data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -0
  174. data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +63 -0
  175. data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -5
  176. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -3
  177. data/spec/rubocop/cop/style/unless_else_spec.rb +2 -4
  178. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +15 -6
  179. data/spec/rubocop/cop/style/when_then_spec.rb +3 -4
  180. data/spec/rubocop/cop/team_spec.rb +4 -18
  181. data/spec/rubocop/file_inspector_spec.rb +4 -0
  182. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
  183. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +69 -0
  184. data/spec/rubocop/options_spec.rb +5 -0
  185. data/spec/rubocop/target_finder_spec.rb +42 -11
  186. data/spec/support/shared_context.rb +1 -1
  187. data/spec/support/statement_modifier_helper.rb +1 -1
  188. metadata +75 -50
  189. data/lib/rubocop/cop/rails/read_attribute.rb +0 -28
  190. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +0 -24
  191. data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +0 -20
  192. data/spec/rubocop/cop/rails/read_attribute_spec.rb +0 -13
@@ -61,7 +61,7 @@ describe Rubocop::Cop::Offense do
61
61
  describe '#severity_level' do
62
62
  subject(:severity_level) do
63
63
  described_class.new(severity, location, 'message', 'CopName')
64
- .severity_level
64
+ .severity.level
65
65
  end
66
66
 
67
67
  context 'when severity is :refactor' do
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Rubocop::Cop::Rails::ReadWriteAttribute do
6
+ subject(:cop) { described_class.new }
7
+
8
+ it 'registers an offense for read_attribute' do
9
+ inspect_source(cop, 'res = read_attribute(:test)')
10
+ expect(cop.offenses.size).to eq(1)
11
+ expect(cop.highlights).to eq(['read_attribute'])
12
+ end
13
+
14
+ it 'registers an offense for write_attribute' do
15
+ inspect_source(cop, 'write_attribute(:test, val)')
16
+ expect(cop.offenses.size).to eq(1)
17
+ expect(cop.highlights).to eq(['write_attribute'])
18
+ end
19
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Rubocop::Cop::Severity do
6
+ let(:refactor) { described_class.new(:refactor) }
7
+ let(:convention) { described_class.new(:convention) }
8
+ let(:warning) { described_class.new(:warning) }
9
+ let(:error) { described_class.new(:error) }
10
+ let(:fatal) { described_class.new(:fatal) }
11
+
12
+ it 'has a few required attributes' do
13
+ expect(convention.name).to eq(:convention)
14
+ end
15
+
16
+ it 'overrides #to_s' do
17
+ expect(convention.to_s).to eq('convention')
18
+ end
19
+
20
+ it 'redefines == to compare severities' do
21
+ expect(convention).to eq(:convention)
22
+ expect(convention).to eq(described_class.new(:convention))
23
+ expect(convention).not_to eq(:warning)
24
+ end
25
+
26
+ it 'is frozen' do
27
+ expect(convention).to be_frozen
28
+ end
29
+
30
+ describe '#code' do
31
+ describe 'refactor' do
32
+ it { expect(refactor.code).to eq('R') }
33
+ end
34
+
35
+ describe 'convention' do
36
+ it { expect(convention.code).to eq('C') }
37
+ end
38
+
39
+ describe 'warning' do
40
+ it { expect(warning.code).to eq('W') }
41
+ end
42
+
43
+ describe 'error' do
44
+ it { expect(error.code).to eq('E') }
45
+ end
46
+
47
+ describe 'fatal' do
48
+ it { expect(fatal.code).to eq('F') }
49
+ end
50
+ end
51
+
52
+ describe '#level' do
53
+ describe 'refactor' do
54
+ it { expect(refactor.level).to eq(1) }
55
+ end
56
+
57
+ describe 'convention' do
58
+ it { expect(convention.level).to eq(2) }
59
+ end
60
+
61
+ describe 'warning' do
62
+ it { expect(warning.level).to eq(3) }
63
+ end
64
+
65
+ describe 'error' do
66
+ it { expect(error.level).to eq(4) }
67
+ end
68
+
69
+ describe 'fatal' do
70
+ it { expect(fatal.level).to eq(5) }
71
+ end
72
+ end
73
+
74
+ describe 'constructs from code' do
75
+ describe 'R' do
76
+ it { expect(Rubocop::Cop::Severity.new('R')).to eq(refactor) }
77
+ end
78
+
79
+ describe 'C' do
80
+ it { expect(Rubocop::Cop::Severity.new('C')).to eq(convention) }
81
+ end
82
+
83
+ describe 'W' do
84
+ it { expect(Rubocop::Cop::Severity.new('W')).to eq(warning) }
85
+ end
86
+
87
+ describe 'E' do
88
+ it { expect(Rubocop::Cop::Severity.new('E')).to eq(error) }
89
+ end
90
+
91
+ describe 'F' do
92
+ it { expect(Rubocop::Cop::Severity.new('F')).to eq(fatal) }
93
+ end
94
+ end
95
+
96
+ describe 'Comparable' do
97
+ describe 'refactor' do
98
+ it { expect(refactor).to be < convention }
99
+ end
100
+
101
+ describe 'convention' do
102
+ it { expect(convention).to be < warning }
103
+ end
104
+
105
+ describe 'warning' do
106
+ it { expect(warning).to be < error }
107
+ end
108
+
109
+ describe 'error' do
110
+ it { expect(error).to be < fatal }
111
+ end
112
+ end
113
+ end
@@ -18,7 +18,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
18
18
  'end'])
19
19
  expect(cop.offenses.size).to eq(1)
20
20
  expect(cop.messages)
21
- .to eq(['Indent access modifiers like private.'])
21
+ .to eq(['Indent access modifiers like `private`.'])
22
22
  expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'outdent')
23
23
  end
24
24
 
@@ -31,7 +31,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
31
31
  ' def test; end',
32
32
  'end'])
33
33
  expect(cop.offenses.size).to eq(1)
34
- expect(cop.messages).to eq(['Indent access modifiers like private.'])
34
+ expect(cop.messages).to eq(['Indent access modifiers like `private`.'])
35
35
  # Not aligned according to `indent` or `outdent` style:
36
36
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
37
37
  end
@@ -47,7 +47,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
47
47
  ' def test; end',
48
48
  'end'])
49
49
  expect(cop.offenses.size).to eq(1)
50
- expect(cop.messages).to eq(['Indent access modifiers like private.'])
50
+ expect(cop.messages).to eq(['Indent access modifiers like `private`.'])
51
51
  # No EnforcedStyle can allow both aligments:
52
52
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
53
53
  end
@@ -63,7 +63,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
63
63
  ' def test; end',
64
64
  'end'])
65
65
  expect(cop.offenses.size).to eq(1)
66
- expect(cop.messages).to eq(['Indent access modifiers like public.'])
66
+ expect(cop.messages).to eq(['Indent access modifiers like `public`.'])
67
67
  # No EnforcedStyle can allow both aligments:
68
68
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
69
69
  end
@@ -78,7 +78,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
78
78
  'end'])
79
79
  expect(cop.offenses.size).to eq(1)
80
80
  expect(cop.messages)
81
- .to eq(['Indent access modifiers like private.'])
81
+ .to eq(['Indent access modifiers like `private`.'])
82
82
  end
83
83
 
84
84
  it 'registers an offense for misaligned private in class ' \
@@ -92,7 +92,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
92
92
  'end'])
93
93
  expect(cop.offenses.size).to eq(1)
94
94
  expect(cop.messages)
95
- .to eq(['Indent access modifiers like private.'])
95
+ .to eq(['Indent access modifiers like `private`.'])
96
96
  end
97
97
 
98
98
  it 'registers an offense for misaligned private in module ' \
@@ -106,7 +106,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
106
106
  'end'])
107
107
  expect(cop.offenses.size).to eq(1)
108
108
  expect(cop.messages)
109
- .to eq(['Indent access modifiers like private.'])
109
+ .to eq(['Indent access modifiers like `private`.'])
110
110
  end
111
111
 
112
112
  it 'registers an offense for misaligned protected' do
@@ -119,7 +119,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
119
119
  'end'])
120
120
  expect(cop.offenses.size).to eq(1)
121
121
  expect(cop.messages)
122
- .to eq(['Indent access modifiers like protected.'])
122
+ .to eq(['Indent access modifiers like `protected`.'])
123
123
  end
124
124
 
125
125
  it 'accepts properly indented private' do
@@ -168,7 +168,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
168
168
  'end'])
169
169
  expect(cop.offenses.size).to eq(1)
170
170
  expect(cop.messages)
171
- .to eq(['Indent access modifiers like private.'])
171
+ .to eq(['Indent access modifiers like `private`.'])
172
172
  end
173
173
 
174
174
  it 'auto-corrects incorrectly indented access modifiers' do
@@ -193,7 +193,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
193
193
 
194
194
  context 'when EnforcedStyle is set to outdent' do
195
195
  let(:cop_config) { { 'EnforcedStyle' => 'outdent' } }
196
- let(:indent_msg) { 'Outdent access modifiers like private.' }
196
+ let(:indent_msg) { 'Outdent access modifiers like `private`.' }
197
197
 
198
198
  it 'registers offense for private indented to method depth in a class' do
199
199
  inspect_source(cop,
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::Alias do
10
10
  ['alias :ala :bala'])
11
11
  expect(cop.offenses.size).to eq(1)
12
12
  expect(cop.messages)
13
- .to eq(['Use alias_method instead of alias.'])
13
+ .to eq(['Use `alias_method` instead of `alias`.'])
14
14
  end
15
15
 
16
16
  it 'autocorrects alias with symbol args' do
@@ -23,7 +23,7 @@ describe Rubocop::Cop::Style::Alias do
23
23
  ['alias ala bala'])
24
24
  expect(cop.offenses.size).to eq(1)
25
25
  expect(cop.messages)
26
- .to eq(['Use alias_method instead of alias.'])
26
+ .to eq(['Use `alias_method` instead of `alias`.'])
27
27
  end
28
28
 
29
29
  it 'autocorrects alias with bareword args' do
@@ -9,14 +9,14 @@ describe Rubocop::Cop::Style::AndOr do
9
9
  inspect_source(cop,
10
10
  ['test if a or b'])
11
11
  expect(cop.offenses.size).to eq(1)
12
- expect(cop.messages).to eq(['Use || instead of or.'])
12
+ expect(cop.messages).to eq(['Use `||` instead of `or`.'])
13
13
  end
14
14
 
15
15
  it 'registers an offense for AND' do
16
16
  inspect_source(cop,
17
17
  ['test if a and b'])
18
18
  expect(cop.offenses.size).to eq(1)
19
- expect(cop.messages).to eq(['Use && instead of and.'])
19
+ expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
20
20
  end
21
21
 
22
22
  it 'accepts ||' do
@@ -2,15 +2,13 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Rubocop::Cop::Style::FavorJoin do
5
+ describe Rubocop::Cop::Style::ArrayJoin do
6
6
  subject(:cop) { described_class.new }
7
7
 
8
8
  it 'registers an offense for an array followed by string' do
9
9
  inspect_source(cop,
10
10
  ['%w(one two three) * ", "'])
11
11
  expect(cop.offenses.size).to eq(1)
12
- expect(cop.messages)
13
- .to eq(['Favor Array#join over Array#*.'])
14
12
  end
15
13
 
16
14
  it 'does not register an offense for numbers' do
@@ -26,7 +26,7 @@ describe Rubocop::Cop::Style::BlockNesting, :config do
26
26
  expect_nesting_offenses(source, [3])
27
27
  end
28
28
 
29
- it 'registers a single offense for `Max + 2` levels of `if` nesting' do
29
+ it 'registers one offense for `Max + 2` levels of `if` nesting' do
30
30
  source = ['if a',
31
31
  ' if b',
32
32
  ' if c',
@@ -36,7 +36,7 @@ describe Rubocop::Cop::Style::BlockNesting, :config do
36
36
  ' end',
37
37
  ' end',
38
38
  'end']
39
- expect_nesting_offenses(source, [3])
39
+ expect_nesting_offenses(source, [3], 4)
40
40
  end
41
41
 
42
42
  it 'registers 2 offenses' do
@@ -144,13 +144,13 @@ describe Rubocop::Cop::Style::BlockNesting, :config do
144
144
  expect_nesting_offenses(source, [])
145
145
  end
146
146
 
147
- def expect_nesting_offenses(source, lines, used_nesting_level = 3)
147
+ def expect_nesting_offenses(source, lines, max_to_allow = 3)
148
148
  inspect_source(cop, source)
149
149
  expect(cop.offenses.map(&:line)).to eq(lines)
150
150
  expect(cop.messages).to eq(
151
151
  ['Avoid more than 2 levels of block nesting.'] * lines.length)
152
152
  if cop.offenses.size > 0
153
- expect(cop.config_to_allow_offenses['Max']).to eq(used_nesting_level)
153
+ expect(cop.config_to_allow_offenses['Max']).to eq(max_to_allow)
154
154
  end
155
155
  end
156
156
  end
@@ -8,5 +8,6 @@ describe Rubocop::Cop::Style::CaseEquality do
8
8
  it 'registers an offense for ===' do
9
9
  inspect_source(cop, ['Array === var'])
10
10
  expect(cop.offenses.size).to eq(1)
11
+ expect(cop.highlights).to eq(['==='])
11
12
  end
12
13
  end
@@ -36,7 +36,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
36
36
  " 'output2'",
37
37
  'end']
38
38
  inspect_source(cop, source)
39
- expect(cop.messages).to eq(['Indent when as deep as case.'])
39
+ expect(cop.messages).to eq(['Indent `when` as deep as `case`.'])
40
40
  expect(cop.config_to_allow_offenses).to eq('IndentWhenRelativeTo' =>
41
41
  'end')
42
42
  end
@@ -49,7 +49,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
49
49
  " 'output2'",
50
50
  'end']
51
51
  inspect_source(cop, source)
52
- expect(cop.messages).to eq(['Indent when as deep as case.'])
52
+ expect(cop.messages).to eq(['Indent `when` as deep as `case`.'])
53
53
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
54
54
  end
55
55
 
@@ -67,7 +67,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
67
67
  " 'output2'",
68
68
  'end']
69
69
  inspect_source(cop, source)
70
- expect(cop.messages).to eq(['Indent when as deep as case.'])
70
+ expect(cop.messages).to eq(['Indent `when` as deep as `case`.'])
71
71
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
72
72
  end
73
73
  end
@@ -81,7 +81,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
81
81
  ' end',
82
82
  'end']
83
83
  inspect_source(cop, source)
84
- expect(cop.messages).to eq(['Indent when as deep as case.'] * 2)
84
+ expect(cop.messages).to eq(['Indent `when` as deep as `case`.'] * 2)
85
85
  end
86
86
 
87
87
  it "accepts a when clause that's equally indented with case" do
@@ -174,7 +174,8 @@ describe Rubocop::Cop::Style::CaseIndentation do
174
174
  " 'output2'",
175
175
  ' end']
176
176
  inspect_source(cop, source)
177
- expect(cop.messages).to eq(['Indent when one step more than case.'])
177
+ expect(cop.messages)
178
+ .to eq(['Indent `when` one step more than `case`.'])
178
179
  end
179
180
  end
180
181
 
@@ -206,7 +207,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
206
207
  '']
207
208
  inspect_source(cop, source)
208
209
  expect(cop.messages)
209
- .to eq(['Indent when one step more than case.'] * 5)
210
+ .to eq(['Indent `when` one step more than `case`.'] * 5)
210
211
  end
211
212
  end
212
213
  end
@@ -237,7 +238,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
237
238
  " 'output2'",
238
239
  'end']
239
240
  inspect_source(cop, source)
240
- expect(cop.messages).to eq(['Indent when as deep as end.'])
241
+ expect(cop.messages).to eq(['Indent `when` as deep as `end`.'])
241
242
  end
242
243
  end
243
244
  end
@@ -267,7 +268,8 @@ describe Rubocop::Cop::Style::CaseIndentation do
267
268
  " 'output2'",
268
269
  ' end']
269
270
  inspect_source(cop, source)
270
- expect(cop.messages).to eq(['Indent when one step more than end.'])
271
+ expect(cop.messages)
272
+ .to eq(['Indent `when` one step more than `end`.'])
271
273
  expect(cop.config_to_allow_offenses).to eq('IndentWhenRelativeTo' =>
272
274
  'case')
273
275
  end
@@ -280,7 +282,8 @@ describe Rubocop::Cop::Style::CaseIndentation do
280
282
  " 'output2'",
281
283
  ' end']
282
284
  inspect_source(cop, source)
283
- expect(cop.messages).to eq(['Indent when one step more than end.'])
285
+ expect(cop.messages)
286
+ .to eq(['Indent `when` one step more than `end`.'])
284
287
  expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
285
288
  end
286
289
  end
@@ -13,6 +13,9 @@ describe Rubocop::Cop::Style::ClassMethods do
13
13
  ' end',
14
14
  'end'])
15
15
  expect(cop.offenses.size).to eq(1)
16
+ expect(cop.messages)
17
+ .to eq(['Use `self.some_method` instead of `Test.some_method`.'])
18
+ expect(cop.highlights).to eq(['Test'])
16
19
  end
17
20
 
18
21
  it 'registers an offense for methods using a module name' do
@@ -23,6 +26,9 @@ describe Rubocop::Cop::Style::ClassMethods do
23
26
  ' end',
24
27
  'end'])
25
28
  expect(cop.offenses.size).to eq(1)
29
+ expect(cop.messages)
30
+ .to eq(['Use `self.some_method` instead of `Test.some_method`.'])
31
+ expect(cop.highlights).to eq(['Test'])
26
32
  end
27
33
 
28
34
  it 'does not register an offense for methods using self' do
@@ -42,4 +48,21 @@ describe Rubocop::Cop::Style::ClassMethods do
42
48
  'end'])
43
49
  expect(cop.offenses).to be_empty
44
50
  end
51
+
52
+ it 'autocorrects class name to self' do
53
+ src = ['class Test',
54
+ ' def Test.some_method',
55
+ ' do_something',
56
+ ' end',
57
+ 'end']
58
+
59
+ correct_source = ['class Test',
60
+ ' def self.some_method',
61
+ ' do_something',
62
+ ' end',
63
+ 'end'].join("\n")
64
+
65
+ new_source = autocorrect_source(cop, src)
66
+ expect(new_source).to eq(correct_source)
67
+ end
45
68
  end
@@ -20,14 +20,14 @@ describe Rubocop::Cop::Style::CollectionMethods, :config do
20
20
  inspect_source(cop, ["[1, 2, 3].#{method} { |e| e + 1 }"])
21
21
  expect(cop.offenses.size).to eq(1)
22
22
  expect(cop.messages)
23
- .to eq(["Prefer #{preferred_method} over #{method}."])
23
+ .to eq(["Prefer `#{preferred_method}` over `#{method}`."])
24
24
  end
25
25
 
26
26
  it "registers an offense for #{method} with proc param" do
27
27
  inspect_source(cop, ["[1, 2, 3].#{method}(&:test)"])
28
28
  expect(cop.offenses.size).to eq(1)
29
29
  expect(cop.messages)
30
- .to eq(["Prefer #{preferred_method} over #{method}."])
30
+ .to eq(["Prefer `#{preferred_method}` over `#{method}`."])
31
31
  end
32
32
 
33
33
  it "accepts #{method} with more than 1 param" do