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
@@ -19,6 +19,7 @@ module RuboCop
19
19
  MSG = 'Use `#%<type>s_type?` to check node type.'
20
20
  RESTRICT_ON_SEND = %i[==].freeze
21
21
 
22
+ # @!method node_type_check(node)
22
23
  def_node_matcher :node_type_check, <<~PATTERN
23
24
  (send (send $_ :type) :== (sym $_))
24
25
  PATTERN
@@ -34,10 +34,12 @@ module RuboCop
34
34
 
35
35
  private
36
36
 
37
+ # @!method node_type_check(node)
37
38
  def_node_matcher :node_type_check, <<~PATTERN
38
39
  (send nil? :add_offense $_node $hash)
39
40
  PATTERN
40
41
 
42
+ # @!method offending_location_argument(node)
41
43
  def_node_matcher :offending_location_argument, <<~PATTERN
42
44
  (pair (sym :location) $(send (send $_node :loc) $_keyword))
43
45
  PATTERN
@@ -21,6 +21,7 @@ module RuboCop
21
21
 
22
22
  MSG = 'Remove the redundant `subject`%<additional_message>s.'
23
23
 
24
+ # @!method described_class_subject?(node)
24
25
  def_node_matcher :described_class_subject?, <<~PATTERN
25
26
  (block
26
27
  (send nil? :subject
@@ -25,6 +25,7 @@ module RuboCop
25
25
 
26
26
  MSG = 'Remove `let` that is `RuboCop::Config.new` with no arguments%<additional_message>s.'
27
27
 
28
+ # @!method let_rubocop_config_new?(node)
28
29
  def_node_matcher :let_rubocop_config_new?, <<~PATTERN
29
30
  (block
30
31
  (send nil? :let
@@ -23,6 +23,7 @@ module RuboCop
23
23
  MSG = 'Redundant location argument to `#add_offense`.'
24
24
  RESTRICT_ON_SEND = %i[add_offense].freeze
25
25
 
26
+ # @!method redundant_location_argument(node)
26
27
  def_node_matcher :redundant_location_argument, <<~PATTERN
27
28
  (send nil? :add_offense _
28
29
  (hash <$(pair (sym :location) (sym :expression)) ...>)
@@ -26,16 +26,19 @@ module RuboCop
26
26
  MSG = 'Redundant message argument to `#add_offense`.'
27
27
  RESTRICT_ON_SEND = %i[add_offense].freeze
28
28
 
29
+ # @!method node_type_check(node)
29
30
  def_node_matcher :node_type_check, <<~PATTERN
30
31
  (send nil? :add_offense $_node $hash)
31
32
  PATTERN
32
33
 
34
+ # @!method redundant_message_argument(node)
33
35
  def_node_matcher :redundant_message_argument, <<~PATTERN
34
36
  (pair
35
37
  (sym :message)
36
38
  ${(const nil? :MSG) (send nil? :message) (send nil? :message _)})
37
39
  PATTERN
38
40
 
41
+ # @!method message_method_call(node)
39
42
  def_node_matcher :message_method_call, '(send nil? :message $_node)'
40
43
 
41
44
  def on_send(node)
@@ -67,18 +67,22 @@ module RuboCop
67
67
  no_acceptable_style! style_detected
68
68
  ].freeze
69
69
 
70
+ # @!method correct_style_detected_check(node)
70
71
  def_node_matcher :correct_style_detected_check, <<~PATTERN
71
72
  (send nil? :correct_style_detected)
72
73
  PATTERN
73
74
 
75
+ # @!method negative_style_detected_method_check(node)
74
76
  def_node_matcher :negative_style_detected_method_check, <<~PATTERN
75
77
  (send nil? /(?:opposite|unexpected|ambiguous|unrecognized)_style_detected|conflicting_styles_detected/ ...)
76
78
  PATTERN
77
79
 
80
+ # @!method no_acceptable_style_check(node)
78
81
  def_node_matcher :no_acceptable_style_check, <<~PATTERN
79
82
  (send nil? :no_acceptable_style!)
80
83
  PATTERN
81
84
 
85
+ # @!method style_detected_check(node)
82
86
  def_node_matcher :style_detected_check, <<~PATTERN
83
87
  (send nil? :style_detected ...)
84
88
  PATTERN
@@ -16,10 +16,12 @@ module RuboCop
16
16
  class UselessMessageAssertion < Base
17
17
  MSG = 'Do not specify cop behavior using `described_class::MSG`.'
18
18
 
19
+ # @!method described_class_msg(node)
19
20
  def_node_search :described_class_msg, <<~PATTERN
20
21
  (const (send nil? :described_class) :MSG)
21
22
  PATTERN
22
23
 
24
+ # @!method rspec_expectation_on_msg?(node)
23
25
  def_node_matcher :rspec_expectation_on_msg?, <<~PATTERN
24
26
  (send (send nil? :expect #contains_described_class_msg?) :to ...)
25
27
  PATTERN
@@ -68,6 +68,7 @@ module RuboCop
68
68
 
69
69
  MSG = '%<current>s is not aligned with %<prefer>s%<alt_prefer>s.'
70
70
 
71
+ # @!method block_end_align_target?(node, child)
71
72
  def_node_matcher :block_end_align_target?, <<~PATTERN
72
73
  {assignment?
73
74
  splat
@@ -147,6 +147,7 @@ module RuboCop
147
147
  MSG = '`%<category>s` is supposed to appear before ' \
148
148
  '`%<previous>s`.'
149
149
 
150
+ # @!method dynamic_constant?(node)
150
151
  def_node_matcher :dynamic_constant?, <<~PATTERN
151
152
  (casgn nil? _ (send ...))
152
153
  PATTERN
@@ -11,12 +11,12 @@ module RuboCop
11
11
  # name = "RuboCop"
12
12
  # # Some comment and an empty line
13
13
  #
14
- # website += "/rubocop-hq/rubocop" unless cond
14
+ # website += "/rubocop/rubocop" unless cond
15
15
  # puts "rubocop" if debug
16
16
  #
17
17
  # # bad for any configuration
18
18
  # set_app("RuboCop")
19
- # website = "https://github.com/rubocop-hq/rubocop"
19
+ # website = "https://github.com/rubocop/rubocop"
20
20
  #
21
21
  # # good only if AllowBeforeTrailingComments is true
22
22
  # object.method(arg) # this is a comment
@@ -153,7 +153,7 @@ module RuboCop
153
153
 
154
154
  def on_send(node)
155
155
  return if style != :consistent && enforce_first_argument_with_fixed_indentation?
156
- return if !node.arguments? || node.operator_method?
156
+ return if !node.arguments? || bare_operator?(node)
157
157
 
158
158
  indent = base_indentation(node) + configured_indentation_width
159
159
 
@@ -167,6 +167,10 @@ module RuboCop
167
167
 
168
168
  private
169
169
 
170
+ def bare_operator?(node)
171
+ node.operator_method? && !node.dot?
172
+ end
173
+
170
174
  def message(arg_node)
171
175
  return 'Bad indentation of the first argument.' unless arg_node
172
176
 
@@ -206,6 +210,7 @@ module RuboCop
206
210
  node.source_range.begin_pos > parent.source_range.begin_pos
207
211
  end
208
212
 
213
+ # @!method eligible_method_call?(node)
209
214
  def_node_matcher :eligible_method_call?, <<~PATTERN
210
215
  (send _ !:[]= ...)
211
216
  PATTERN
@@ -52,6 +52,7 @@ module RuboCop
52
52
  MSG = 'Use %<configured_indentation_width>d (not %<indentation>d) ' \
53
53
  'spaces for%<name>s indentation.'
54
54
 
55
+ # @!method access_modifier?(node)
55
56
  def_node_matcher :access_modifier?, <<~PATTERN
56
57
  [(send ...) access_modifier?]
57
58
  PATTERN
@@ -61,7 +61,7 @@ module RuboCop
61
61
  # by `EnforcedStyle: line_count_based` of `Style/BlockDelimiters` cop.
62
62
  # That means preventing auto-correction to incorrect auto-corrected
63
63
  # code.
64
- # See: https://github.com/rubocop-hq/rubocop/issues/7534
64
+ # See: https://github.com/rubocop/rubocop/issues/7534
65
65
  return if conflict_with_block_delimiters?(node)
66
66
 
67
67
  left_brace = node.loc.begin
@@ -89,7 +89,7 @@ module RuboCop
89
89
  # preventing auto-correction to single-line empty braces. It will
90
90
  # conflict with auto-correction by `Layout/SpaceInsideBlockBraces` cop
91
91
  # if auto-corrected to a single-line empty braces.
92
- # See: https://github.com/rubocop-hq/rubocop/issues/7363
92
+ # See: https://github.com/rubocop/rubocop/issues/7363
93
93
  return if node.body.nil? && node.multiline?
94
94
 
95
95
  left_brace = node.loc.begin
@@ -21,6 +21,7 @@ module RuboCop
21
21
  'Use `%<double_colon>sBigDecimal()` instead.'
22
22
  RESTRICT_ON_SEND = %i[new].freeze
23
23
 
24
+ # @!method big_decimal_new(node)
24
25
  def_node_matcher :big_decimal_new, <<~PATTERN
25
26
  (send
26
27
  (const ${nil? cbase} :BigDecimal) :new ...)
@@ -27,6 +27,7 @@ module RuboCop
27
27
  MSG = 'Symbol with a boolean name - ' \
28
28
  'you probably meant to use `%<boolean>s`.'
29
29
 
30
+ # @!method boolean_symbol?(node)
30
31
  def_node_matcher :boolean_symbol?, '(sym {:true :false})'
31
32
 
32
33
  def on_sym(node)
@@ -66,10 +66,12 @@ module RuboCop
66
66
 
67
67
  MSG = 'Do not define constants this way within a block.'
68
68
 
69
+ # @!method constant_assigned_in_block?(node)
69
70
  def_node_matcher :constant_assigned_in_block?, <<~PATTERN
70
71
  ({^block_type? [^begin_type? ^^block_type?]} nil? ...)
71
72
  PATTERN
72
73
 
74
+ # @!method module_defined_in_block?(node)
73
75
  def_node_matcher :module_defined_in_block?, <<~PATTERN
74
76
  ({^block_type? [^begin_type? ^^block_type?]} ...)
75
77
  PATTERN
@@ -58,6 +58,7 @@ module RuboCop
58
58
  class ConstantResolution < Base
59
59
  MSG = 'Fully qualify this constant to avoid possibly ambiguous resolution.'
60
60
 
61
+ # @!method unqualified_const?(node)
61
62
  def_node_matcher :unqualified_const?, <<~PATTERN
62
63
  (const nil? #const_name?)
63
64
  PATTERN
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # ----
17
17
  # Lint/Debugger:
18
18
  # WebConsole: ~
19
- # ---
19
+ # ----
20
20
  #
21
21
  #
22
22
  # @example
@@ -59,10 +59,12 @@ module RuboCop
59
59
 
60
60
  RESTRICT_ON_SEND = [].freeze
61
61
 
62
+ # @!method kernel?(node)
62
63
  def_node_matcher :kernel?, <<~PATTERN
63
64
  (const {nil? cbase} :Kernel)
64
65
  PATTERN
65
66
 
67
+ # @!method valid_receiver?(node, arg1)
66
68
  def_node_matcher :valid_receiver?, <<~PATTERN
67
69
  {
68
70
  (const {nil? cbase} %1)
@@ -46,6 +46,7 @@ module RuboCop
46
46
 
47
47
  NO_ARG_ALGORITHM = %w[BF DES IDEA RC4].freeze
48
48
 
49
+ # @!method algorithm_const(node)
49
50
  def_node_matcher :algorithm_const, <<~PATTERN
50
51
  (send
51
52
  $(const
@@ -74,7 +74,7 @@ module RuboCop
74
74
  # else 250
75
75
  # end
76
76
  #
77
- # @example IgnoreLiteralBranches: true
77
+ # @example IgnoreConstantBranches: true
78
78
  # # good
79
79
  # case size
80
80
  # when "small" then SMALL_SIZE
@@ -82,6 +82,7 @@ module RuboCop
82
82
  end
83
83
  end
84
84
 
85
+ # @!method method_alias?(node)
85
86
  def_node_matcher :method_alias?, <<~PATTERN
86
87
  (alias (sym $_name) sym)
87
88
  PATTERN
@@ -94,10 +95,12 @@ module RuboCop
94
95
  found_instance_method(node, name)
95
96
  end
96
97
 
98
+ # @!method alias_method?(node)
97
99
  def_node_matcher :alias_method?, <<~PATTERN
98
100
  (send nil? :alias_method (sym $_name) _)
99
101
  PATTERN
100
102
 
103
+ # @!method sym_name(node)
101
104
  def_node_matcher :sym_name, '(sym $_name)'
102
105
  def on_send(node)
103
106
  if (name = alias_method?(node))
@@ -24,6 +24,7 @@ module RuboCop
24
24
  REQUIRE_METHODS = Set.new(%i[require require_relative]).freeze
25
25
  RESTRICT_ON_SEND = REQUIRE_METHODS
26
26
 
27
+ # @!method require_call?(node)
27
28
  def_node_matcher :require_call?, <<~PATTERN
28
29
  (send {nil? (const _ :Kernel)} %REQUIRE_METHODS _)
29
30
  PATTERN
@@ -25,6 +25,7 @@ module RuboCop
25
25
  MSG = 'The argument to each_with_object cannot be immutable.'
26
26
  RESTRICT_ON_SEND = %i[each_with_object].freeze
27
27
 
28
+ # @!method each_with_object?(node)
28
29
  def_node_matcher :each_with_object?, <<~PATTERN
29
30
  ({send csend} _ :each_with_object $_)
30
31
  PATTERN
@@ -80,6 +80,7 @@ module RuboCop
80
80
 
81
81
  RESTRICT_ON_SEND = %i[new].freeze
82
82
 
83
+ # @!method erb_new_with_non_keyword_arguments(node)
83
84
  def_node_matcher :erb_new_with_non_keyword_arguments, <<~PATTERN
84
85
  (send
85
86
  (const {nil? cbase} :ERB) :new $...)
@@ -92,6 +92,7 @@ module RuboCop
92
92
  end
93
93
  end
94
94
 
95
+ # @!method called_on_string?(node)
95
96
  def_node_matcher :called_on_string?, <<~PATTERN
96
97
  {(send {nil? const_type?} _ (str _) ...)
97
98
  (send (str ...) ...)}
@@ -24,6 +24,7 @@ module RuboCop
24
24
 
25
25
  MSG = 'Use `Hash#compare_by_identity` instead of using `object_id` for keys.'
26
26
 
27
+ # @!method id_as_hash_key?(node)
27
28
  def_node_matcher :id_as_hash_key?, <<~PATTERN
28
29
  (send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
29
30
  PATTERN
@@ -53,6 +53,7 @@ module RuboCop
53
53
  ALTERNATIVE_PROTECTED = '`protected` inside a `class << self` ' \
54
54
  'block'
55
55
 
56
+ # @!method private_class_methods(node)
56
57
  def_node_search :private_class_methods, <<~PATTERN
57
58
  (send nil? :private_class_method $...)
58
59
  PATTERN
@@ -58,6 +58,7 @@ module RuboCop
58
58
 
59
59
  RESTRICT_ON_SEND = %i[new].freeze
60
60
 
61
+ # @!method class_new_call?(node)
61
62
  def_node_matcher :class_new_call?, <<~PATTERN
62
63
  (send
63
64
  (const {cbase nil?} :Class) :new
@@ -25,6 +25,7 @@ module RuboCop
25
25
  SET_OPERATION_OPERATORS = %i[& | ^].freeze
26
26
  RESTRICT_ON_SEND = COMPARISON_METHODS
27
27
 
28
+ # @!method multiple_compare?(node)
28
29
  def_node_matcher :multiple_compare?, <<~PATTERN
29
30
  (send (send _ {:< :> :<= :>=} $_) {:#{COMPARISON_METHODS.join(' :')}} _)
30
31
  PATTERN
@@ -81,14 +81,17 @@ module RuboCop
81
81
  class_or_module_or_struct_new_call?(child)
82
82
  end
83
83
 
84
+ # @!method eval_call?(node)
84
85
  def_node_matcher :eval_call?, <<~PATTERN
85
86
  (block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
86
87
  PATTERN
87
88
 
89
+ # @!method exec_call?(node)
88
90
  def_node_matcher :exec_call?, <<~PATTERN
89
91
  (block (send _ {:instance_exec :class_exec :module_exec} ...) ...)
90
92
  PATTERN
91
93
 
94
+ # @!method class_or_module_or_struct_new_call?(node)
92
95
  def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
93
96
  (block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
94
97
  PATTERN
@@ -25,6 +25,7 @@ module RuboCop
25
25
  class NextWithoutAccumulator < Base
26
26
  MSG = 'Use `next` with an accumulator argument in a `reduce`.'
27
27
 
28
+ # @!method on_body_of_reduce(node)
28
29
  def_node_matcher :on_body_of_reduce, <<~PATTERN
29
30
  (block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
30
31
  PATTERN
@@ -129,32 +129,39 @@ module RuboCop
129
129
  unsorted_dir_glob_pass?(node) || unsorted_dir_each_pass?(node)
130
130
  end
131
131
 
132
+ # @!method unsorted_dir_block?(node)
132
133
  def_node_matcher :unsorted_dir_block?, <<~PATTERN
133
134
  (send (const {nil? cbase} :Dir) :glob ...)
134
135
  PATTERN
135
136
 
137
+ # @!method unsorted_dir_each?(node)
136
138
  def_node_matcher :unsorted_dir_each?, <<~PATTERN
137
139
  (send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each)
138
140
  PATTERN
139
141
 
142
+ # @!method method_require?(node)
140
143
  def_node_matcher :method_require?, <<~PATTERN
141
144
  (block-pass (send nil? :method (sym :require)))
142
145
  PATTERN
143
146
 
147
+ # @!method unsorted_dir_glob_pass?(node)
144
148
  def_node_matcher :unsorted_dir_glob_pass?, <<~PATTERN
145
149
  (send (const {nil? cbase} :Dir) :glob ...
146
150
  (block-pass (send nil? :method (sym :require))))
147
151
  PATTERN
148
152
 
153
+ # @!method unsorted_dir_each_pass?(node)
149
154
  def_node_matcher :unsorted_dir_each_pass?, <<~PATTERN
150
155
  (send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each
151
156
  (block-pass (send nil? :method (sym :require))))
152
157
  PATTERN
153
158
 
159
+ # @!method loop_variable(node)
154
160
  def_node_matcher :loop_variable, <<~PATTERN
155
161
  (args (arg $_))
156
162
  PATTERN
157
163
 
164
+ # @!method var_is_required?(node, name)
158
165
  def_node_search :var_is_required?, <<~PATTERN
159
166
  (send nil? :require (lvar %1))
160
167
  PATTERN