rubocop 0.89.0 → 0.89.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  4. data/lib/rubocop/comment_config.rb +3 -5
  5. data/lib/rubocop/config.rb +1 -1
  6. data/lib/rubocop/config_loader.rb +1 -1
  7. data/lib/rubocop/config_validator.rb +1 -1
  8. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  9. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  10. data/lib/rubocop/cop/layout/class_structure.rb +3 -7
  11. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/extra_spacing.rb +14 -21
  13. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  14. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -1
  15. data/lib/rubocop/cop/lint/missing_super.rb +9 -9
  16. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +33 -4
  17. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +14 -17
  18. data/lib/rubocop/cop/lint/uri_regexp.rb +9 -25
  19. data/lib/rubocop/cop/migration/department_name.rb +2 -2
  20. data/lib/rubocop/cop/mixin/alignment.rb +2 -1
  21. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  22. data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -2
  23. data/lib/rubocop/cop/mixin/hash_transform_method.rb +5 -11
  24. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -3
  25. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -2
  26. data/lib/rubocop/cop/mixin/percent_array.rb +2 -6
  27. data/lib/rubocop/cop/mixin/range_help.rb +18 -4
  28. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  29. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  30. data/lib/rubocop/cop/style/access_modifier_declarations.rb +5 -8
  31. data/lib/rubocop/cop/style/accessor_grouping.rb +20 -20
  32. data/lib/rubocop/cop/style/alias.rb +34 -33
  33. data/lib/rubocop/cop/style/and_or.rb +9 -11
  34. data/lib/rubocop/cop/style/array_join.rb +6 -8
  35. data/lib/rubocop/cop/style/ascii_comments.rb +4 -4
  36. data/lib/rubocop/cop/style/attr.rb +11 -9
  37. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -5
  38. data/lib/rubocop/cop/style/bare_percent_literals.rb +10 -12
  39. data/lib/rubocop/cop/style/begin_block.rb +2 -2
  40. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +9 -12
  41. data/lib/rubocop/cop/style/block_comments.rb +14 -18
  42. data/lib/rubocop/cop/style/block_delimiters.rb +23 -23
  43. data/lib/rubocop/cop/style/case_like_if.rb +17 -14
  44. data/lib/rubocop/cop/style/class_and_module_children.rb +14 -11
  45. data/lib/rubocop/cop/style/class_check.rb +7 -9
  46. data/lib/rubocop/cop/style/class_methods.rb +7 -11
  47. data/lib/rubocop/cop/style/class_vars.rb +6 -10
  48. data/lib/rubocop/cop/style/collection_methods.rb +11 -17
  49. data/lib/rubocop/cop/style/colon_method_call.rb +6 -7
  50. data/lib/rubocop/cop/style/colon_method_definition.rb +6 -6
  51. data/lib/rubocop/cop/style/command_literal.rb +23 -24
  52. data/lib/rubocop/cop/style/comment_annotation.rb +15 -15
  53. data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  55. data/lib/rubocop/cop/style/constant_visibility.rb +3 -2
  56. data/lib/rubocop/cop/style/copyright.rb +12 -12
  57. data/lib/rubocop/cop/style/date_time.rb +1 -1
  58. data/lib/rubocop/cop/style/def_with_parentheses.rb +8 -10
  59. data/lib/rubocop/cop/style/dir.rb +7 -10
  60. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +7 -9
  61. data/lib/rubocop/cop/style/documentation.rb +2 -4
  62. data/lib/rubocop/cop/style/documentation_method.rb +1 -1
  63. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +12 -15
  64. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  65. data/lib/rubocop/cop/style/each_for_simple_loop.rb +5 -8
  66. data/lib/rubocop/cop/style/each_with_object.rb +16 -17
  67. data/lib/rubocop/cop/style/empty_case_condition.rb +19 -20
  68. data/lib/rubocop/cop/style/empty_else.rb +17 -19
  69. data/lib/rubocop/cop/style/empty_literal.rb +15 -16
  70. data/lib/rubocop/cop/style/empty_method.rb +5 -8
  71. data/lib/rubocop/cop/style/encoding.rb +5 -9
  72. data/lib/rubocop/cop/style/end_block.rb +4 -6
  73. data/lib/rubocop/cop/style/eval_with_location.rb +5 -7
  74. data/lib/rubocop/cop/style/even_odd.rb +7 -11
  75. data/lib/rubocop/cop/style/expand_path_arguments.rb +21 -24
  76. data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
  77. data/lib/rubocop/cop/style/float_division.rb +1 -1
  78. data/lib/rubocop/cop/style/for.rb +11 -15
  79. data/lib/rubocop/cop/style/format_string.rb +17 -19
  80. data/lib/rubocop/cop/style/format_string_token.rb +4 -7
  81. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +19 -41
  82. data/lib/rubocop/cop/style/global_vars.rb +2 -2
  83. data/lib/rubocop/cop/style/guard_clause.rb +3 -4
  84. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -1
  85. data/lib/rubocop/cop/style/hash_each_methods.rb +5 -8
  86. data/lib/rubocop/cop/style/hash_syntax.rb +0 -2
  87. data/lib/rubocop/cop/style/hash_transform_keys.rb +3 -2
  88. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -1
  89. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  90. data/lib/rubocop/cop/style/if_inside_else.rb +2 -2
  91. data/lib/rubocop/cop/style/if_unless_modifier.rb +10 -12
  92. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +3 -7
  93. data/lib/rubocop/cop/style/if_with_semicolon.rb +3 -6
  94. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -1
  95. data/lib/rubocop/cop/style/infinite_loop.rb +23 -23
  96. data/lib/rubocop/cop/style/inline_comment.rb +3 -3
  97. data/lib/rubocop/cop/style/inverse_methods.rb +20 -29
  98. data/lib/rubocop/cop/style/lambda.rb +7 -12
  99. data/lib/rubocop/cop/style/lambda_call.rb +14 -13
  100. data/lib/rubocop/cop/style/line_end_concatenation.rb +19 -16
  101. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -1
  102. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +11 -11
  103. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +4 -8
  104. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +7 -6
  105. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -2
  106. data/lib/rubocop/cop/style/method_def_parentheses.rb +11 -16
  107. data/lib/rubocop/cop/style/min_max.rb +8 -12
  108. data/lib/rubocop/cop/style/missing_else.rb +13 -13
  109. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +1 -1
  110. data/lib/rubocop/cop/style/mixin_grouping.rb +24 -27
  111. data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
  112. data/lib/rubocop/cop/style/module_function.rb +10 -13
  113. data/lib/rubocop/cop/style/multiline_if_modifier.rb +3 -10
  114. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -10
  115. data/lib/rubocop/cop/style/multiline_memoization.rb +12 -10
  116. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  117. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +4 -6
  118. data/lib/rubocop/cop/style/multiline_when_then.rb +7 -9
  119. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
  120. data/lib/rubocop/cop/style/mutable_constant.rb +23 -20
  121. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +3 -1
  122. data/lib/rubocop/cop/style/redundant_sort.rb +0 -2
  123. data/lib/rubocop/cop/style/safe_navigation.rb +4 -4
  124. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  125. data/lib/rubocop/cop/util.rb +2 -0
  126. data/lib/rubocop/cops_documentation_generator.rb +1 -1
  127. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  128. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  129. data/lib/rubocop/options.rb +3 -3
  130. data/lib/rubocop/rspec/shared_contexts.rb +1 -5
  131. data/lib/rubocop/runner.rb +1 -1
  132. data/lib/rubocop/version.rb +1 -1
  133. metadata +4 -4
@@ -40,7 +40,7 @@ module RuboCop
40
40
  # class C
41
41
  # prepend M
42
42
  # end
43
- class MixinUsage < Cop
43
+ class MixinUsage < Base
44
44
  MSG = '`%<statement>s` is used at the top level. Use inside `class` ' \
45
45
  'or `module`.'
46
46
 
@@ -71,8 +71,9 @@ module RuboCop
71
71
  #
72
72
  # These offenses are not safe to auto-correct since there are different
73
73
  # implications to each approach.
74
- class ModuleFunction < Cop
74
+ class ModuleFunction < Base
75
75
  include ConfigurableEnforcedStyle
76
+ extend AutoCorrector
76
77
 
77
78
  MODULE_FUNCTION_MSG =
78
79
  'Use `module_function` instead of `extend self`.'
@@ -89,18 +90,14 @@ module RuboCop
89
90
  return unless node.body&.begin_type?
90
91
 
91
92
  each_wrong_style(node.body.children) do |child_node|
92
- add_offense(child_node)
93
- end
94
- end
95
-
96
- def autocorrect(node)
97
- return if style == :forbidden
93
+ add_offense(child_node) do |corrector|
94
+ next if style == :forbidden
98
95
 
99
- lambda do |corrector|
100
- if extend_self_node?(node)
101
- corrector.replace(node, 'module_function')
102
- else
103
- corrector.replace(node, 'extend self')
96
+ if extend_self_node?(child_node)
97
+ corrector.replace(child_node, 'module_function')
98
+ else
99
+ corrector.replace(child_node, 'extend self')
100
+ end
104
101
  end
105
102
  end
106
103
  end
@@ -139,7 +136,7 @@ module RuboCop
139
136
  end
140
137
  end
141
138
 
142
- def message(_node)
139
+ def message(_range)
143
140
  return FORBIDDEN_MSG if style == :forbidden
144
141
 
145
142
  style == :module_function ? MODULE_FUNCTION_MSG : EXTEND_SELF_MSG
@@ -14,9 +14,10 @@ module RuboCop
14
14
  #
15
15
  # # good
16
16
  # { result: 'ok' } if cond
17
- class MultilineIfModifier < Cop
17
+ class MultilineIfModifier < Base
18
18
  include StatementModifier
19
19
  include Alignment
20
+ extend AutoCorrector
20
21
 
21
22
  MSG = 'Favor a normal %<keyword>s-statement over a modifier' \
22
23
  ' clause in a multiline statement.'
@@ -24,21 +25,13 @@ module RuboCop
24
25
  def on_if(node)
25
26
  return unless node.modifier_form? && node.body.multiline?
26
27
 
27
- add_offense(node)
28
- end
29
-
30
- def autocorrect(node)
31
- lambda do |corrector|
28
+ add_offense(node, message: format(MSG, keyword: node.keyword)) do |corrector|
32
29
  corrector.replace(node, to_normal_if(node))
33
30
  end
34
31
  end
35
32
 
36
33
  private
37
34
 
38
- def message(node)
39
- format(MSG, keyword: node.keyword)
40
- end
41
-
42
35
  def to_normal_if(node)
43
36
  indented_body = indented_body(node.body, node)
44
37
  condition = "#{node.keyword} #{node.condition.source}"
@@ -16,9 +16,10 @@ module RuboCop
16
16
  # if cond then a
17
17
  # elsif cond then b
18
18
  # end
19
- class MultilineIfThen < Cop
19
+ class MultilineIfThen < Base
20
20
  include OnNormalIfUnless
21
21
  include RangeHelp
22
+ extend AutoCorrector
22
23
 
23
24
  NON_MODIFIER_THEN = /then\s*(#.*)?$/.freeze
24
25
 
@@ -27,15 +28,8 @@ module RuboCop
27
28
  def on_normal_if_unless(node)
28
29
  return unless non_modifier_then?(node)
29
30
 
30
- add_offense(node, location: :begin,
31
- message: format(MSG, keyword: node.keyword))
32
- end
33
-
34
- def autocorrect(node)
35
- lambda do |corrector|
36
- corrector.remove(
37
- range_with_surrounding_space(range: node.loc.begin, side: :left)
38
- )
31
+ add_offense(node.loc.begin, message: format(MSG, keyword: node.keyword)) do |corrector|
32
+ corrector.remove(range_with_surrounding_space(range: node.loc.begin, side: :left))
39
33
  end
40
34
  end
41
35
 
@@ -30,30 +30,32 @@ module RuboCop
30
30
  # bar
31
31
  # baz
32
32
  # )
33
- class MultilineMemoization < Cop
33
+ class MultilineMemoization < Base
34
34
  include ConfigurableEnforcedStyle
35
+ extend AutoCorrector
35
36
 
36
- MSG = 'Wrap multiline memoization blocks in `begin` and `end`.'
37
+ KEYWORD_MSG = 'Wrap multiline memoization blocks in `begin` and `end`.'
38
+ BRACES_MSG = 'Wrap multiline memoization blocks in `(` and `)`.'
37
39
 
38
40
  def on_or_asgn(node)
39
41
  _lhs, rhs = *node
40
42
 
41
43
  return unless bad_rhs?(rhs)
42
44
 
43
- add_offense(rhs, location: node.source_range)
44
- end
45
-
46
- def autocorrect(node)
47
- lambda do |corrector|
45
+ add_offense(node.source_range) do |corrector|
48
46
  if style == :keyword
49
- keyword_autocorrect(node, corrector)
47
+ keyword_autocorrect(rhs, corrector)
50
48
  else
51
- corrector.replace(node.loc.begin, '(')
52
- corrector.replace(node.loc.end, ')')
49
+ corrector.replace(rhs.loc.begin, '(')
50
+ corrector.replace(rhs.loc.end, ')')
53
51
  end
54
52
  end
55
53
  end
56
54
 
55
+ def message(_node)
56
+ style == :braces ? BRACES_MSG : KEYWORD_MSG
57
+ end
58
+
57
59
  private
58
60
 
59
61
  def bad_rhs?(rhs)
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # baz)
19
19
  # end
20
20
  #
21
- class MultilineMethodSignature < Cop
21
+ class MultilineMethodSignature < Base
22
22
  MSG = 'Avoid multi-line method signatures.'
23
23
 
24
24
  def on_def(node)
@@ -22,18 +22,16 @@ module RuboCop
22
22
  # else
23
23
  # c
24
24
  # end
25
- class MultilineTernaryOperator < Cop
25
+ class MultilineTernaryOperator < Base
26
+ extend AutoCorrector
27
+
26
28
  MSG = 'Avoid multi-line ternary operators, ' \
27
29
  'use `if` or `unless` instead.'
28
30
 
29
31
  def on_if(node)
30
32
  return unless node.ternary? && node.multiline?
31
33
 
32
- add_offense(node)
33
- end
34
-
35
- def autocorrect(node)
36
- lambda do |corrector|
34
+ add_offense(node) do |corrector|
37
35
  corrector.replace(node, <<~RUBY.chop)
38
36
  if #{node.condition.source}
39
37
  #{node.if_branch.source}
@@ -28,8 +28,9 @@ module RuboCop
28
28
  # arg2)
29
29
  # end
30
30
  #
31
- class MultilineWhenThen < Cop
31
+ class MultilineWhenThen < Base
32
32
  include RangeHelp
33
+ extend AutoCorrector
33
34
 
34
35
  MSG = 'Do not use `then` for multiline `when` statement.'
35
36
 
@@ -46,19 +47,16 @@ module RuboCop
46
47
  # With more than one statements after then, there's not offense
47
48
  return if accept_node_type?(node.body)
48
49
 
49
- add_offense(node, location: :begin)
50
- end
51
-
52
- def autocorrect(node)
53
- lambda do |corrector|
50
+ range = node.loc.begin
51
+ add_offense(range) do |corrector|
54
52
  corrector.remove(
55
- range_with_surrounding_space(
56
- range: node.loc.begin, side: :left, newlines: false
57
- )
53
+ range_with_surrounding_space(range: range, side: :left, newlines: false)
58
54
  )
59
55
  end
60
56
  end
61
57
 
58
+ private
59
+
62
60
  def require_then?(when_node)
63
61
  return false unless when_node.body
64
62
 
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # # good
15
15
  # a = 'a'
16
16
  # foo if ['a', 'b', 'c'].include?(a)
17
- class MultipleComparison < Cop
17
+ class MultipleComparison < Base
18
18
  MSG = 'Avoid comparing a variable with multiple items ' \
19
19
  'in a conditional, use `Array#include?` instead.'
20
20
 
@@ -50,9 +50,10 @@ module RuboCop
50
50
  # puts 1
51
51
  # end
52
52
  # end.freeze
53
- class MutableConstant < Cop
53
+ class MutableConstant < Base
54
54
  include FrozenStringLiteral
55
55
  include ConfigurableEnforcedStyle
56
+ extend AutoCorrector
56
57
 
57
58
  MSG = 'Freeze mutable objects assigned to constants.'
58
59
 
@@ -69,23 +70,6 @@ module RuboCop
69
70
  on_assignment(value)
70
71
  end
71
72
 
72
- def autocorrect(node)
73
- expr = node.source_range
74
-
75
- lambda do |corrector|
76
- splat_value = splat_value(node)
77
- if splat_value
78
- correct_splat_expansion(corrector, expr, splat_value)
79
- elsif node.array_type? && !node.bracketed?
80
- corrector.wrap(expr, '[', ']')
81
- elsif requires_parentheses?(node)
82
- corrector.wrap(expr, '(', ')')
83
- end
84
-
85
- corrector.insert_after(expr, '.freeze')
86
- end
87
- end
88
-
89
73
  private
90
74
 
91
75
  def on_assignment(value)
@@ -101,7 +85,9 @@ module RuboCop
101
85
  return if operation_produces_immutable_object?(value)
102
86
  return if frozen_string_literal?(value)
103
87
 
104
- add_offense(value)
88
+ add_offense(value) do |corrector|
89
+ autocorrect(corrector, value)
90
+ end
105
91
  end
106
92
 
107
93
  def check(value)
@@ -112,7 +98,24 @@ module RuboCop
112
98
  return if FROZEN_STRING_LITERAL_TYPES.include?(value.type) &&
113
99
  frozen_string_literals_enabled?
114
100
 
115
- add_offense(value)
101
+ add_offense(value) do |corrector|
102
+ autocorrect(corrector, value)
103
+ end
104
+ end
105
+
106
+ def autocorrect(corrector, node)
107
+ expr = node.source_range
108
+
109
+ splat_value = splat_value(node)
110
+ if splat_value
111
+ correct_splat_expansion(corrector, expr, splat_value)
112
+ elsif node.array_type? && !node.bracketed?
113
+ corrector.wrap(expr, '[', ']')
114
+ elsif requires_parentheses?(node)
115
+ corrector.wrap(expr, '(', ')')
116
+ end
117
+
118
+ corrector.insert_after(expr, '.freeze')
116
119
  end
117
120
 
118
121
  def mutable_literal?(value)
@@ -37,7 +37,9 @@ module RuboCop
37
37
 
38
38
  leading_space =
39
39
  range_with_surrounding_space(range: first_arg.begin,
40
- side: :left)
40
+ side: :left,
41
+ whitespace: true,
42
+ continuations: true)
41
43
 
42
44
  lambda do |corrector|
43
45
  corrector.replace(leading_space, '(')
@@ -73,7 +73,6 @@ module RuboCop
73
73
  }
74
74
  MATCHER
75
75
 
76
- # rubocop:disable Metrics/AbcSize
77
76
  def on_send(node)
78
77
  return unless sort_method?(node)
79
78
 
@@ -91,7 +90,6 @@ module RuboCop
91
90
  sorter,
92
91
  accessor))
93
92
  end
94
- # rubocop:enable Metrics/AbcSize
95
93
 
96
94
  def autocorrect(node)
97
95
  sort_node, sorter, accessor = redundant_sort?(node)
@@ -136,10 +136,10 @@ module RuboCop
136
136
  end
137
137
 
138
138
  def comments(node)
139
- processed_source.comments.select do |comment|
140
- comment.loc.first_line > node.loc.first_line &&
141
- comment.loc.last_line < node.loc.last_line
142
- end
139
+ processed_source.each_comment_in_lines(
140
+ node.loc.first_line...
141
+ node.loc.last_line
142
+ ).to_a
143
143
  end
144
144
 
145
145
  def allowed_if_condition?(node)
@@ -73,7 +73,7 @@ module RuboCop
73
73
 
74
74
  def move_comment(node, corrector)
75
75
  LineBreakCorrector.move_comment(
76
- eol_comment: end_of_line_comment(node.source_range.line),
76
+ eol_comment: processed_source.comment_at_line(node.source_range.line),
77
77
  node: node, corrector: corrector
78
78
  )
79
79
  end
@@ -14,10 +14,12 @@ module RuboCop
14
14
 
15
15
  module_function
16
16
 
17
+ # This is a bad API
17
18
  def comment_line?(line_source)
18
19
  /^\s*#/.match?(line_source)
19
20
  end
20
21
 
22
+ # @deprecated Use `ProcessedSource#line_with_comment?`, `contains_comment` or similar
21
23
  def comment_lines?(node)
22
24
  processed_source[line_range(node)].any? { |line| comment_line?(line) }
23
25
  end
@@ -10,7 +10,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
10
10
  #
11
11
  def initialize(departments: [])
12
12
  @departments = departments.map(&:to_sym).sort!
13
- @cops = RuboCop::Cop::Cop.registry
13
+ @cops = RuboCop::Cop::Registry.global
14
14
  @config = RuboCop::ConfigLoader.default_configuration
15
15
  end
16
16
 
@@ -114,7 +114,7 @@ module RuboCop
114
114
  def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
115
115
  output_buffer.puts "# Offense count: #{offense_count}" if @show_offense_counts
116
116
 
117
- cop_class = Cop::Cop.registry.find_by_cop_name(cop_name)
117
+ cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
118
118
  output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
119
119
 
120
120
  default_cfg = default_config(cop_name)
@@ -34,7 +34,7 @@ module RuboCop
34
34
  # https://github.com/mikian/rubocop-junit-formatter/blob/v0.1.4/lib/rubocop/formatter/junit_formatter.rb#L9
35
35
  #
36
36
  # In the future, it would be preferable to return only enabled cops.
37
- Cop::Cop.all.each do |cop|
37
+ Cop::Registry.all.each do |cop|
38
38
  target_offenses = offenses_for_cop(offenses, cop)
39
39
 
40
40
  next unless relevant_for_output?(options, target_offenses)
@@ -94,7 +94,7 @@ module RuboCop
94
94
  ['']
95
95
  else
96
96
  list.split(',').map do |c|
97
- Cop::Cop.qualified_cop_name(c, "--#{option} option")
97
+ Cop::Registry.qualified_cop_name(c, "--#{option} option")
98
98
  end
99
99
  end
100
100
  end
@@ -239,8 +239,8 @@ module RuboCop
239
239
  def validate_cop_list(names)
240
240
  return unless names
241
241
 
242
- cop_names = Cop::Cop.registry.names
243
- departments = Cop::Cop.registry.departments.map(&:to_s)
242
+ cop_names = Cop::Registry.global.names
243
+ departments = Cop::Registry.global.departments.map(&:to_s)
244
244
 
245
245
  names.each do |name|
246
246
  next if cop_names.include?(name)
@@ -44,8 +44,6 @@ end
44
44
  RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
45
45
  ### Meant to be overridden at will
46
46
 
47
- let(:source) { 'code = {some: :ruby}' }
48
-
49
47
  let(:cop_class) do
50
48
  unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
51
49
  raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
@@ -97,9 +95,7 @@ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
97
95
  end
98
96
 
99
97
  let(:cop) do
100
- cop_class.new(config, cop_options).tap do |cop|
101
- cop.send :begin_investigation, processed_source
102
- end
98
+ cop_class.new(config, cop_options)
103
99
  end
104
100
  end
105
101