rubocop 1.10.0 → 1.11.0

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 (199) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -12
  3. data/assets/output.html.erb +1 -1
  4. data/config/default.yml +13 -0
  5. data/lib/rubocop.rb +1 -0
  6. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  7. data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
  8. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
  9. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
  10. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
  11. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
  12. data/lib/rubocop/cop/gemspec/date_assignment.rb +1 -0
  13. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
  14. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
  15. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
  16. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
  17. data/lib/rubocop/cop/generator.rb +2 -2
  18. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  19. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
  20. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
  21. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
  22. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
  23. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
  24. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
  25. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
  26. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
  27. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
  28. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
  29. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
  30. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
  31. data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
  32. data/lib/rubocop/cop/layout/class_structure.rb +1 -0
  33. data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
  34. data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
  35. data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
  36. data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
  37. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  38. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
  39. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
  40. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
  41. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
  42. data/lib/rubocop/cop/lint/debugger.rb +3 -1
  43. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -0
  44. data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
  45. data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
  46. data/lib/rubocop/cop/lint/duplicate_require.rb +1 -0
  47. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
  48. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
  49. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
  50. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
  51. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
  52. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
  53. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -0
  54. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
  55. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
  56. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
  57. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
  58. data/lib/rubocop/cop/lint/number_conversion.rb +2 -0
  59. data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
  60. data/lib/rubocop/cop/lint/rand_one.rb +1 -0
  61. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
  62. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
  63. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -0
  64. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
  65. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
  66. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
  67. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
  68. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
  69. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
  70. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  71. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
  72. data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
  73. data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
  74. data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
  75. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
  76. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
  77. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
  78. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
  79. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
  80. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
  81. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
  82. data/lib/rubocop/cop/lint/useless_times.rb +3 -0
  83. data/lib/rubocop/cop/metrics/module_length.rb +1 -0
  84. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -0
  85. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
  86. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
  87. data/lib/rubocop/cop/mixin/def_node.rb +1 -0
  88. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
  89. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
  90. data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
  91. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
  92. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
  93. data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
  94. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
  95. data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
  96. data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
  97. data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
  98. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
  99. data/lib/rubocop/cop/naming/constant_name.rb +2 -0
  100. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -0
  101. data/lib/rubocop/cop/naming/method_name.rb +3 -0
  102. data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
  103. data/lib/rubocop/cop/security/eval.rb +1 -0
  104. data/lib/rubocop/cop/security/json_load.rb +1 -0
  105. data/lib/rubocop/cop/security/marshal_load.rb +1 -0
  106. data/lib/rubocop/cop/security/open.rb +1 -0
  107. data/lib/rubocop/cop/security/yaml_load.rb +1 -0
  108. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
  109. data/lib/rubocop/cop/style/alias.rb +1 -0
  110. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
  111. data/lib/rubocop/cop/style/array_coercion.rb +2 -0
  112. data/lib/rubocop/cop/style/array_join.rb +1 -0
  113. data/lib/rubocop/cop/style/attr.rb +1 -0
  114. data/lib/rubocop/cop/style/case_equality.rb +2 -1
  115. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -0
  116. data/lib/rubocop/cop/style/collection_compact.rb +2 -0
  117. data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
  118. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  119. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
  120. data/lib/rubocop/cop/style/constant_visibility.rb +1 -0
  121. data/lib/rubocop/cop/style/date_time.rb +3 -0
  122. data/lib/rubocop/cop/style/dir.rb +1 -0
  123. data/lib/rubocop/cop/style/documentation.rb +5 -0
  124. data/lib/rubocop/cop/style/documentation_method.rb +1 -0
  125. data/lib/rubocop/cop/style/double_negation.rb +1 -0
  126. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
  127. data/lib/rubocop/cop/style/each_with_object.rb +1 -0
  128. data/lib/rubocop/cop/style/empty_literal.rb +9 -0
  129. data/lib/rubocop/cop/style/endless_method.rb +1 -0
  130. data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
  131. data/lib/rubocop/cop/style/even_odd.rb +1 -0
  132. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
  133. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -0
  134. data/lib/rubocop/cop/style/float_division.rb +4 -0
  135. data/lib/rubocop/cop/style/format_string.rb +2 -0
  136. data/lib/rubocop/cop/style/format_string_token.rb +1 -0
  137. data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
  138. data/lib/rubocop/cop/style/hash_conversion.rb +26 -2
  139. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
  140. data/lib/rubocop/cop/style/hash_except.rb +1 -0
  141. data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
  142. data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
  143. data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
  144. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
  145. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
  146. data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
  147. data/lib/rubocop/cop/style/min_max.rb +1 -0
  148. data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
  149. data/lib/rubocop/cop/style/module_function.rb +5 -0
  150. data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
  151. data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
  152. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -0
  153. data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
  154. data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
  155. data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
  156. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -0
  157. data/lib/rubocop/cop/style/option_hash.rb +1 -0
  158. data/lib/rubocop/cop/style/or_assignment.rb +2 -0
  159. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
  160. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
  161. data/lib/rubocop/cop/style/proc.rb +1 -0
  162. data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
  163. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
  164. data/lib/rubocop/cop/style/redundant_begin.rb +7 -1
  165. data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
  166. data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
  167. data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
  168. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
  169. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
  170. data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
  171. data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
  172. data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
  173. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
  174. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  175. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
  176. data/lib/rubocop/cop/style/return_nil.rb +6 -0
  177. data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
  178. data/lib/rubocop/cop/style/sample.rb +1 -0
  179. data/lib/rubocop/cop/style/signal_exception.rb +3 -0
  180. data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
  181. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
  182. data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
  183. data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
  184. data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
  185. data/lib/rubocop/cop/style/strip.rb +1 -0
  186. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -0
  187. data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
  188. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
  189. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -0
  190. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
  191. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
  192. data/lib/rubocop/cop/style/unless_logical_operators.rb +99 -0
  193. data/lib/rubocop/cop/style/unpack_first.rb +1 -0
  194. data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
  195. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
  196. data/lib/rubocop/name_similarity.rb +1 -1
  197. data/lib/rubocop/target_ruby.rb +21 -13
  198. data/lib/rubocop/version.rb +1 -1
  199. metadata +9 -7
@@ -15,7 +15,7 @@ module RuboCop
15
15
  end
16
16
 
17
17
  def delimiters
18
- preferred_delimiters[type].split(//)
18
+ preferred_delimiters[type].split('')
19
19
  end
20
20
 
21
21
  private
@@ -8,6 +8,7 @@ module RuboCop
8
8
 
9
9
  private
10
10
 
11
+ # @!method rational_literal?(node)
11
12
  def_node_matcher :rational_literal?, <<~PATTERN
12
13
  (send
13
14
  (int _) :/
@@ -10,8 +10,13 @@ module RuboCop
10
10
 
11
11
  private
12
12
 
13
+ # @!method empty_condition?(node)
13
14
  def_node_matcher :empty_condition?, '(begin)'
15
+
16
+ # @!method setter_method?(node)
14
17
  def_node_matcher :setter_method?, '[(send ...) setter_method?]'
18
+
19
+ # @!method safe_assignment?(node)
15
20
  def_node_matcher :safe_assignment?,
16
21
  '(begin {equals_asgn? #setter_method?})'
17
22
 
@@ -28,6 +28,7 @@ module RuboCop
28
28
  end || right.last
29
29
  end
30
30
 
31
+ # @!method visibility_block?(node)
31
32
  def_node_matcher :visibility_block?, <<~PATTERN
32
33
  (send nil? { :private :protected :public })
33
34
  PATTERN
@@ -22,6 +22,7 @@ module RuboCop
22
22
  OP_LIKE_METHODS = %i[eql? equal?].freeze
23
23
  EXCLUDED = %i[+@ -@ [] []= << === ` =~].freeze
24
24
 
25
+ # @!method op_method_candidate?(node)
25
26
  def_node_matcher :op_method_candidate?, <<~PATTERN
26
27
  (def [#op_method? $_] (args $(arg [!:other !:_other])) _)
27
28
  PATTERN
@@ -23,6 +23,7 @@ module RuboCop
23
23
  # than just standard ASCII characters
24
24
  SNAKE_CASE = /^[[:digit:][:upper:]_]+$/.freeze
25
25
 
26
+ # @!method class_or_struct_return_method?(node)
26
27
  def_node_matcher :class_or_struct_return_method?, <<~PATTERN
27
28
  (send
28
29
  (const _ {:Class :Struct}) :new
@@ -64,6 +65,7 @@ module RuboCop
64
65
  (node.receiver.nil? || !literal_receiver?(node))
65
66
  end
66
67
 
68
+ # @!method literal_receiver?(node)
67
69
  def_node_matcher :literal_receiver?, <<~PATTERN
68
70
  {(send literal? ...)
69
71
  (send (begin literal?) ...)}
@@ -148,6 +148,7 @@ module RuboCop
148
148
  'with `_`. Use `@%<suggested_var>s` instead.'
149
149
  DYNAMIC_DEFINE_METHODS = %i[define_method define_singleton_method].to_set.freeze
150
150
 
151
+ # @!method method_definition?(node)
151
152
  def_node_matcher :method_definition?, <<~PATTERN
152
153
  ${
153
154
  (block (send _ %DYNAMIC_DEFINE_METHODS ({sym str} $_)) ...)
@@ -179,6 +180,7 @@ module RuboCop
179
180
  end
180
181
  # rubocop:enable Metrics/AbcSize
181
182
 
183
+ # @!method defined_memoized?(node, ivar)
182
184
  def_node_matcher :defined_memoized?, <<~PATTERN
183
185
  (begin
184
186
  (if (defined $(ivar %1)) (return $(ivar %1)) nil?)
@@ -35,7 +35,10 @@ module RuboCop
35
35
 
36
36
  MSG = 'Use %<style>s for method names.'
37
37
 
38
+ # @!method sym_name(node)
38
39
  def_node_matcher :sym_name, '(sym $_name)'
40
+
41
+ # @!method str_name(node)
39
42
  def_node_matcher :str_name, '(str $_name)'
40
43
 
41
44
  def on_send(node)
@@ -30,6 +30,7 @@ module RuboCop
30
30
  class PredicateName < Base
31
31
  include AllowedMethods
32
32
 
33
+ # @!method dynamic_method_define(node)
33
34
  def_node_matcher :dynamic_method_define, <<~PATTERN
34
35
  (send nil? #method_definition_macros
35
36
  (sym $_)
@@ -15,6 +15,7 @@ module RuboCop
15
15
  MSG = 'The use of `eval` is a serious security risk.'
16
16
  RESTRICT_ON_SEND = %i[eval].freeze
17
17
 
18
+ # @!method eval?(node)
18
19
  def_node_matcher :eval?, <<~PATTERN
19
20
  (send {nil? (send nil? :binding)} :eval $!str ...)
20
21
  PATTERN
@@ -28,6 +28,7 @@ module RuboCop
28
28
  MSG = 'Prefer `JSON.parse` over `JSON.%<method>s`.'
29
29
  RESTRICT_ON_SEND = %i[load restore].freeze
30
30
 
31
+ # @!method json_load(node)
31
32
  def_node_matcher :json_load, <<~PATTERN
32
33
  (send (const {nil? cbase} :JSON) ${:load :restore} ...)
33
34
  PATTERN
@@ -22,6 +22,7 @@ module RuboCop
22
22
  MSG = 'Avoid using `Marshal.%<method>s`.'
23
23
  RESTRICT_ON_SEND = %i[load restore].freeze
24
24
 
25
+ # @!method marshal_load(node)
25
26
  def_node_matcher :marshal_load, <<~PATTERN
26
27
  (send (const {nil? cbase} :Marshal) ${:load :restore}
27
28
  !(send (const {nil? cbase} :Marshal) :dump ...))
@@ -24,6 +24,7 @@ module RuboCop
24
24
  MSG = 'The use of `%<receiver>sopen` is a serious security risk.'
25
25
  RESTRICT_ON_SEND = %i[open].freeze
26
26
 
27
+ # @!method open?(node)
27
28
  def_node_matcher :open?, <<~PATTERN
28
29
  (send ${nil? (const {nil? cbase} :URI)} :open $!str ...)
29
30
  PATTERN
@@ -21,6 +21,7 @@ module RuboCop
21
21
  MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'
22
22
  RESTRICT_ON_SEND = %i[load].freeze
23
23
 
24
+ # @!method yaml_load(node)
24
25
  def_node_matcher :yaml_load, <<~PATTERN
25
26
  (send (const {nil? cbase} :YAML) :load ...)
26
27
  PATTERN
@@ -77,6 +77,7 @@ module RuboCop
77
77
 
78
78
  RESTRICT_ON_SEND = %i[private protected public module_function].freeze
79
79
 
80
+ # @!method access_modifier_with_symbol?(node)
80
81
  def_node_matcher :access_modifier_with_symbol?, <<~PATTERN
81
82
  (send nil? {:private :protected :public} (sym _))
82
83
  PATTERN
@@ -145,6 +145,7 @@ module RuboCop
145
145
  corrector.replace(node.old_identifier, node.old_identifier.source[1..-1])
146
146
  end
147
147
 
148
+ # @!method identifier(node)
148
149
  def_node_matcher :identifier, <<~PATTERN
149
150
  (sym $_)
150
151
  PATTERN
@@ -47,14 +47,17 @@ module RuboCop
47
47
 
48
48
  MSG = 'Use arguments forwarding.'
49
49
 
50
+ # @!method use_rest_arguments?(node)
50
51
  def_node_matcher :use_rest_arguments?, <<~PATTERN
51
52
  (args (restarg $_) $...)
52
53
  PATTERN
53
54
 
55
+ # @!method only_rest_arguments?(node, name)
54
56
  def_node_matcher :only_rest_arguments?, <<~PATTERN
55
57
  (send _ _ (splat (lvar %1)))
56
58
  PATTERN
57
59
 
60
+ # @!method forwarding_method_arguments?(node, rest_name, block_name, kwargs_name)
58
61
  def_node_matcher :forwarding_method_arguments?, <<~PATTERN
59
62
  {
60
63
  (send _ _
@@ -26,10 +26,12 @@ module RuboCop
26
26
  SPLAT_MSG = 'Use `Array(%<arg>s)` instead of `[*%<arg>s]`.'
27
27
  CHECK_MSG = 'Use `Array(%<arg>s)` instead of explicit `Array` check.'
28
28
 
29
+ # @!method array_splat?(node)
29
30
  def_node_matcher :array_splat?, <<~PATTERN
30
31
  (array (splat $_))
31
32
  PATTERN
32
33
 
34
+ # @!method unless_array?(node)
33
35
  def_node_matcher :unless_array?, <<~PATTERN
34
36
  (if
35
37
  (send
@@ -23,6 +23,7 @@ module RuboCop
23
23
  MSG = 'Favor `Array#join` over `Array#*`.'
24
24
  RESTRICT_ON_SEND = %i[*].freeze
25
25
 
26
+ # @!method join_candidate?(node)
26
27
  def_node_matcher :join_candidate?, '(send $array :* $str)'
27
28
 
28
29
  def on_send(node)
@@ -62,6 +62,7 @@ module RuboCop
62
62
  end
63
63
  end
64
64
 
65
+ # @!method class_eval?(node)
65
66
  def_node_matcher :class_eval?, <<~PATTERN
66
67
  (block (send _ {:class_eval :module_eval}) ...)
67
68
  PATTERN
@@ -35,6 +35,7 @@ module RuboCop
35
35
  MSG = 'Avoid the use of the case equality operator `===`.'
36
36
  RESTRICT_ON_SEND = %i[===].freeze
37
37
 
38
+ # @!method case_equality?(node)
38
39
  def_node_matcher :case_equality?, '(send $#const? :=== $_)'
39
40
 
40
41
  def on_send(node)
@@ -64,7 +65,7 @@ module RuboCop
64
65
  # The automatic correction from `a === b` to `a.match?(b)` needs to
65
66
  # consider `Regexp.last_match?`, `$~`, `$1`, and etc.
66
67
  # This correction is expected to be supported by `Performance/Regexp` cop.
67
- # See: https://github.com/rubocop-hq/rubocop-performance/issues/152
68
+ # See: https://github.com/rubocop/rubocop-performance/issues/152
68
69
  #
69
70
  # So here is noop.
70
71
  when :begin
@@ -25,6 +25,7 @@ module RuboCop
25
25
 
26
26
  RESTRICT_ON_SEND = %i[== equal? eql?].freeze
27
27
 
28
+ # @!method class_comparison_candidate?(node)
28
29
  def_node_matcher :class_comparison_candidate?, <<~PATTERN
29
30
  (send
30
31
  {$(send _ :class) (send $(send _ :class) :name)}
@@ -35,6 +35,7 @@ module RuboCop
35
35
 
36
36
  RESTRICT_ON_SEND = %i[reject reject! select select!].freeze
37
37
 
38
+ # @!method reject_method?(node)
38
39
  def_node_matcher :reject_method?, <<~PATTERN
39
40
  (block
40
41
  (send
@@ -44,6 +45,7 @@ module RuboCop
44
45
  $(lvar _) :nil?))
45
46
  PATTERN
46
47
 
48
+ # @!method select_method?(node)
47
49
  def_node_matcher :select_method?, <<~PATTERN
48
50
  (block
49
51
  (send
@@ -22,6 +22,7 @@ module RuboCop
22
22
 
23
23
  MSG = 'Do not use `::` for method calls.'
24
24
 
25
+ # @!method java_type_node?(node)
25
26
  def_node_matcher :java_type_node?, <<~PATTERN
26
27
  (send
27
28
  (const nil? :Java) _)
@@ -165,7 +165,7 @@ module RuboCop
165
165
  end
166
166
 
167
167
  def preferred_delimiter
168
- (command_delimiter || default_delimiter).split(//)
168
+ (command_delimiter || default_delimiter).split('')
169
169
  end
170
170
 
171
171
  def command_delimiter
@@ -231,6 +231,7 @@ module RuboCop
231
231
 
232
232
  # The shovel operator `<<` does not have its own type. It is a `send`
233
233
  # type.
234
+ # @!method assignment_type?(node)
234
235
  def_node_matcher :assignment_type?, <<~PATTERN
235
236
  {
236
237
  #{ASSIGNMENT_TYPES.join(' ')}
@@ -300,6 +301,7 @@ module RuboCop
300
301
  style == :assign_inside_condition && assignment_rhs_exist?(node)
301
302
  end
302
303
 
304
+ # @!method candidate_condition?(node)
303
305
  def_node_matcher :candidate_condition?, '[{if case} !#allowed_ternary?]'
304
306
 
305
307
  def allowed_ternary?(assignment)
@@ -92,6 +92,7 @@ module RuboCop
92
92
  end
93
93
  end
94
94
 
95
+ # @!method visibility_declaration_for?(node, const_name)
95
96
  def_node_matcher :visibility_declaration_for?, <<~PATTERN
96
97
  (send nil? {:public_constant :private_constant} ({sym str} #match_name?(%1)))
97
98
  PATTERN
@@ -47,14 +47,17 @@ module RuboCop
47
47
  CLASS_MSG = 'Prefer Time over DateTime.'
48
48
  COERCION_MSG = 'Do not use #to_datetime.'
49
49
 
50
+ # @!method date_time?(node)
50
51
  def_node_matcher :date_time?, <<~PATTERN
51
52
  (send (const {nil? (cbase)} :DateTime) ...)
52
53
  PATTERN
53
54
 
55
+ # @!method historic_date?(node)
54
56
  def_node_matcher :historic_date?, <<~PATTERN
55
57
  (send _ _ _ (const (const {nil? (cbase)} :Date) _))
56
58
  PATTERN
57
59
 
60
+ # @!method to_datetime?(node)
58
61
  def_node_matcher :to_datetime?, <<~PATTERN
59
62
  (send _ :to_datetime)
60
63
  PATTERN
@@ -22,6 +22,7 @@ module RuboCop
22
22
  MSG = "Use `__dir__` to get an absolute path to the current file's directory."
23
23
  RESTRICT_ON_SEND = %i[expand_path dirname].freeze
24
24
 
25
+ # @!method dir_replacement?(node)
25
26
  def_node_matcher :dir_replacement?, <<~PATTERN
26
27
  {(send (const {nil? cbase} :File) :expand_path (send (const {nil? cbase} :File) :dirname #file_keyword?))
27
28
  (send (const {nil? cbase} :File) :dirname (send (const {nil? cbase} :File) :realpath #file_keyword?))}
@@ -65,8 +65,13 @@ module RuboCop
65
65
 
66
66
  MSG = 'Missing top-level %<type>s documentation comment.'
67
67
 
68
+ # @!method constant_definition?(node)
68
69
  def_node_matcher :constant_definition?, '{class module casgn}'
70
+
71
+ # @!method outer_module(node)
69
72
  def_node_search :outer_module, '(const (const nil? _) _)'
73
+
74
+ # @!method constant_visibility_declaration?(node)
70
75
  def_node_matcher :constant_visibility_declaration?, <<~PATTERN
71
76
  (send nil? {:public_constant :private_constant} ({sym str} _))
72
77
  PATTERN
@@ -97,6 +97,7 @@ module RuboCop
97
97
 
98
98
  MSG = 'Missing method documentation comment.'
99
99
 
100
+ # @!method module_function_node?(node)
100
101
  def_node_matcher :module_function_node?, <<~PATTERN
101
102
  (send nil? :module_function ...)
102
103
  PATTERN
@@ -39,6 +39,7 @@ module RuboCop
39
39
  MSG = 'Avoid the use of double negation (`!!`).'
40
40
  RESTRICT_ON_SEND = %i[!].freeze
41
41
 
42
+ # @!method double_negative?(node)
42
43
  def_node_matcher :double_negative?, '(send (send _ :!) :!)'
43
44
 
44
45
  def on_send(node)
@@ -46,6 +46,7 @@ module RuboCop
46
46
 
47
47
  private
48
48
 
49
+ # @!method offending_each_range(node)
49
50
  def_node_matcher :offending_each_range, <<~PATTERN
50
51
  (block (send (begin (${irange erange} (int $_) (int $_))) :each) (args) ...)
51
52
  PATTERN
@@ -23,6 +23,7 @@ module RuboCop
23
23
  MSG = 'Use `each_with_object` instead of `%<method>s`.'
24
24
  METHODS = %i[inject reduce].freeze
25
25
 
26
+ # @!method each_with_object_candidate?(node)
26
27
  def_node_matcher :each_with_object_candidate?, <<~PATTERN
27
28
  (block $(send _ {:inject :reduce} _) $_ $_)
28
29
  PATTERN
@@ -27,11 +27,20 @@ module RuboCop
27
27
 
28
28
  RESTRICT_ON_SEND = %i[new].freeze
29
29
 
30
+ # @!method array_node(node)
30
31
  def_node_matcher :array_node, '(send (const {nil? cbase} :Array) :new)'
32
+
33
+ # @!method hash_node(node)
31
34
  def_node_matcher :hash_node, '(send (const {nil? cbase} :Hash) :new)'
35
+
36
+ # @!method str_node(node)
32
37
  def_node_matcher :str_node, '(send (const {nil? cbase} :String) :new)'
38
+
39
+ # @!method array_with_block(node)
33
40
  def_node_matcher :array_with_block,
34
41
  '(block (send (const {nil? cbase} :Array) :new) args _)'
42
+
43
+ # @!method hash_with_block(node)
35
44
  def_node_matcher :hash_with_block, <<~PATTERN
36
45
  {
37
46
  (block (send (const {nil? cbase} :Hash) :new) args _)
@@ -11,6 +11,7 @@ module RuboCop
11
11
  # Other method definition types are not considered by this cop.
12
12
  #
13
13
  # The supported styles are:
14
+ #
14
15
  # * allow_single_line (default) - only single line endless method definitions are allowed.
15
16
  # * allow_always - all endless method definitions are allowed.
16
17
  # * disallow - all endless method definitions are disallowed.
@@ -65,10 +65,12 @@ module RuboCop
65
65
 
66
66
  RESTRICT_ON_SEND = %i[eval class_eval module_eval instance_eval].freeze
67
67
 
68
+ # @!method valid_eval_receiver?(node)
68
69
  def_node_matcher :valid_eval_receiver?, <<~PATTERN
69
70
  { nil? (const {nil? cbase} :Kernel) }
70
71
  PATTERN
71
72
 
73
+ # @!method line_with_offset?(node, sign, num)
72
74
  def_node_matcher :line_with_offset?, <<~PATTERN
73
75
  {
74
76
  (send #special_line_keyword? %1 (int %2))
@@ -21,6 +21,7 @@ module RuboCop
21
21
  MSG = 'Replace with `Integer#%<method>s?`.'
22
22
  RESTRICT_ON_SEND = %i[== !=].freeze
23
23
 
24
+ # @!method even_odd_candidate?(node)
24
25
  def_node_matcher :even_odd_candidate?, <<~PATTERN
25
26
  (send
26
27
  {(send $_ :% (int 2))