rubocop 1.1.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -12
  3. data/config/default.yml +113 -16
  4. data/exe/rubocop +1 -1
  5. data/lib/rubocop.rb +9 -0
  6. data/lib/rubocop/cli/command/execute_runner.rb +26 -11
  7. data/lib/rubocop/config_loader.rb +14 -5
  8. data/lib/rubocop/config_regeneration.rb +1 -1
  9. data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
  10. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  11. data/lib/rubocop/cop/commissioner.rb +1 -1
  12. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  13. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -3
  14. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +4 -5
  15. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  16. data/lib/rubocop/cop/generator.rb +2 -9
  17. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  18. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -1
  19. data/lib/rubocop/cop/layout/block_alignment.rb +3 -4
  20. data/lib/rubocop/cop/layout/class_structure.rb +15 -3
  21. data/lib/rubocop/cop/layout/else_alignment.rb +15 -2
  22. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +77 -7
  23. data/lib/rubocop/cop/layout/end_alignment.rb +3 -3
  24. data/lib/rubocop/cop/layout/hash_alignment.rb +4 -4
  25. data/lib/rubocop/cop/layout/line_length.rb +8 -1
  26. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +24 -18
  27. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
  28. data/lib/rubocop/cop/layout/space_inside_parens.rb +35 -13
  29. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
  30. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +26 -2
  31. data/lib/rubocop/cop/lint/debugger.rb +17 -27
  32. data/lib/rubocop/cop/lint/duplicate_branch.rb +93 -0
  33. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +2 -12
  34. data/lib/rubocop/cop/lint/else_layout.rb +29 -3
  35. data/lib/rubocop/cop/lint/empty_block.rb +38 -2
  36. data/lib/rubocop/cop/lint/empty_class.rb +93 -0
  37. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +22 -4
  38. data/lib/rubocop/cop/lint/loop.rb +4 -4
  39. data/lib/rubocop/cop/lint/missing_super.rb +7 -4
  40. data/lib/rubocop/cop/lint/nested_percent_literal.rb +14 -0
  41. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -0
  42. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +19 -16
  43. data/lib/rubocop/cop/lint/shadowed_exception.rb +4 -5
  44. data/lib/rubocop/cop/lint/to_enum_arguments.rb +6 -15
  45. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +13 -4
  46. data/lib/rubocop/cop/lint/useless_method_definition.rb +2 -4
  47. data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -1
  48. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  49. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  50. data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
  51. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  52. data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
  53. data/lib/rubocop/cop/mixin/visibility_help.rb +1 -3
  54. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +11 -1
  55. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +11 -5
  56. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +67 -18
  57. data/lib/rubocop/cop/naming/variable_number.rb +98 -8
  58. data/lib/rubocop/cop/style/and_or.rb +1 -3
  59. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +0 -4
  60. data/lib/rubocop/cop/style/case_like_if.rb +0 -4
  61. data/lib/rubocop/cop/style/collection_compact.rb +91 -0
  62. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +107 -5
  63. data/lib/rubocop/cop/style/documentation.rb +12 -1
  64. data/lib/rubocop/cop/style/double_negation.rb +6 -1
  65. data/lib/rubocop/cop/style/hash_syntax.rb +3 -3
  66. data/lib/rubocop/cop/style/identical_conditional_branches.rb +7 -2
  67. data/lib/rubocop/cop/style/if_inside_else.rb +37 -1
  68. data/lib/rubocop/cop/style/if_unless_modifier.rb +7 -3
  69. data/lib/rubocop/cop/style/infinite_loop.rb +4 -0
  70. data/lib/rubocop/cop/style/keyword_parameters_order.rb +12 -0
  71. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
  72. data/lib/rubocop/cop/style/mixin_grouping.rb +0 -4
  73. data/lib/rubocop/cop/style/multiple_comparison.rb +3 -2
  74. data/lib/rubocop/cop/style/negated_if_else_condition.rb +106 -0
  75. data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
  76. data/lib/rubocop/cop/style/raise_args.rb +21 -6
  77. data/lib/rubocop/cop/style/redundant_argument.rb +73 -0
  78. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  79. data/lib/rubocop/cop/style/static_class.rb +97 -0
  80. data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
  81. data/lib/rubocop/cop/util.rb +5 -1
  82. data/lib/rubocop/cop/variable_force/branch.rb +1 -1
  83. data/lib/rubocop/cop/variable_force/scope.rb +1 -1
  84. data/lib/rubocop/ext/regexp_node.rb +10 -5
  85. data/lib/rubocop/ext/regexp_parser.rb +9 -2
  86. data/lib/rubocop/formatter/disabled_config_formatter.rb +21 -6
  87. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  88. data/lib/rubocop/formatter/git_hub_actions_formatter.rb +47 -0
  89. data/lib/rubocop/options.rb +7 -0
  90. data/lib/rubocop/rake_task.rb +2 -2
  91. data/lib/rubocop/runner.rb +1 -1
  92. data/lib/rubocop/target_finder.rb +1 -1
  93. data/lib/rubocop/target_ruby.rb +65 -1
  94. data/lib/rubocop/version.rb +1 -1
  95. metadata +14 -8
  96. data/bin/console +0 -10
  97. data/bin/rubocop-profile +0 -32
  98. data/bin/setup +0 -7
@@ -13,7 +13,8 @@ module RuboCop
13
13
  # `AllowAdjacentOneLineDefs` configures whether adjacent
14
14
  # one-line method definitions are considered an offense.
15
15
  #
16
- # @example
16
+ # @example EmptyLineBetweenMethodDefs: true (default)
17
+ # # checks for empty lines between method definitions.
17
18
  #
18
19
  # # bad
19
20
  # def a
@@ -29,11 +30,57 @@ module RuboCop
29
30
  #
30
31
  # def b
31
32
  # end
33
+ #
34
+ # @example EmptyLineBetweenClassDefs: true (default)
35
+ # # checks for empty lines between class definitions.
36
+ #
37
+ # # bad
38
+ # class A
39
+ # end
40
+ # class B
41
+ # end
42
+ # def b
43
+ # end
44
+ #
45
+ # @example
46
+ #
47
+ # # good
48
+ # class A
49
+ # end
50
+ #
51
+ # class B
52
+ # end
53
+ #
54
+ # def b
55
+ # end
56
+ #
57
+ # @example EmptyLineBetweenModuleDefs: true (default)
58
+ # # checks for empty lines between module definitions.
59
+ #
60
+ # # bad
61
+ # module A
62
+ # end
63
+ # module B
64
+ # end
65
+ # def b
66
+ # end
67
+ #
68
+ # @example
69
+ #
70
+ # # good
71
+ # module A
72
+ # end
73
+ #
74
+ # module B
75
+ # end
76
+ #
77
+ # def b
78
+ # end
32
79
  class EmptyLineBetweenDefs < Base
33
80
  include RangeHelp
34
81
  extend AutoCorrector
35
82
 
36
- MSG = 'Use empty lines between method definitions.'
83
+ MSG = 'Use empty lines between %<type>s definitions.'
37
84
 
38
85
  def self.autocorrect_incompatible_with
39
86
  [Layout::EmptyLines]
@@ -47,7 +94,7 @@ module RuboCop
47
94
  def on_begin(node)
48
95
  node.children.each_cons(2) do |prev, n|
49
96
  nodes = [prev, n]
50
- check_defs(nodes) if nodes.all?(&method(:def_node?))
97
+ check_defs(nodes) if nodes.all? { |def_candidate| candidate?(def_candidate) }
51
98
  end
52
99
  end
53
100
 
@@ -57,8 +104,9 @@ module RuboCop
57
104
  return if nodes.all?(&:single_line?) &&
58
105
  cop_config['AllowAdjacentOneLineDefs']
59
106
 
60
- location = nodes.last.loc.keyword.join(nodes.last.loc.name)
61
- add_offense(location) do |corrector|
107
+ correction_node = nodes.last
108
+ location = correction_node.loc.keyword.join(correction_node.loc.name)
109
+ add_offense(location, message: message(correction_node)) do |corrector|
62
110
  autocorrect(corrector, *nodes)
63
111
  end
64
112
  end
@@ -83,10 +131,32 @@ module RuboCop
83
131
 
84
132
  private
85
133
 
86
- def def_node?(node)
134
+ def candidate?(node)
87
135
  return unless node
88
136
 
89
- node.def_type? || node.defs_type?
137
+ method_candidate?(node) || class_candidate?(node) || module_candidate?(node)
138
+ end
139
+
140
+ def method_candidate?(node)
141
+ cop_config['EmptyLineBetweenMethodDefs'] && (node.def_type? || node.defs_type?)
142
+ end
143
+
144
+ def class_candidate?(node)
145
+ cop_config['EmptyLineBetweenClassDefs'] && node.class_type?
146
+ end
147
+
148
+ def module_candidate?(node)
149
+ cop_config['EmptyLineBetweenModuleDefs'] && node.module_type?
150
+ end
151
+
152
+ def message(node)
153
+ type = case node.type
154
+ when :def, :defs
155
+ :method
156
+ else
157
+ node.type
158
+ end
159
+ format(MSG, type: type)
90
160
  end
91
161
 
92
162
  def multiple_blank_lines_groups?(first_def_node, second_def_node)
@@ -137,10 +137,10 @@ module RuboCop
137
137
  def asgn_variable_align_with(outer_node, inner_node)
138
138
  expr = outer_node.source_range
139
139
 
140
- if !line_break_before_keyword?(expr, inner_node)
141
- range_between(expr.begin_pos, inner_node.loc.keyword.end_pos)
142
- else
140
+ if line_break_before_keyword?(expr, inner_node)
143
141
  inner_node.loc.keyword
142
+ else
143
+ range_between(expr.begin_pos, inner_node.loc.keyword.end_pos)
144
144
  end
145
145
  end
146
146
 
@@ -296,13 +296,13 @@ module RuboCop
296
296
  # just give each lambda the same reference and they would all get the
297
297
  # last value of each. A local variable fixes the problem.
298
298
 
299
- if !node.value
300
- delta_value = delta[:key] || 0
301
- correct_no_value(corrector, delta_value, node.source_range)
302
- else
299
+ if node.value
303
300
  correct_key_value(corrector, delta, node.key.source_range,
304
301
  node.value.source_range,
305
302
  node.loc.operator)
303
+ else
304
+ delta_value = delta[:key] || 0
305
+ correct_no_value(corrector, delta_value, node.source_range)
306
306
  end
307
307
  end
308
308
 
@@ -88,6 +88,10 @@ module RuboCop
88
88
  end
89
89
  end
90
90
 
91
+ def correctable?
92
+ super && !breakable_range.nil?
93
+ end
94
+
91
95
  def autocorrect(range)
92
96
  return if range.nil?
93
97
 
@@ -98,6 +102,8 @@ module RuboCop
98
102
 
99
103
  private
100
104
 
105
+ attr_accessor :breakable_range
106
+
101
107
  def check_for_breakable_node(node)
102
108
  breakable_node = extract_breakable_node(node, max)
103
109
  return if breakable_node.nil?
@@ -195,7 +201,8 @@ module RuboCop
195
201
  def register_offense(loc, line, line_index)
196
202
  message = format(MSG, length: line_length(line), max: max)
197
203
 
198
- breakable_range = breakable_range_by_line_index[line_index]
204
+ self.breakable_range = breakable_range_by_line_index[line_index]
205
+
199
206
  add_offense(breakable_range, location: loc, message: message) do
200
207
  self.max = line_length(line)
201
208
  end
@@ -54,17 +54,11 @@ module RuboCop
54
54
  end
55
55
 
56
56
  def check_inside_pipes(arguments)
57
- opening_pipe, closing_pipe = pipes(arguments)
58
-
59
57
  case style
60
58
  when :no_space
61
- check_no_space_style_inside_pipes(arguments.children,
62
- opening_pipe,
63
- closing_pipe)
59
+ check_no_space_style_inside_pipes(arguments)
64
60
  when :space
65
- check_space_style_inside_pipes(arguments.children,
66
- opening_pipe,
67
- closing_pipe)
61
+ check_space_style_inside_pipes(arguments)
68
62
  end
69
63
  end
70
64
 
@@ -76,22 +70,29 @@ module RuboCop
76
70
  closing_pipe, 'after closing `|`')
77
71
  end
78
72
 
79
- def check_no_space_style_inside_pipes(args, opening_pipe, closing_pipe)
73
+ def check_no_space_style_inside_pipes(arguments)
74
+ args = arguments.children
75
+ opening_pipe, closing_pipe = pipes(arguments)
76
+
80
77
  first = args.first.source_range
81
78
  last = args.last.source_range
82
79
 
83
80
  check_no_space(opening_pipe.end_pos, first.begin_pos,
84
81
  'Space before first')
85
- check_no_space(last_end_pos_inside_pipes(last),
82
+ check_no_space(last_end_pos_inside_pipes(arguments, last),
86
83
  closing_pipe.begin_pos, 'Space after last')
87
84
  end
88
85
 
89
- def check_space_style_inside_pipes(args, opening_pipe, closing_pipe)
90
- check_opening_pipe_space(args, opening_pipe)
91
- check_closing_pipe_space(args, closing_pipe)
86
+ def check_space_style_inside_pipes(arguments)
87
+ opening_pipe, closing_pipe = pipes(arguments)
88
+
89
+ check_opening_pipe_space(arguments, opening_pipe)
90
+ check_closing_pipe_space(arguments, closing_pipe)
92
91
  end
93
92
 
94
- def check_opening_pipe_space(args, opening_pipe)
93
+ def check_opening_pipe_space(arguments, opening_pipe)
94
+ args = arguments.children
95
+
95
96
  first_arg = args.first
96
97
  range = first_arg.source_range
97
98
 
@@ -101,9 +102,11 @@ module RuboCop
101
102
  'Extra space before first')
102
103
  end
103
104
 
104
- def check_closing_pipe_space(args, closing_pipe)
105
+ def check_closing_pipe_space(arguments, closing_pipe)
106
+ args = arguments.children
107
+
105
108
  last = args.last.source_range
106
- last_end_pos = last_end_pos_inside_pipes(last)
109
+ last_end_pos = last_end_pos_inside_pipes(arguments, last)
107
110
 
108
111
  check_space(last_end_pos, closing_pipe.begin_pos, last,
109
112
  'after last block parameter')
@@ -111,9 +114,12 @@ module RuboCop
111
114
  'Extra space after last')
112
115
  end
113
116
 
114
- def last_end_pos_inside_pipes(range)
117
+ def last_end_pos_inside_pipes(arguments, range)
115
118
  pos = range.end_pos
116
- range.source_buffer.source[pos] == ',' ? pos + 1 : pos
119
+ num = pos - arguments.source_range.begin_pos
120
+ trailing_comma_index = arguments.source[num..-1].index(',')
121
+
122
+ trailing_comma_index ? pos + trailing_comma_index + 1 : pos
117
123
  end
118
124
 
119
125
  def check_each_arg(args)
@@ -51,7 +51,7 @@ module RuboCop
51
51
  alias on_csend on_send
52
52
 
53
53
  def on_const(node)
54
- return unless node.loc.double_colon
54
+ return unless node.loc.respond_to?(:double_colon) && node.loc.double_colon
55
55
 
56
56
  check_space_after_double_colon(node)
57
57
  end
@@ -11,10 +11,12 @@ module RuboCop
11
11
  # # bad
12
12
  # f( 3)
13
13
  # g = (a + 3 )
14
+ # f( )
14
15
  #
15
16
  # # good
16
17
  # f(3)
17
18
  # g = (a + 3)
19
+ # f()
18
20
  #
19
21
  # @example EnforcedStyle: space
20
22
  # # The `space` style enforces that parentheses have a space at the
@@ -44,11 +46,7 @@ module RuboCop
44
46
  @processed_source = processed_source
45
47
 
46
48
  if style == :space
47
- each_missing_space(processed_source.tokens) do |range|
48
- add_offense(range, message: MSG_SPACE) do |corrector|
49
- corrector.insert_before(range, ' ')
50
- end
51
- end
49
+ process_with_space_style(processed_source)
52
50
  else
53
51
  each_extraneous_space(processed_source.tokens) do |range|
54
52
  add_offense(range) do |corrector|
@@ -60,6 +58,21 @@ module RuboCop
60
58
 
61
59
  private
62
60
 
61
+ def process_with_space_style(processed_source)
62
+ processed_source.tokens.each_cons(2) do |token1, token2|
63
+ each_extraneous_space_in_empty_parens(token1, token2) do |range|
64
+ add_offense(range) do |corrector|
65
+ corrector.remove(range)
66
+ end
67
+ end
68
+ each_missing_space(token1, token2) do |range|
69
+ add_offense(range, message: MSG_SPACE) do |corrector|
70
+ corrector.insert_before(range, ' ')
71
+ end
72
+ end
73
+ end
74
+ end
75
+
63
76
  def each_extraneous_space(tokens)
64
77
  tokens.each_cons(2) do |token1, token2|
65
78
  next unless parens?(token1, token2)
@@ -73,15 +86,21 @@ module RuboCop
73
86
  end
74
87
  end
75
88
 
76
- def each_missing_space(tokens)
77
- tokens.each_cons(2) do |token1, token2|
78
- next if can_be_ignored?(token1, token2)
89
+ def each_extraneous_space_in_empty_parens(token1, token2)
90
+ return unless token1.left_parens? && token2.right_parens?
79
91
 
80
- if token1.left_parens?
81
- yield range_between(token2.begin_pos, token2.begin_pos + 1)
82
- elsif token2.right_parens?
83
- yield range_between(token2.begin_pos, token2.end_pos)
84
- end
92
+ return if range_between(token1.begin_pos, token2.end_pos).source == '()'
93
+
94
+ yield range_between(token1.end_pos, token2.begin_pos)
95
+ end
96
+
97
+ def each_missing_space(token1, token2)
98
+ return if can_be_ignored?(token1, token2)
99
+
100
+ if token1.left_parens?
101
+ yield range_between(token2.begin_pos, token2.begin_pos + 1)
102
+ elsif token2.right_parens?
103
+ yield range_between(token2.begin_pos, token2.end_pos)
85
104
  end
86
105
  end
87
106
 
@@ -96,6 +115,9 @@ module RuboCop
96
115
  def can_be_ignored?(token1, token2)
97
116
  return true unless parens?(token1, token2)
98
117
 
118
+ # Ignore empty parentheses.
119
+ return true if range_between(token1.begin_pos, token2.end_pos).source == '()'
120
+
99
121
  # If the second token is a comment, that means that a line break
100
122
  # follows, and that the rules for space inside don't apply.
101
123
  return true if token2.comment?
@@ -53,7 +53,8 @@ module RuboCop
53
53
  def find_offense_node(node, regexp_receiver)
54
54
  return node unless node.parent
55
55
 
56
- if node.parent.send_type? || method_chain_to_regexp_receiver?(node, regexp_receiver)
56
+ if (node.parent.send_type? && node.receiver) ||
57
+ method_chain_to_regexp_receiver?(node, regexp_receiver)
57
58
  node = find_offense_node(node.parent, regexp_receiver)
58
59
  end
59
60
 
@@ -49,7 +49,21 @@ module RuboCop
49
49
  # const_set(:LIST, [])
50
50
  # end
51
51
  # end
52
+ #
53
+ # @example AllowedMethods: ['enums'] (default)
54
+ # # good
55
+ #
56
+ # # `enums` for Typed Enums via `T::Enum` in Sorbet.
57
+ # # https://sorbet.org/docs/tenum
58
+ # class TestEnum < T::Enum
59
+ # enums do
60
+ # Foo = new("foo")
61
+ # end
62
+ # end
63
+ #
52
64
  class ConstantDefinitionInBlock < Base
65
+ include AllowedMethods
66
+
53
67
  MSG = 'Do not define constants this way within a block.'
54
68
 
55
69
  def_node_matcher :constant_assigned_in_block?, <<~PATTERN
@@ -61,13 +75,23 @@ module RuboCop
61
75
  PATTERN
62
76
 
63
77
  def on_casgn(node)
64
- add_offense(node) if constant_assigned_in_block?(node)
78
+ return if !constant_assigned_in_block?(node) || allowed_method?(method_name(node))
79
+
80
+ add_offense(node)
65
81
  end
66
82
 
67
83
  def on_class(node)
68
- add_offense(node) if module_defined_in_block?(node)
84
+ return if !module_defined_in_block?(node) || allowed_method?(method_name(node))
85
+
86
+ add_offense(node)
69
87
  end
70
88
  alias on_module on_class
89
+
90
+ private
91
+
92
+ def method_name(node)
93
+ node.ancestors.find(&:block_type?).send_node.method_name
94
+ end
71
95
  end
72
96
  end
73
97
  end
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  # This cop checks for calls to debugger or pry.
7
+ # The cop can be configured to define which methods and receivers must be fixed.
7
8
  #
8
9
  # @example
9
10
  #
@@ -35,33 +36,11 @@ module RuboCop
35
36
  class Debugger < Base
36
37
  MSG = 'Remove debugger entry point `%<source>s`.'
37
38
 
38
- RESTRICT_ON_SEND = %i[
39
- debugger byebug remote_byebug pry remote_pry pry_remote console rescue
40
- save_and_open_page save_and_open_screenshot irb
41
- ].freeze
42
-
43
- def_node_matcher :kernel?, <<~PATTERN
44
- {
45
- (const nil? :Kernel)
46
- (const (cbase) :Kernel)
47
- }
48
- PATTERN
49
-
50
- def_node_matcher :debugger_call?, <<~PATTERN
51
- {(send {nil? #kernel?} {:debugger :byebug :remote_byebug} ...)
52
- (send (send {#kernel? nil?} :binding)
53
- {:pry :remote_pry :pry_remote :console} ...)
54
- (send (const {nil? (cbase)} :Pry) :rescue ...)
55
- (send nil? {:save_and_open_page
56
- :save_and_open_screenshot} ...)}
57
- PATTERN
58
-
59
- def_node_matcher :binding_irb_call?, <<~PATTERN
60
- (send (send {#kernel? nil?} :binding) :irb ...)
61
- PATTERN
39
+ RESTRICT_ON_SEND = [].freeze
62
40
 
63
41
  def on_send(node)
64
- return unless debugger_call?(node) || binding_irb?(node)
42
+ return unless debugger_method?(node.method_name)
43
+ return if !node.receiver.nil? && !debugger_receiver?(node)
65
44
 
66
45
  add_offense(node)
67
46
  end
@@ -72,8 +51,19 @@ module RuboCop
72
51
  format(MSG, source: node.source)
73
52
  end
74
53
 
75
- def binding_irb?(node)
76
- binding_irb_call?(node)
54
+ def debugger_method?(name)
55
+ cop_config.fetch('DebuggerMethods', []).include?(name.to_s)
56
+ end
57
+
58
+ def debugger_receiver?(node)
59
+ receiver = case node.receiver
60
+ when RuboCop::AST::SendNode
61
+ node.receiver.method_name
62
+ when RuboCop::AST::ConstNode
63
+ node.receiver.const_name
64
+ end
65
+
66
+ cop_config.fetch('DebuggerReceivers', []).include?(receiver.to_s)
77
67
  end
78
68
  end
79
69
  end