rubocop 0.90.0 → 0.91.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +35 -0
  4. data/lib/rubocop.rb +10 -1
  5. data/lib/rubocop/cli/command/execute_runner.rb +8 -0
  6. data/lib/rubocop/config_loader.rb +3 -3
  7. data/lib/rubocop/config_store.rb +3 -3
  8. data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -1
  9. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
  10. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -0
  11. data/lib/rubocop/cop/generator.rb +1 -1
  12. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
  13. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
  14. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -0
  15. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
  16. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -0
  17. data/lib/rubocop/cop/layout/begin_end_alignment.rb +77 -0
  18. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  19. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +6 -5
  20. data/lib/rubocop/cop/layout/end_alignment.rb +5 -10
  21. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +17 -4
  22. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -3
  23. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -6
  24. data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -0
  25. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -2
  26. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +54 -0
  27. data/lib/rubocop/cop/lint/debugger.rb +2 -3
  28. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -3
  29. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -4
  30. data/lib/rubocop/cop/lint/duplicate_require.rb +7 -2
  31. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
  32. data/lib/rubocop/cop/lint/empty_file.rb +1 -4
  33. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -0
  34. data/lib/rubocop/cop/lint/float_comparison.rb +2 -2
  35. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
  36. data/lib/rubocop/cop/lint/identity_comparison.rb +49 -0
  37. data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
  38. data/lib/rubocop/cop/lint/multiple_comparison.rb +3 -1
  39. data/lib/rubocop/cop/lint/number_conversion.rb +1 -0
  40. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -2
  41. data/lib/rubocop/cop/lint/raise_exception.rb +1 -0
  42. data/lib/rubocop/cop/lint/rand_one.rb +2 -1
  43. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
  44. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +3 -1
  45. data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
  46. data/lib/rubocop/cop/lint/to_json.rb +16 -5
  47. data/lib/rubocop/cop/lint/unreachable_loop.rb +2 -1
  48. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -1
  49. data/lib/rubocop/cop/lint/uri_regexp.rb +2 -1
  50. data/lib/rubocop/cop/lint/useless_method_definition.rb +20 -27
  51. data/lib/rubocop/cop/lint/useless_times.rb +97 -0
  52. data/lib/rubocop/cop/mixin/comments_help.rb +3 -9
  53. data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
  54. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +9 -0
  55. data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -1
  56. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  57. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  58. data/lib/rubocop/cop/security/eval.rb +1 -0
  59. data/lib/rubocop/cop/security/json_load.rb +1 -0
  60. data/lib/rubocop/cop/security/marshal_load.rb +1 -0
  61. data/lib/rubocop/cop/security/open.rb +1 -0
  62. data/lib/rubocop/cop/security/yaml_load.rb +1 -0
  63. data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -11
  64. data/lib/rubocop/cop/style/alias.rb +2 -0
  65. data/lib/rubocop/cop/style/array_join.rb +1 -0
  66. data/lib/rubocop/cop/style/attr.rb +1 -0
  67. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -0
  68. data/lib/rubocop/cop/style/case_equality.rb +3 -0
  69. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
  70. data/lib/rubocop/cop/style/class_check.rb +6 -9
  71. data/lib/rubocop/cop/style/class_methods_definitions.rb +42 -16
  72. data/lib/rubocop/cop/style/class_vars.rb +1 -2
  73. data/lib/rubocop/cop/style/conditional_assignment.rb +49 -60
  74. data/lib/rubocop/cop/style/dir.rb +1 -0
  75. data/lib/rubocop/cop/style/double_negation.rb +1 -0
  76. data/lib/rubocop/cop/style/empty_literal.rb +3 -1
  77. data/lib/rubocop/cop/style/eval_with_location.rb +1 -3
  78. data/lib/rubocop/cop/style/even_odd.rb +1 -0
  79. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  80. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  81. data/lib/rubocop/cop/style/float_division.rb +2 -0
  82. data/lib/rubocop/cop/style/format_string.rb +1 -4
  83. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +12 -2
  84. data/lib/rubocop/cop/style/hash_transform_keys.rb +5 -11
  85. data/lib/rubocop/cop/style/hash_transform_values.rb +5 -11
  86. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
  87. data/lib/rubocop/cop/style/lambda_call.rb +3 -1
  88. data/lib/rubocop/cop/style/mixin_usage.rb +1 -0
  89. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +14 -1
  90. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  91. data/lib/rubocop/cop/style/non_nil_check.rb +2 -0
  92. data/lib/rubocop/cop/style/not.rb +1 -0
  93. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -3
  94. data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -0
  95. data/lib/rubocop/cop/style/raise_args.rb +2 -0
  96. data/lib/rubocop/cop/style/random_with_offset.rb +1 -0
  97. data/lib/rubocop/cop/style/redundant_exception.rb +1 -3
  98. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
  99. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -1
  100. data/lib/rubocop/cop/style/redundant_parentheses.rb +12 -3
  101. data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -2
  102. data/lib/rubocop/cop/style/redundant_sort.rb +1 -7
  103. data/lib/rubocop/cop/style/safe_navigation.rb +5 -0
  104. data/lib/rubocop/cop/style/sample.rb +2 -1
  105. data/lib/rubocop/cop/style/send.rb +2 -3
  106. data/lib/rubocop/cop/style/signal_exception.rb +2 -0
  107. data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
  108. data/lib/rubocop/cop/style/slicing_with_range.rb +2 -1
  109. data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
  110. data/lib/rubocop/cop/style/string_concatenation.rb +16 -2
  111. data/lib/rubocop/cop/style/strip.rb +1 -0
  112. data/lib/rubocop/cop/style/unpack_first.rb +1 -0
  113. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -5
  114. data/lib/rubocop/core_ext/string.rb +1 -1
  115. data/lib/rubocop/ext/regexp_node.rb +4 -4
  116. data/lib/rubocop/options.rb +19 -1
  117. data/lib/rubocop/result_cache.rb +30 -13
  118. data/lib/rubocop/runner.rb +29 -14
  119. data/lib/rubocop/version.rb +1 -1
  120. metadata +8 -4
@@ -26,6 +26,7 @@ module RuboCop
26
26
  extend AutoCorrector
27
27
 
28
28
  MSG = 'Remove unnecessary `require` statement.'
29
+ RESTRICT_ON_SEND = %i[require].freeze
29
30
 
30
31
  def_node_matcher :unnecessary_require_statement?, <<~PATTERN
31
32
  (send nil? :require
@@ -40,10 +40,12 @@ module RuboCop
40
40
 
41
41
  MSG = 'Use `%<method>s %<module_name>s` instead of `%<bad_method>s`.'
42
42
  MIXIN_METHODS = %i[include prepend extend].freeze
43
+ SEND_METHODS = %i[send public_send __send__].freeze
44
+ RESTRICT_ON_SEND = SEND_METHODS
43
45
 
44
46
  def_node_matcher :send_with_mixin_argument?, <<~PATTERN
45
47
  (send
46
- (const _ _) {:send :public_send :__send__}
48
+ (const _ _) {:#{SEND_METHODS.join(' :')}}
47
49
  ({sym str} $#mixin_method?)
48
50
  $(const _ _))
49
51
  PATTERN
@@ -24,6 +24,7 @@ module RuboCop
24
24
  class StructNewOverride < Base
25
25
  MSG = '`%<member_name>s` member overrides `Struct#%<method_name>s`' \
26
26
  ' and it may be unexpected.'
27
+ RESTRICT_ON_SEND = %i[new].freeze
27
28
 
28
29
  STRUCT_METHOD_NAMES = Struct.instance_methods
29
30
  STRUCT_MEMBER_NAME_TYPES = %i[sym str].freeze
@@ -9,12 +9,23 @@ module RuboCop
9
9
  # for an optional argument, your method should too.
10
10
  #
11
11
  # @example
12
- # # bad
13
- # def to_json
14
- # end
12
+ # class Point
13
+ # attr_reader :x, :y
14
+ #
15
+ # # bad, incorrect arity
16
+ # def to_json
17
+ # JSON.generate([x, y])
18
+ # end
19
+ #
20
+ # # good, preserving args
21
+ # def to_json(*args)
22
+ # JSON.generate([x, y], *args)
23
+ # end
15
24
  #
16
- # # good
17
- # def to_json(*_args)
25
+ # # good, discarding args
26
+ # def to_json(*_args)
27
+ # JSON.generate([x, y])
28
+ # end
18
29
  # end
19
30
  #
20
31
  class ToJSON < Base
@@ -130,7 +130,8 @@ module RuboCop
130
130
  case node.type
131
131
  when :begin, :kwbegin
132
132
  statements = *node
133
- statements.any? { |statement| break_statement?(statement) }
133
+ break_statement = statements.find { |statement| break_statement?(statement) }
134
+ break_statement && !preceded_by_continue_statement?(break_statement)
134
135
  when :if
135
136
  check_if(node)
136
137
  when :case
@@ -44,10 +44,12 @@ module RuboCop
44
44
  MSG = '`%<uri_method>s` method is obsolete and should not be used. ' \
45
45
  'Instead, use %<replacements>s depending on your specific use ' \
46
46
  'case.'
47
+ METHOD_NAMES = %i[escape encode unescape decode].freeze
48
+ RESTRICT_ON_SEND = METHOD_NAMES
47
49
 
48
50
  def_node_matcher :uri_escape_unescape?, <<~PATTERN
49
51
  (send
50
- (const ${nil? cbase} :URI) ${:escape :encode :unescape :decode}
52
+ (const ${nil? cbase} :URI) ${:#{METHOD_NAMES.join(' :')}}
51
53
  ...)
52
54
  PATTERN
53
55
 
@@ -18,9 +18,10 @@ module RuboCop
18
18
 
19
19
  MSG = '`%<current>s` is obsolete and should not be used. Instead, use `%<preferred>s`.'
20
20
  URI_CONSTANTS = ['URI', '::URI'].freeze
21
+ RESTRICT_ON_SEND = %i[regexp].freeze
21
22
 
22
23
  def on_send(node)
23
- return unless node.method?(:regexp) && node.receiver
24
+ return unless node.receiver
24
25
  return unless URI_CONSTANTS.include?(node.receiver.source)
25
26
 
26
27
  argument = node.first_argument ? "(#{node.first_argument.source})" : ''
@@ -12,32 +12,26 @@ module RuboCop
12
12
  # @example
13
13
  # # bad
14
14
  # def initialize
15
+ # super
15
16
  # end
16
17
  #
17
18
  # def method
18
19
  # super
19
20
  # end
20
21
  #
21
- # # good
22
- # def initialize
23
- # initialize_internals
24
- # end
25
- #
26
- # def method
22
+ # # good - with default arguments
23
+ # def initialize(x = Object.new)
27
24
  # super
28
- # do_something_else
29
25
  # end
30
26
  #
31
- # @example AllowComments: true (default)
32
27
  # # good
33
28
  # def initialize
34
- # # Comment.
29
+ # super
30
+ # initialize_internals
35
31
  # end
36
32
  #
37
- # @example AllowComments: false
38
- # # bad
39
- # def initialize
40
- # # Comment.
33
+ # def method(*args)
34
+ # super(:extra_arg, *args)
41
35
  # end
42
36
  #
43
37
  class UselessMethodDefinition < Base
@@ -46,8 +40,8 @@ module RuboCop
46
40
  MSG = 'Useless method definition detected.'
47
41
 
48
42
  def on_def(node)
49
- return unless (constructor?(node) && empty_constructor?(node)) ||
50
- delegating?(node.body, node)
43
+ return if optional_args?(node)
44
+ return unless delegating?(node.body, node)
51
45
 
52
46
  add_offense(node) { |corrector| corrector.remove(node) }
53
47
  end
@@ -55,21 +49,20 @@ module RuboCop
55
49
 
56
50
  private
57
51
 
58
- def empty_constructor?(node)
59
- return false if node.body
60
- return false if cop_config['AllowComments'] && comment_lines?(node)
61
-
62
- true
63
- end
64
-
65
- def constructor?(node)
66
- node.def_type? && node.method?(:initialize)
52
+ def optional_args?(node)
53
+ node.arguments.any? { |arg| arg.optarg_type? || arg.kwoptarg_type? }
67
54
  end
68
55
 
69
56
  def delegating?(node, def_node)
70
- return false unless node&.super_type? || node&.zsuper_type?
71
-
72
- !node.arguments? || node.arguments.map(&:source) == def_node.arguments.map(&:source)
57
+ if node.nil?
58
+ false
59
+ elsif node.zsuper_type?
60
+ true
61
+ elsif node.super_type?
62
+ node.arguments.map(&:source) == def_node.arguments.map(&:source)
63
+ else
64
+ false
65
+ end
73
66
  end
74
67
  end
75
68
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # This cop checks for uses of `Integer#times` that will never yield
7
+ # (when the integer <= 0) or that will only ever yield once
8
+ # (`1.times`).
9
+ #
10
+ # This cop is marked as unsafe as `times` returns its receiver, which
11
+ # is *usually* OK, but might change behavior.
12
+ #
13
+ # @example
14
+ # # bad
15
+ # -5.times { do_something }
16
+ # 0.times { do_something }
17
+ # 1.times { do_something }
18
+ # 1.times { |i| do_something(i) }
19
+ #
20
+ # # good
21
+ # do_something
22
+ # do_something(1)
23
+ class UselessTimes < Base
24
+ include RangeHelp
25
+ extend AutoCorrector
26
+
27
+ MSG = 'Useless call to `%<count>i.times` detected.'
28
+ RESTRICT_ON_SEND = %i[times].freeze
29
+
30
+ def_node_matcher :times_call?, <<~PATTERN
31
+ (send (int $_) :times (block-pass (sym $_))?)
32
+ PATTERN
33
+
34
+ def_node_matcher :block_arg, <<~PATTERN
35
+ (block _ (args (arg $_)) ...)
36
+ PATTERN
37
+
38
+ def_node_search :block_reassigns_arg?, <<~PATTERN
39
+ (lvasgn %)
40
+ PATTERN
41
+
42
+ def on_send(node)
43
+ return unless (count, proc_name = times_call?(node))
44
+ return if count > 1
45
+
46
+ # Get the block node if applicable
47
+ node = node.block_node if node.block_literal?
48
+
49
+ add_offense(node, message: format(MSG, count: count)) do |corrector|
50
+ next unless own_line?(node)
51
+
52
+ if count < 1
53
+ remove_node(corrector, node)
54
+ elsif !proc_name.empty?
55
+ autocorrect_block_pass(corrector, node, proc_name)
56
+ else
57
+ autocorrect_block(corrector, node)
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def remove_node(corrector, node)
65
+ corrector.remove(range_by_whole_lines(node.loc.expression, include_final_newline: true))
66
+ end
67
+
68
+ def autocorrect_block_pass(corrector, node, proc_name)
69
+ corrector.replace(node, proc_name)
70
+ end
71
+
72
+ def autocorrect_block(corrector, node)
73
+ block_arg = block_arg(node)
74
+ return if block_reassigns_arg?(node, block_arg)
75
+
76
+ source = node.body.source
77
+ source.gsub!(/\b#{block_arg}\b/, '1') if block_arg
78
+
79
+ corrector.replace(node, fix_indentation(source, node.loc.column...node.body.loc.column))
80
+ end
81
+
82
+ def fix_indentation(source, range)
83
+ # Cleanup indentation in a multiline block
84
+ source_lines = source.split("\n")
85
+ source_lines[1..-1].each { |line| line[range] = '' }
86
+ source_lines.join("\n")
87
+ end
88
+
89
+ def own_line?(node)
90
+ # If there is anything else on the line other than whitespace,
91
+ # don't try to autocorrect
92
+ processed_source.buffer.source_line(node.loc.line)[0...node.loc.column] !~ /\S/
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -7,15 +7,9 @@ module RuboCop
7
7
  include VisibilityHelp
8
8
 
9
9
  def source_range_with_comment(node)
10
- begin_pos, end_pos =
11
- if node.def_type?
12
- start_node = find_visibility_start(node) || node
13
- end_node = find_visibility_end(node) || node
14
- [begin_pos_with_comment(start_node),
15
- end_position_for(end_node) + 1]
16
- else
17
- [begin_pos_with_comment(node), end_position_for(node)]
18
- end
10
+ begin_pos = begin_pos_with_comment(node)
11
+ end_pos = end_position_for(node)
12
+ end_pos += 1 if node.def_type?
19
13
 
20
14
  Parser::Source::Range.new(buffer, begin_pos, end_pos)
21
15
  end
@@ -8,8 +8,8 @@ module RuboCop
8
8
  include ConfigurableFormatting
9
9
 
10
10
  FORMATS = {
11
- snake_case: /^@{0,2}[\da-z_]+[!?=]?$/,
12
- camelCase: /^@{0,2}(?:_|_?[a-z][\da-zA-Z]*)[!?=]?$/
11
+ snake_case: /^@{0,2}[\d[[:lower:]]_]+[!?=]?$/,
12
+ camelCase: /^@{0,2}(?:_|_?[[[:lower:]]][\d[[:lower:]][[:upper:]]]*)[!?=]?$/
13
13
  }.freeze
14
14
  end
15
15
  end
@@ -39,6 +39,15 @@ module RuboCop
39
39
  end
40
40
  end
41
41
 
42
+ def start_line_range(node)
43
+ expr = node.source_range
44
+ buffer = expr.source_buffer
45
+ source = buffer.source_line(expr.line)
46
+ range = buffer.line_range(expr.line)
47
+
48
+ range_between(range.begin_pos + (source =~ /\S/), range.begin_pos + (source =~ /\s*\z/))
49
+ end
50
+
42
51
  def add_offense_for_misalignment(node, align_with)
43
52
  end_loc = node.loc.end
44
53
  msg = format(MSG, end_line: end_loc.line,
@@ -4,7 +4,15 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for Style/HashTransformKeys and
6
6
  # Style/HashTransformValues
7
- module HashTransformMethod
7
+ module HashTransformMethod # rubocop:disable Metrics/ModuleLength
8
+ extend NodePattern::Macros
9
+
10
+ RESTRICT_ON_SEND = %i[[] to_h].freeze
11
+
12
+ def_node_matcher :array_receiver?, <<~PATTERN
13
+ {(array ...) (send _ :each_with_index) (send _ :with_index _ ?) (send _ :zip ...)}
14
+ PATTERN
15
+
8
16
  def on_block(node)
9
17
  on_bad_each_with_object(node) do |*match|
10
18
  handle_possible_offense(node, match, 'each_with_object')
@@ -35,7 +35,7 @@ module RuboCop
35
35
  def op_method?(name)
36
36
  return false if EXCLUDED.include?(name)
37
37
 
38
- !/\A\w/.match?(name) || OP_LIKE_METHODS.include?(name)
38
+ !/\A[[:word:]]/.match?(name) || OP_LIKE_METHODS.include?(name)
39
39
  end
40
40
  end
41
41
  end
@@ -33,7 +33,7 @@ module RuboCop
33
33
  'called `%<namespace>s`.'
34
34
  MSG_REGEX = '`%<basename>s` should match `%<regex>s`.'
35
35
 
36
- SNAKE_CASE = /^[\da-z_.?!]+$/.freeze
36
+ SNAKE_CASE = /^[\d[[:lower:]]_.?!]+$/.freeze
37
37
 
38
38
  def on_new_investigation
39
39
  file_path = processed_source.file_path
@@ -13,6 +13,7 @@ module RuboCop
13
13
  # binding.eval(something)
14
14
  class Eval < Base
15
15
  MSG = 'The use of `eval` is a serious security risk.'
16
+ RESTRICT_ON_SEND = %i[eval].freeze
16
17
 
17
18
  def_node_matcher :eval?, <<~PATTERN
18
19
  (send {nil? (send nil? :binding)} :eval $!str ...)
@@ -26,6 +26,7 @@ module RuboCop
26
26
  extend AutoCorrector
27
27
 
28
28
  MSG = 'Prefer `JSON.parse` over `JSON.%<method>s`.'
29
+ RESTRICT_ON_SEND = %i[load restore].freeze
29
30
 
30
31
  def_node_matcher :json_load, <<~PATTERN
31
32
  (send (const {nil? cbase} :JSON) ${:load :restore} ...)
@@ -20,6 +20,7 @@ module RuboCop
20
20
  #
21
21
  class MarshalLoad < Base
22
22
  MSG = 'Avoid using `Marshal.%<method>s`.'
23
+ RESTRICT_ON_SEND = %i[load restore].freeze
23
24
 
24
25
  def_node_matcher :marshal_load, <<~PATTERN
25
26
  (send (const {nil? cbase} :Marshal) ${:load :restore}
@@ -21,6 +21,7 @@ module RuboCop
21
21
  # URI.parse(something).open
22
22
  class Open < Base
23
23
  MSG = 'The use of `Kernel#open` is a serious security risk.'
24
+ RESTRICT_ON_SEND = %i[open].freeze
24
25
 
25
26
  def_node_matcher :open?, <<~PATTERN
26
27
  (send nil? :open $!str ...)
@@ -19,6 +19,7 @@ module RuboCop
19
19
  extend AutoCorrector
20
20
 
21
21
  MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'
22
+ RESTRICT_ON_SEND = %i[load].freeze
22
23
 
23
24
  def_node_matcher :yaml_load, <<~PATTERN
24
25
  (send (const {nil? cbase} :YAML) :load ...)
@@ -65,8 +65,6 @@ module RuboCop
65
65
  class AccessModifierDeclarations < Base
66
66
  include ConfigurableEnforcedStyle
67
67
 
68
- ACCESS_MODIFIERS = %i[private protected public module_function].to_set.freeze
69
-
70
68
  GROUP_STYLE_MESSAGE = [
71
69
  '`%<access_modifier>s` should not be',
72
70
  'inlined in method definitions.'
@@ -77,12 +75,14 @@ module RuboCop
77
75
  'inlined in method definitions.'
78
76
  ].join(' ')
79
77
 
78
+ RESTRICT_ON_SEND = %i[private protected public module_function].freeze
79
+
80
80
  def_node_matcher :access_modifier_with_symbol?, <<~PATTERN
81
81
  (send nil? {:private :protected :public} (sym _))
82
82
  PATTERN
83
83
 
84
84
  def on_send(node)
85
- return unless access_modifier?(node)
85
+ return unless node.access_modifier?
86
86
  return if node.parent.pair_type?
87
87
  return if cop_config['AllowModifiersOnSymbols'] && access_modifier_with_symbol?(node)
88
88
 
@@ -95,14 +95,6 @@ module RuboCop
95
95
 
96
96
  private
97
97
 
98
- def access_modifier?(node)
99
- maybe_access_modifier?(node) && node.access_modifier?
100
- end
101
-
102
- def maybe_access_modifier?(node)
103
- !node.receiver && ACCESS_MODIFIERS.include?(node.method_name)
104
- end
105
-
106
98
  def offense?(node)
107
99
  (group_style? && access_modifier_is_inlined?(node)) ||
108
100
  (inline_style? && access_modifier_is_not_inlined?(node))