rubocop 0.80.1 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/config/default.yml +202 -49
  4. data/lib/rubocop.rb +20 -61
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli.rb +13 -7
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
  8. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  9. data/lib/rubocop/comment_config.rb +1 -1
  10. data/lib/rubocop/config.rb +14 -2
  11. data/lib/rubocop/config_loader.rb +37 -33
  12. data/lib/rubocop/config_loader_resolver.rb +45 -6
  13. data/lib/rubocop/config_obsoletion.rb +2 -0
  14. data/lib/rubocop/config_store.rb +12 -2
  15. data/lib/rubocop/config_validator.rb +18 -1
  16. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  17. data/lib/rubocop/cop/badge.rb +5 -5
  18. data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
  19. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  20. data/lib/rubocop/cop/commissioner.rb +0 -21
  21. data/lib/rubocop/cop/cop.rb +14 -6
  22. data/lib/rubocop/cop/corrector.rb +48 -24
  23. data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
  24. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
  25. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
  26. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +4 -4
  27. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  28. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  29. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  30. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
  31. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  32. data/lib/rubocop/cop/generator.rb +4 -3
  33. data/lib/rubocop/cop/ignored_node.rb +1 -3
  34. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
  35. data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
  36. data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
  37. data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
  38. data/lib/rubocop/cop/layout/class_structure.rb +19 -16
  39. data/lib/rubocop/cop/layout/condition_position.rb +12 -2
  40. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  41. data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
  42. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  43. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
  44. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  45. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -3
  46. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
  47. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  48. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  49. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  50. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  51. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
  52. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -9
  53. data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
  54. data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
  55. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  56. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  57. data/lib/rubocop/cop/layout/line_length.rb +23 -20
  58. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  60. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  61. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
  62. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
  63. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  64. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +131 -0
  65. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
  66. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  67. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  68. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
  69. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  70. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
  71. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
  72. data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
  73. data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
  74. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
  75. data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
  76. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  77. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
  78. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
  79. data/lib/rubocop/cop/lint/empty_when.rb +29 -6
  80. data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
  81. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -4
  82. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  83. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  84. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
  85. data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
  86. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  87. data/lib/rubocop/cop/lint/loop.rb +7 -5
  88. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +62 -0
  89. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
  90. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  91. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  92. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  93. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  94. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  95. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
  96. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
  97. data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
  98. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
  99. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  100. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  101. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  102. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  103. data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
  104. data/lib/rubocop/cop/lint/suppressed_exception.rb +23 -26
  105. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  106. data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
  107. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  108. data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
  109. data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
  110. data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
  111. data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
  112. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
  113. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  114. data/lib/rubocop/cop/migration/department_name.rb +22 -9
  115. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  116. data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
  117. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
  118. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  119. data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
  120. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
  121. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
  122. data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -2
  123. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  124. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
  125. data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
  126. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
  127. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
  128. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
  129. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  130. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  131. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
  132. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  133. data/lib/rubocop/cop/naming/constant_name.rb +2 -1
  134. data/lib/rubocop/cop/naming/file_name.rb +27 -14
  135. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  136. data/lib/rubocop/cop/naming/method_name.rb +26 -0
  137. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  138. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  139. data/lib/rubocop/cop/registry.rb +12 -7
  140. data/lib/rubocop/cop/severity.rb +1 -3
  141. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
  142. data/lib/rubocop/cop/style/alias.rb +4 -4
  143. data/lib/rubocop/cop/style/and_or.rb +7 -8
  144. data/lib/rubocop/cop/style/array_join.rb +2 -2
  145. data/lib/rubocop/cop/style/attr.rb +1 -3
  146. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  147. data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
  148. data/lib/rubocop/cop/style/case_equality.rb +24 -1
  149. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  150. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  151. data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
  152. data/lib/rubocop/cop/style/copyright.rb +3 -3
  153. data/lib/rubocop/cop/style/dir.rb +1 -1
  154. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
  155. data/lib/rubocop/cop/style/documentation.rb +43 -5
  156. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
  157. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  158. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  159. data/lib/rubocop/cop/style/each_with_object.rb +3 -3
  160. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  161. data/lib/rubocop/cop/style/empty_method.rb +2 -6
  162. data/lib/rubocop/cop/style/end_block.rb +6 -0
  163. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  164. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  165. data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
  166. data/lib/rubocop/cop/style/format_string.rb +2 -2
  167. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  168. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
  169. data/lib/rubocop/cop/style/guard_clause.rb +25 -2
  170. data/lib/rubocop/cop/style/hash_each_methods.rb +6 -4
  171. data/lib/rubocop/cop/style/hash_syntax.rb +19 -12
  172. data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
  173. data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
  174. data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
  175. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
  176. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  177. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  178. data/lib/rubocop/cop/style/lambda.rb +3 -2
  179. data/lib/rubocop/cop/style/lambda_call.rb +1 -21
  180. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  181. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  182. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  183. data/lib/rubocop/cop/style/module_function.rb +58 -12
  184. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  185. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  186. data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
  187. data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
  188. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  189. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  190. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
  191. data/lib/rubocop/cop/style/next.rb +2 -2
  192. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  193. data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
  194. data/lib/rubocop/cop/style/not.rb +1 -1
  195. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  196. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  197. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  198. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
  199. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  200. data/lib/rubocop/cop/style/or_assignment.rb +1 -1
  201. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  202. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  203. data/lib/rubocop/cop/style/proc.rb +1 -1
  204. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  205. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  206. data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
  207. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  208. data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
  209. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  210. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
  211. data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
  212. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
  213. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
  214. data/lib/rubocop/cop/style/redundant_return.rb +5 -7
  215. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  216. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  217. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  218. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  219. data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
  220. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  221. data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
  222. data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
  223. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
  224. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
  225. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  226. data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
  227. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
  228. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
  229. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
  230. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
  231. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
  232. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
  233. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  234. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  235. data/lib/rubocop/cop/style/unpack_first.rb +0 -4
  236. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  237. data/lib/rubocop/cop/style/when_then.rb +1 -1
  238. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  239. data/lib/rubocop/cop/style/word_array.rb +1 -1
  240. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
  241. data/lib/rubocop/cop/team.rb +61 -25
  242. data/lib/rubocop/cop/util.rb +25 -1
  243. data/lib/rubocop/cop/variable_force.rb +3 -9
  244. data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
  245. data/lib/rubocop/cop/variable_force/branch.rb +1 -3
  246. data/lib/rubocop/cop/variable_force/scope.rb +1 -0
  247. data/lib/rubocop/cop/variable_force/variable.rb +3 -6
  248. data/lib/rubocop/ext/processed_source.rb +18 -0
  249. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  250. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  251. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
  252. data/lib/rubocop/formatter/formatter_set.rb +1 -4
  253. data/lib/rubocop/formatter/junit_formatter.rb +27 -6
  254. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  255. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  256. data/lib/rubocop/magic_comment.rb +1 -1
  257. data/lib/rubocop/name_similarity.rb +12 -9
  258. data/lib/rubocop/options.rb +33 -12
  259. data/lib/rubocop/remote_config.rb +1 -3
  260. data/lib/rubocop/result_cache.rb +5 -7
  261. data/lib/rubocop/rspec/cop_helper.rb +3 -26
  262. data/lib/rubocop/rspec/expect_offense.rb +46 -16
  263. data/lib/rubocop/rspec/shared_contexts.rb +54 -20
  264. data/lib/rubocop/runner.rb +21 -14
  265. data/lib/rubocop/target_finder.rb +7 -7
  266. data/lib/rubocop/target_ruby.rb +5 -2
  267. data/lib/rubocop/version.rb +5 -3
  268. metadata +50 -77
  269. data/lib/rubocop/ast/builder.rb +0 -83
  270. data/lib/rubocop/ast/node.rb +0 -632
  271. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  272. data/lib/rubocop/ast/node/and_node.rb +0 -29
  273. data/lib/rubocop/ast/node/args_node.rb +0 -29
  274. data/lib/rubocop/ast/node/array_node.rb +0 -57
  275. data/lib/rubocop/ast/node/block_node.rb +0 -117
  276. data/lib/rubocop/ast/node/break_node.rb +0 -17
  277. data/lib/rubocop/ast/node/case_node.rb +0 -56
  278. data/lib/rubocop/ast/node/class_node.rb +0 -31
  279. data/lib/rubocop/ast/node/def_node.rb +0 -82
  280. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  281. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  282. data/lib/rubocop/ast/node/float_node.rb +0 -12
  283. data/lib/rubocop/ast/node/for_node.rb +0 -53
  284. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  285. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  286. data/lib/rubocop/ast/node/if_node.rb +0 -175
  287. data/lib/rubocop/ast/node/int_node.rb +0 -12
  288. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  289. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  290. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  291. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  292. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  293. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  294. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
  295. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  296. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  297. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  298. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  299. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  300. data/lib/rubocop/ast/node/module_node.rb +0 -24
  301. data/lib/rubocop/ast/node/or_node.rb +0 -29
  302. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  303. data/lib/rubocop/ast/node/range_node.rb +0 -18
  304. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  305. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  306. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  307. data/lib/rubocop/ast/node/return_node.rb +0 -24
  308. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  309. data/lib/rubocop/ast/node/send_node.rb +0 -13
  310. data/lib/rubocop/ast/node/str_node.rb +0 -16
  311. data/lib/rubocop/ast/node/super_node.rb +0 -21
  312. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  313. data/lib/rubocop/ast/node/until_node.rb +0 -35
  314. data/lib/rubocop/ast/node/when_node.rb +0 -53
  315. data/lib/rubocop/ast/node/while_node.rb +0 -35
  316. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  317. data/lib/rubocop/ast/sexp.rb +0 -16
  318. data/lib/rubocop/ast/traversal.rb +0 -200
  319. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  320. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
  321. data/lib/rubocop/node_pattern.rb +0 -887
  322. data/lib/rubocop/processed_source.rb +0 -216
  323. data/lib/rubocop/string_util.rb +0 -14
  324. data/lib/rubocop/token.rb +0 -114
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module AST
5
- # `RuboCop::AST::Builder` is an AST builder that is utilized to let `Parser`
6
- # generate ASTs with {RuboCop::AST::Node}.
7
- #
8
- # @example
9
- # buffer = Parser::Source::Buffer.new('(string)')
10
- # buffer.source = 'puts :foo'
11
- #
12
- # builder = RuboCop::AST::Builder.new
13
- # require 'parser/ruby25'
14
- # parser = Parser::Ruby25.new(builder)
15
- # root_node = parser.parse(buffer)
16
- class Builder < Parser::Builders::Default
17
- NODE_MAP = {
18
- and: AndNode,
19
- alias: AliasNode,
20
- args: ArgsNode,
21
- array: ArrayNode,
22
- block: BlockNode,
23
- break: BreakNode,
24
- case: CaseNode,
25
- class: ClassNode,
26
- def: DefNode,
27
- defined?: DefinedNode,
28
- defs: DefNode,
29
- ensure: EnsureNode,
30
- for: ForNode,
31
- forward_args: ForwardArgsNode,
32
- float: FloatNode,
33
- hash: HashNode,
34
- if: IfNode,
35
- int: IntNode,
36
- irange: RangeNode,
37
- erange: RangeNode,
38
- kwsplat: KeywordSplatNode,
39
- module: ModuleNode,
40
- or: OrNode,
41
- pair: PairNode,
42
- regexp: RegexpNode,
43
- resbody: ResbodyNode,
44
- retry: RetryNode,
45
- return: ReturnNode,
46
- csend: SendNode,
47
- send: SendNode,
48
- str: StrNode,
49
- dstr: StrNode,
50
- xstr: StrNode,
51
- sclass: SelfClassNode,
52
- super: SuperNode,
53
- zsuper: SuperNode,
54
- sym: SymbolNode,
55
- until: UntilNode,
56
- until_post: UntilNode,
57
- when: WhenNode,
58
- while: WhileNode,
59
- while_post: WhileNode,
60
- yield: YieldNode
61
- }.freeze
62
-
63
- # Generates {Node} from the given information.
64
- #
65
- # @return [Node] the generated node
66
- def n(type, children, source_map)
67
- node_klass(type).new(type, children, location: source_map)
68
- end
69
-
70
- # TODO: Figure out what to do about literal encoding handling...
71
- # More details here https://github.com/whitequark/parser/issues/283
72
- def string_value(token)
73
- value(token)
74
- end
75
-
76
- private
77
-
78
- def node_klass(type)
79
- NODE_MAP[type] || Node
80
- end
81
- end
82
- end
83
- end
@@ -1,632 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module AST
5
- # `RuboCop::AST::Node` is a subclass of `Parser::AST::Node`. It provides
6
- # access to parent nodes and an object-oriented way to traverse an AST with
7
- # the power of `Enumerable`.
8
- #
9
- # It has predicate methods for every node type, like this:
10
- #
11
- # @example
12
- # node.send_type? # Equivalent to: `node.type == :send`
13
- # node.op_asgn_type? # Equivalent to: `node.type == :op_asgn`
14
- #
15
- # # Non-word characters (other than a-zA-Z0-9_) in type names are omitted.
16
- # node.defined_type? # Equivalent to: `node.type == :defined?`
17
- #
18
- # # Find the first lvar node under the receiver node.
19
- # lvar_node = node.each_descendant.find(&:lvar_type?)
20
- #
21
- class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
22
- include RuboCop::AST::Sexp
23
- extend NodePattern::Macros
24
-
25
- # <=> isn't included here, because it doesn't return a boolean.
26
- COMPARISON_OPERATORS = %i[== === != <= >= > <].freeze
27
-
28
- TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
29
- hash regexp true irange erange complex
30
- rational regopt].freeze
31
- FALSEY_LITERALS = %i[false nil].freeze
32
- LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
33
- COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
34
- erange regexp].freeze
35
- BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
36
- MUTABLE_LITERALS = %i[str dstr xstr array hash
37
- regexp irange erange].freeze
38
- IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
39
-
40
- EQUALS_ASSIGNMENTS = %i[lvasgn ivasgn cvasgn gvasgn
41
- casgn masgn].freeze
42
- SHORTHAND_ASSIGNMENTS = %i[op_asgn or_asgn and_asgn].freeze
43
- ASSIGNMENTS = (EQUALS_ASSIGNMENTS + SHORTHAND_ASSIGNMENTS).freeze
44
-
45
- BASIC_CONDITIONALS = %i[if while until].freeze
46
- CONDITIONALS = [*BASIC_CONDITIONALS, :case].freeze
47
- VARIABLES = %i[ivar gvar cvar lvar].freeze
48
- REFERENCES = %i[nth_ref back_ref].freeze
49
- KEYWORDS = %i[alias and break case class def defs defined?
50
- kwbegin do else ensure for if module next
51
- not or postexe redo rescue retry return self
52
- super zsuper then undef until when while
53
- yield].freeze
54
- OPERATOR_KEYWORDS = %i[and or].freeze
55
- SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].freeze
56
-
57
- # @see https://www.rubydoc.info/gems/ast/AST/Node:initialize
58
- def initialize(type, children = [], properties = {})
59
- @mutable_attributes = {}
60
-
61
- # ::AST::Node#initialize freezes itself.
62
- super
63
-
64
- # #parent= may be invoked multiple times for a node because there are
65
- # pending nodes while constructing AST and they are replaced later.
66
- # For example, `lvar` and `send` type nodes are initially created as an
67
- # `ident` type node and fixed to the appropriate type later.
68
- # So, the #parent attribute needs to be mutable.
69
- each_child_node do |child_node|
70
- child_node.parent = self unless child_node.complete?
71
- end
72
- end
73
-
74
- Parser::Meta::NODE_TYPES.each do |node_type|
75
- method_name = "#{node_type.to_s.gsub(/\W/, '')}_type?"
76
- define_method(method_name) do
77
- type == node_type
78
- end
79
- end
80
-
81
- # Returns the parent node, or `nil` if the receiver is a root node.
82
- #
83
- # @return [Node, nil] the parent node or `nil`
84
- def parent
85
- @mutable_attributes[:parent]
86
- end
87
-
88
- def parent=(node)
89
- @mutable_attributes[:parent] = node
90
- end
91
-
92
- def complete!
93
- @mutable_attributes.freeze
94
- each_child_node(&:complete!)
95
- end
96
-
97
- def complete?
98
- @mutable_attributes.frozen?
99
- end
100
-
101
- protected :parent= # rubocop:disable Style/AccessModifierDeclarations
102
-
103
- # Override `AST::Node#updated` so that `AST::Processor` does not try to
104
- # mutate our ASTs. Since we keep references from children to parents and
105
- # not just the other way around, we cannot update an AST and share
106
- # identical subtrees. Rather, the entire AST must be copied any time any
107
- # part of it is changed.
108
- def updated(type = nil, children = nil, properties = {})
109
- properties[:location] ||= @location
110
- klass = RuboCop::AST::Builder::NODE_MAP[type || @type] || Node
111
- klass.new(type || @type, children || @children, properties)
112
- end
113
-
114
- # Returns the index of the receiver node in its siblings. (Sibling index
115
- # uses zero based numbering.)
116
- #
117
- # @return [Integer] the index of the receiver node in its siblings
118
- def sibling_index
119
- parent.children.index { |sibling| sibling.equal?(self) }
120
- end
121
-
122
- # Common destructuring method. This can be used to normalize
123
- # destructuring for different variations of the node.
124
- # Some node types override this with their own custom
125
- # destructuring method.
126
- #
127
- # @return [Array<Node>] the different parts of the ndde
128
- def node_parts
129
- to_a
130
- end
131
-
132
- # Calls the given block for each ancestor node from parent to root.
133
- # If no block is given, an `Enumerator` is returned.
134
- #
135
- # @overload each_ancestor
136
- # Yield all nodes.
137
- # @overload each_ancestor(type)
138
- # Yield only nodes matching the type.
139
- # @param [Symbol] type a node type
140
- # @overload each_ancestor(type_a, type_b, ...)
141
- # Yield only nodes matching any of the types.
142
- # @param [Symbol] type_a a node type
143
- # @param [Symbol] type_b a node type
144
- # @yieldparam [Node] node each ancestor node
145
- # @return [self] if a block is given
146
- # @return [Enumerator] if no block is given
147
- def each_ancestor(*types, &block)
148
- return to_enum(__method__, *types) unless block_given?
149
-
150
- visit_ancestors(types, &block)
151
-
152
- self
153
- end
154
-
155
- # Returns an array of ancestor nodes.
156
- # This is a shorthand for `node.each_ancestor.to_a`.
157
- #
158
- # @return [Array<Node>] an array of ancestor nodes
159
- def ancestors
160
- each_ancestor.to_a
161
- end
162
-
163
- # Calls the given block for each child node.
164
- # If no block is given, an `Enumerator` is returned.
165
- #
166
- # Note that this is different from `node.children.each { |child| ... }`
167
- # which yields all children including non-node elements.
168
- #
169
- # @overload each_child_node
170
- # Yield all nodes.
171
- # @overload each_child_node(type)
172
- # Yield only nodes matching the type.
173
- # @param [Symbol] type a node type
174
- # @overload each_child_node(type_a, type_b, ...)
175
- # Yield only nodes matching any of the types.
176
- # @param [Symbol] type_a a node type
177
- # @param [Symbol] type_b a node type
178
- # @yieldparam [Node] node each child node
179
- # @return [self] if a block is given
180
- # @return [Enumerator] if no block is given
181
- def each_child_node(*types)
182
- return to_enum(__method__, *types) unless block_given?
183
-
184
- children.each do |child|
185
- next unless child.is_a?(Node)
186
-
187
- yield child if types.empty? || types.include?(child.type)
188
- end
189
-
190
- self
191
- end
192
-
193
- # Returns an array of child nodes.
194
- # This is a shorthand for `node.each_child_node.to_a`.
195
- #
196
- # @return [Array<Node>] an array of child nodes
197
- def child_nodes
198
- each_child_node.to_a
199
- end
200
-
201
- # Calls the given block for each descendant node with depth first order.
202
- # If no block is given, an `Enumerator` is returned.
203
- #
204
- # @overload each_descendant
205
- # Yield all nodes.
206
- # @overload each_descendant(type)
207
- # Yield only nodes matching the type.
208
- # @param [Symbol] type a node type
209
- # @overload each_descendant(type_a, type_b, ...)
210
- # Yield only nodes matching any of the types.
211
- # @param [Symbol] type_a a node type
212
- # @param [Symbol] type_b a node type
213
- # @yieldparam [Node] node each descendant node
214
- # @return [self] if a block is given
215
- # @return [Enumerator] if no block is given
216
- def each_descendant(*types, &block)
217
- return to_enum(__method__, *types) unless block_given?
218
-
219
- visit_descendants(types, &block)
220
-
221
- self
222
- end
223
-
224
- # Returns an array of descendant nodes.
225
- # This is a shorthand for `node.each_descendant.to_a`.
226
- #
227
- # @return [Array<Node>] an array of descendant nodes
228
- def descendants
229
- each_descendant.to_a
230
- end
231
-
232
- # Calls the given block for the receiver and each descendant node in
233
- # depth-first order.
234
- # If no block is given, an `Enumerator` is returned.
235
- #
236
- # This method would be useful when you treat the receiver node as the root
237
- # of a tree and want to iterate over all nodes in the tree.
238
- #
239
- # @overload each_node
240
- # Yield all nodes.
241
- # @overload each_node(type)
242
- # Yield only nodes matching the type.
243
- # @param [Symbol] type a node type
244
- # @overload each_node(type_a, type_b, ...)
245
- # Yield only nodes matching any of the types.
246
- # @param [Symbol] type_a a node type
247
- # @param [Symbol] type_b a node type
248
- # @yieldparam [Node] node each node
249
- # @return [self] if a block is given
250
- # @return [Enumerator] if no block is given
251
- def each_node(*types, &block)
252
- return to_enum(__method__, *types) unless block_given?
253
-
254
- yield self if types.empty? || types.include?(type)
255
-
256
- visit_descendants(types, &block)
257
-
258
- self
259
- end
260
-
261
- def source
262
- loc.expression.source
263
- end
264
-
265
- def source_range
266
- loc.expression
267
- end
268
-
269
- def first_line
270
- loc.line
271
- end
272
-
273
- def last_line
274
- loc.last_line
275
- end
276
-
277
- def line_count
278
- return 0 unless source_range
279
-
280
- source_range.last_line - source_range.first_line + 1
281
- end
282
-
283
- def nonempty_line_count
284
- source.lines.grep(/\S/).size
285
- end
286
-
287
- def source_length
288
- source_range ? source_range.size : 0
289
- end
290
-
291
- ## Destructuring
292
-
293
- def_node_matcher :receiver, <<~PATTERN
294
- {(send $_ ...) (block (send $_ ...) ...)}
295
- PATTERN
296
-
297
- def_node_matcher :str_content, '(str $_)'
298
-
299
- def const_name
300
- return unless const_type?
301
-
302
- namespace, name = *self
303
- if namespace && !namespace.cbase_type?
304
- "#{namespace.const_name}::#{name}"
305
- else
306
- name.to_s
307
- end
308
- end
309
-
310
- def_node_matcher :defined_module0, <<~PATTERN
311
- {(class (const $_ $_) ...)
312
- (module (const $_ $_) ...)
313
- (casgn $_ $_ (send (const nil? {:Class :Module}) :new ...))
314
- (casgn $_ $_ (block (send (const nil? {:Class :Module}) :new ...) ...))}
315
- PATTERN
316
- # rubocop:disable Style/AccessModifierDeclarations
317
- private :defined_module0
318
- # rubocop:enable Style/AccessModifierDeclarations
319
-
320
- def defined_module
321
- namespace, name = *defined_module0
322
- s(:const, namespace, name) if name
323
- end
324
-
325
- def defined_module_name
326
- (const = defined_module) && const.const_name
327
- end
328
-
329
- ## Searching the AST
330
-
331
- def parent_module_name
332
- # what class or module is this method/constant/etc definition in?
333
- # returns nil if answer cannot be determined
334
- ancestors = each_ancestor(:class, :module, :sclass, :casgn, :block)
335
- result = ancestors.map do |ancestor|
336
- parent_module_name_part(ancestor) { |full_name| return full_name }
337
- end.compact.reverse.join('::')
338
- result.empty? ? 'Object' : result
339
- end
340
-
341
- ## Predicates
342
-
343
- def multiline?
344
- line_count > 1
345
- end
346
-
347
- def single_line?
348
- line_count == 1
349
- end
350
-
351
- def empty_source?
352
- source_length.zero?
353
- end
354
-
355
- # Some cops treat the shovel operator as a kind of assignment.
356
- def_node_matcher :assignment_or_similar?, <<~PATTERN
357
- {assignment? (send _recv :<< ...)}
358
- PATTERN
359
-
360
- def literal?
361
- LITERALS.include?(type)
362
- end
363
-
364
- def basic_literal?
365
- BASIC_LITERALS.include?(type)
366
- end
367
-
368
- def truthy_literal?
369
- TRUTHY_LITERALS.include?(type)
370
- end
371
-
372
- def falsey_literal?
373
- FALSEY_LITERALS.include?(type)
374
- end
375
-
376
- def mutable_literal?
377
- MUTABLE_LITERALS.include?(type)
378
- end
379
-
380
- def immutable_literal?
381
- IMMUTABLE_LITERALS.include?(type)
382
- end
383
-
384
- %i[literal basic_literal].each do |kind|
385
- recursive_kind = :"recursive_#{kind}?"
386
- kind_filter = :"#{kind}?"
387
- define_method(recursive_kind) do
388
- case type
389
- when :send
390
- [*COMPARISON_OPERATORS, :!, :<=>].include?(method_name) &&
391
- receiver.send(recursive_kind) &&
392
- arguments.all?(&recursive_kind)
393
- when :begin, :pair, *OPERATOR_KEYWORDS, *COMPOSITE_LITERALS
394
- children.compact.all?(&recursive_kind)
395
- else
396
- send(kind_filter)
397
- end
398
- end
399
- end
400
-
401
- def variable?
402
- VARIABLES.include?(type)
403
- end
404
-
405
- def reference?
406
- REFERENCES.include?(type)
407
- end
408
-
409
- def equals_asgn?
410
- EQUALS_ASSIGNMENTS.include?(type)
411
- end
412
-
413
- def shorthand_asgn?
414
- SHORTHAND_ASSIGNMENTS.include?(type)
415
- end
416
-
417
- def assignment?
418
- ASSIGNMENTS.include?(type)
419
- end
420
-
421
- def basic_conditional?
422
- BASIC_CONDITIONALS.include?(type)
423
- end
424
-
425
- def conditional?
426
- CONDITIONALS.include?(type)
427
- end
428
-
429
- def keyword?
430
- return true if special_keyword? || send_type? && prefix_not?
431
- return false unless KEYWORDS.include?(type)
432
-
433
- !OPERATOR_KEYWORDS.include?(type) || loc.operator.is?(type.to_s)
434
- end
435
-
436
- def special_keyword?
437
- SPECIAL_KEYWORDS.include?(source)
438
- end
439
-
440
- def operator_keyword?
441
- OPERATOR_KEYWORDS.include?(type)
442
- end
443
-
444
- def parenthesized_call?
445
- loc.respond_to?(:begin) && loc.begin && loc.begin.is?('(')
446
- end
447
-
448
- def call_type?
449
- send_type? || csend_type?
450
- end
451
-
452
- def chained?
453
- parent&.call_type? && eql?(parent.receiver)
454
- end
455
-
456
- def argument?
457
- parent&.send_type? && parent.arguments.include?(self)
458
- end
459
-
460
- def boolean_type?
461
- true_type? || false_type?
462
- end
463
-
464
- def numeric_type?
465
- int_type? || float_type?
466
- end
467
-
468
- def range_type?
469
- irange_type? || erange_type?
470
- end
471
-
472
- def_node_matcher :guard_clause?, <<~PATTERN
473
- [${(send nil? {:raise :fail} ...) return break next} single_line?]
474
- PATTERN
475
-
476
- def_node_matcher :proc?, <<~PATTERN
477
- {(block (send nil? :proc) ...)
478
- (block (send (const nil? :Proc) :new) ...)
479
- (send (const nil? :Proc) :new)}
480
- PATTERN
481
-
482
- def_node_matcher :lambda?, '(block (send nil? :lambda) ...)'
483
- def_node_matcher :lambda_or_proc?, '{lambda? proc?}'
484
-
485
- def_node_matcher :class_constructor?, <<~PATTERN
486
- { (send (const nil? {:Class :Module}) :new ...)
487
- (block (send (const nil? {:Class :Module}) :new ...) ...)}
488
- PATTERN
489
-
490
- # Some expressions are evaluated for their value, some for their side
491
- # effects, and some for both
492
- # If we know that an expression is useful only for its side effects, that
493
- # means we can transform it in ways which preserve the side effects, but
494
- # change the return value
495
- # So, does the return value of this node matter? If we changed it to
496
- # `(...; nil)`, might that affect anything?
497
- #
498
- # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
499
- def value_used?
500
- # Be conservative and return true if we're not sure.
501
- return false if parent.nil?
502
-
503
- case parent.type
504
- when :array, :defined?, :dstr, :dsym, :eflipflop, :erange, :float,
505
- :hash, :iflipflop, :irange, :not, :pair, :regexp, :str, :sym,
506
- :when, :xstr
507
- parent.value_used?
508
- when :begin, :kwbegin
509
- begin_value_used?
510
- when :for
511
- for_value_used?
512
- when :case, :if
513
- case_if_value_used?
514
- when :while, :until, :while_post, :until_post
515
- while_until_value_used?
516
- else
517
- true
518
- end
519
- end
520
- # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
521
-
522
- # Some expressions are evaluated for their value, some for their side
523
- # effects, and some for both.
524
- # If we know that expressions are useful only for their return values,
525
- # and have no side effects, that means we can reorder them, change the
526
- # number of times they are evaluated, or replace them with other
527
- # expressions which are equivalent in value.
528
- # So, is evaluation of this node free of side effects?
529
- #
530
- def pure?
531
- # Be conservative and return false if we're not sure
532
- case type
533
- when :__FILE__, :__LINE__, :const, :cvar, :defined?, :false, :float,
534
- :gvar, :int, :ivar, :lvar, :nil, :str, :sym, :true, :regopt
535
- true
536
- when :and, :array, :begin, :case, :dstr, :dsym, :eflipflop, :ensure,
537
- :erange, :for, :hash, :if, :iflipflop, :irange, :kwbegin, :not,
538
- :or, :pair, :regexp, :until, :until_post, :when, :while,
539
- :while_post
540
- child_nodes.all?(&:pure?)
541
- else
542
- false
543
- end
544
- end
545
-
546
- protected
547
-
548
- def visit_descendants(types, &block)
549
- each_child_node do |child|
550
- yield child if types.empty? || types.include?(child.type)
551
- child.visit_descendants(types, &block)
552
- end
553
- end
554
-
555
- private
556
-
557
- def visit_ancestors(types)
558
- last_node = self
559
-
560
- while (current_node = last_node.parent)
561
- yield current_node if types.empty? ||
562
- types.include?(current_node.type)
563
- last_node = current_node
564
- end
565
- end
566
-
567
- def begin_value_used?
568
- # the last child node determines the value of the parent
569
- sibling_index == parent.children.size - 1 ? parent.value_used? : false
570
- end
571
-
572
- def for_value_used?
573
- # `for var in enum; body; end`
574
- # (for <var> <enum> <body>)
575
- sibling_index == 2 ? parent.value_used? : true
576
- end
577
-
578
- def case_if_value_used?
579
- # (case <condition> <when...>)
580
- # (if <condition> <truebranch> <falsebranch>)
581
- sibling_index.zero? ? true : parent.value_used?
582
- end
583
-
584
- def while_until_value_used?
585
- # (while <condition> <body>) -> always evaluates to `nil`
586
- sibling_index.zero?
587
- end
588
-
589
- def parent_module_name_part(node)
590
- case node.type
591
- when :class, :module, :casgn
592
- # TODO: if constant name has cbase (leading ::), then we don't need
593
- # to keep traversing up through nested classes/modules
594
- node.defined_module_name
595
- when :sclass
596
- yield parent_module_name_for_sclass(node)
597
- else # block
598
- parent_module_name_for_block(node) { yield nil }
599
- end
600
- end
601
-
602
- def parent_module_name_for_sclass(sclass_node)
603
- # TODO: look for constant definition and see if it is nested
604
- # inside a class or module
605
- subject = sclass_node.children[0]
606
-
607
- if subject.const_type?
608
- "#<Class:#{subject.const_name}>"
609
- elsif subject.self_type?
610
- "#<Class:#{sclass_node.parent_module_name}>"
611
- end
612
- end
613
-
614
- def parent_module_name_for_block(ancestor)
615
- if ancestor.method?(:class_eval)
616
- # `class_eval` with no receiver applies to whatever module or class
617
- # we are currently in
618
- return unless (receiver = ancestor.receiver)
619
-
620
- yield unless receiver.const_type?
621
- receiver.const_name
622
- elsif !new_class_or_module_block?(ancestor)
623
- yield
624
- end
625
- end
626
-
627
- def_node_matcher :new_class_or_module_block?, <<~PATTERN
628
- ^(casgn _ _ (block (send (const _ {:Class :Module}) :new) ...))
629
- PATTERN
630
- end
631
- end
632
- end