rubocop 0.83.0 → 0.87.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 (312) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -18
  3. data/config/default.yml +128 -23
  4. data/lib/rubocop.rb +21 -59
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli.rb +2 -4
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
  8. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  9. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  10. data/lib/rubocop/comment_config.rb +1 -1
  11. data/lib/rubocop/config.rb +1 -1
  12. data/lib/rubocop/config_loader.rb +24 -70
  13. data/lib/rubocop/config_loader_resolver.rb +21 -9
  14. data/lib/rubocop/config_obsoletion.rb +0 -1
  15. data/lib/rubocop/config_store.rb +12 -2
  16. data/lib/rubocop/cop/autocorrect_logic.rb +14 -25
  17. data/lib/rubocop/cop/base.rb +399 -0
  18. data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
  19. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
  20. data/lib/rubocop/cop/commissioner.rb +48 -71
  21. data/lib/rubocop/cop/cop.rb +91 -227
  22. data/lib/rubocop/cop/corrector.rb +38 -115
  23. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
  24. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
  25. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  26. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  27. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  28. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  29. data/lib/rubocop/cop/generator.rb +2 -2
  30. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  31. data/lib/rubocop/cop/ignored_node.rb +1 -3
  32. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
  33. data/lib/rubocop/cop/layout/case_indentation.rb +21 -22
  34. data/lib/rubocop/cop/layout/class_structure.rb +19 -16
  35. data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
  36. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  37. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  38. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +57 -4
  39. data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
  40. data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -4
  41. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
  42. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  43. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  44. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  45. data/lib/rubocop/cop/layout/hash_alignment.rb +8 -9
  46. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
  47. data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
  48. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  49. data/lib/rubocop/cop/layout/line_length.rb +17 -17
  50. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -2
  51. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  52. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  53. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
  54. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  55. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
  56. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  57. data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
  58. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  59. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
  60. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  61. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  62. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
  63. data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
  64. data/lib/rubocop/cop/legacy/corrector.rb +29 -0
  65. data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -2
  66. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  67. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
  68. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  69. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
  70. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  71. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
  72. data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
  73. data/lib/rubocop/cop/lint/loop.rb +1 -1
  74. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
  75. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  76. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  77. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  78. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  79. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +20 -5
  80. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
  81. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  82. data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
  83. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  84. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
  85. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  86. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
  87. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  88. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  89. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
  90. data/lib/rubocop/cop/lint/suppressed_exception.rb +15 -2
  91. data/lib/rubocop/cop/lint/syntax.rb +11 -28
  92. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  93. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  94. data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
  95. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
  96. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  97. data/lib/rubocop/cop/metrics/block_length.rb +22 -0
  98. data/lib/rubocop/cop/metrics/class_length.rb +25 -2
  99. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
  100. data/lib/rubocop/cop/metrics/method_length.rb +23 -0
  101. data/lib/rubocop/cop/metrics/module_length.rb +25 -2
  102. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  103. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
  104. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  105. data/lib/rubocop/cop/migration/department_name.rb +7 -7
  106. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  107. data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
  108. data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
  109. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  110. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
  111. data/lib/rubocop/cop/mixin/code_length.rb +4 -0
  112. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  113. data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -5
  114. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  115. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  116. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  117. data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
  118. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  119. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  120. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
  121. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  122. data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
  123. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
  124. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  125. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  126. data/lib/rubocop/cop/mixin/range_help.rb +1 -1
  127. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
  128. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  129. data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
  130. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
  131. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  132. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +7 -5
  133. data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
  134. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
  135. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  136. data/lib/rubocop/cop/naming/file_name.rb +28 -17
  137. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  138. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  139. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  140. data/lib/rubocop/cop/naming/predicate_name.rb +4 -6
  141. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  142. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  143. data/lib/rubocop/cop/offense.rb +16 -2
  144. data/lib/rubocop/cop/registry.rb +63 -10
  145. data/lib/rubocop/cop/severity.rb +1 -3
  146. data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
  147. data/lib/rubocop/cop/style/and_or.rb +2 -2
  148. data/lib/rubocop/cop/style/array_join.rb +1 -1
  149. data/lib/rubocop/cop/style/attr.rb +1 -3
  150. data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
  151. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
  152. data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
  153. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  154. data/lib/rubocop/cop/style/class_vars.rb +21 -0
  155. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  156. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  157. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
  158. data/lib/rubocop/cop/style/copyright.rb +5 -5
  159. data/lib/rubocop/cop/style/date_time.rb +1 -1
  160. data/lib/rubocop/cop/style/dir.rb +2 -2
  161. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  162. data/lib/rubocop/cop/style/documentation.rb +2 -2
  163. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  164. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
  165. data/lib/rubocop/cop/style/empty_literal.rb +6 -8
  166. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  167. data/lib/rubocop/cop/style/encoding.rb +1 -1
  168. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  169. data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
  170. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  171. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
  172. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
  173. data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
  174. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  175. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  176. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
  177. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  178. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  179. data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
  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/multiline_block_chain.rb +10 -1
  183. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  184. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  185. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
  186. data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
  187. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  188. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  189. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
  190. data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
  191. data/lib/rubocop/cop/style/next.rb +2 -2
  192. data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
  193. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
  194. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
  195. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  196. data/lib/rubocop/cop/style/proc.rb +1 -1
  197. data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
  198. data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
  199. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
  200. data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
  201. data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
  202. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  203. data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -8
  204. data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
  205. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +90 -0
  206. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
  207. data/lib/rubocop/cop/style/redundant_self.rb +6 -9
  208. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
  209. data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
  210. data/lib/rubocop/cop/style/sample.rb +1 -1
  211. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  212. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  213. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  214. data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
  215. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  216. data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
  217. data/lib/rubocop/cop/style/symbol_array.rb +5 -5
  218. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  219. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
  220. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
  221. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
  222. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
  223. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
  224. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
  225. data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
  226. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  227. data/lib/rubocop/cop/style/when_then.rb +1 -1
  228. data/lib/rubocop/cop/style/word_array.rb +1 -1
  229. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  230. data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
  231. data/lib/rubocop/cop/team.rb +141 -81
  232. data/lib/rubocop/cop/util.rb +3 -3
  233. data/lib/rubocop/cop/utils/format_string.rb +19 -2
  234. data/lib/rubocop/cop/variable_force.rb +3 -9
  235. data/lib/rubocop/cop/variable_force/branch.rb +1 -3
  236. data/lib/rubocop/cop/variable_force/variable.rb +2 -6
  237. data/lib/rubocop/ext/processed_source.rb +18 -0
  238. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  239. data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
  240. data/lib/rubocop/formatter/formatter_set.rb +2 -4
  241. data/lib/rubocop/formatter/junit_formatter.rb +14 -4
  242. data/lib/rubocop/magic_comment.rb +1 -1
  243. data/lib/rubocop/name_similarity.rb +7 -3
  244. data/lib/rubocop/options.rb +30 -15
  245. data/lib/rubocop/path_util.rb +2 -2
  246. data/lib/rubocop/platform.rb +1 -1
  247. data/lib/rubocop/rake_task.rb +6 -9
  248. data/lib/rubocop/remote_config.rb +1 -3
  249. data/lib/rubocop/result_cache.rb +5 -7
  250. data/lib/rubocop/rspec/cop_helper.rb +5 -28
  251. data/lib/rubocop/rspec/expect_offense.rb +60 -23
  252. data/lib/rubocop/rspec/shared_contexts.rb +55 -17
  253. data/lib/rubocop/runner.rb +42 -38
  254. data/lib/rubocop/target_finder.rb +2 -4
  255. data/lib/rubocop/target_ruby.rb +5 -2
  256. data/lib/rubocop/version.rb +5 -3
  257. metadata +60 -62
  258. data/lib/rubocop/ast/builder.rb +0 -85
  259. data/lib/rubocop/ast/node.rb +0 -637
  260. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  261. data/lib/rubocop/ast/node/and_node.rb +0 -29
  262. data/lib/rubocop/ast/node/args_node.rb +0 -29
  263. data/lib/rubocop/ast/node/array_node.rb +0 -70
  264. data/lib/rubocop/ast/node/block_node.rb +0 -121
  265. data/lib/rubocop/ast/node/break_node.rb +0 -17
  266. data/lib/rubocop/ast/node/case_match_node.rb +0 -56
  267. data/lib/rubocop/ast/node/case_node.rb +0 -56
  268. data/lib/rubocop/ast/node/class_node.rb +0 -31
  269. data/lib/rubocop/ast/node/def_node.rb +0 -82
  270. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  271. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  272. data/lib/rubocop/ast/node/float_node.rb +0 -12
  273. data/lib/rubocop/ast/node/for_node.rb +0 -53
  274. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  275. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  276. data/lib/rubocop/ast/node/if_node.rb +0 -175
  277. data/lib/rubocop/ast/node/int_node.rb +0 -12
  278. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  279. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  280. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  281. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  282. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  283. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  284. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
  285. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  286. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  287. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  288. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  289. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  290. data/lib/rubocop/ast/node/module_node.rb +0 -24
  291. data/lib/rubocop/ast/node/or_node.rb +0 -29
  292. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  293. data/lib/rubocop/ast/node/range_node.rb +0 -18
  294. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  295. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  296. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  297. data/lib/rubocop/ast/node/return_node.rb +0 -24
  298. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  299. data/lib/rubocop/ast/node/send_node.rb +0 -17
  300. data/lib/rubocop/ast/node/str_node.rb +0 -16
  301. data/lib/rubocop/ast/node/super_node.rb +0 -21
  302. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  303. data/lib/rubocop/ast/node/until_node.rb +0 -35
  304. data/lib/rubocop/ast/node/when_node.rb +0 -53
  305. data/lib/rubocop/ast/node/while_node.rb +0 -35
  306. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  307. data/lib/rubocop/ast/sexp.rb +0 -16
  308. data/lib/rubocop/ast/traversal.rb +0 -202
  309. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
  310. data/lib/rubocop/node_pattern.rb +0 -887
  311. data/lib/rubocop/processed_source.rb +0 -213
  312. data/lib/rubocop/token.rb +0 -114
@@ -1,73 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser'
4
3
  require 'rainbow'
5
4
 
6
5
  require 'English'
7
6
  require 'set'
8
7
  require 'forwardable'
8
+ require 'regexp_parser'
9
9
  require 'unicode/display_width/no_string_ext'
10
+ require 'rubocop-ast'
11
+ require_relative 'rubocop/ast_aliases'
10
12
 
11
13
  require_relative 'rubocop/version'
12
14
 
13
15
  require_relative 'rubocop/core_ext/string'
16
+ require_relative 'rubocop/ext/processed_source'
17
+
14
18
  require_relative 'rubocop/path_util'
15
19
  require_relative 'rubocop/file_finder'
16
20
  require_relative 'rubocop/platform'
17
21
  require_relative 'rubocop/name_similarity'
18
- require_relative 'rubocop/node_pattern'
19
22
  require_relative 'rubocop/string_interpreter'
20
- require_relative 'rubocop/ast/sexp'
21
- require_relative 'rubocop/ast/node'
22
- require_relative 'rubocop/ast/node/mixin/method_identifier_predicates'
23
- require_relative 'rubocop/ast/node/mixin/binary_operator_node'
24
- require_relative 'rubocop/ast/node/mixin/collection_node'
25
- require_relative 'rubocop/ast/node/mixin/conditional_node'
26
- require_relative 'rubocop/ast/node/mixin/hash_element_node'
27
- require_relative 'rubocop/ast/node/mixin/method_dispatch_node'
28
- require_relative 'rubocop/ast/node/mixin/modifier_node'
29
- require_relative 'rubocop/ast/node/mixin/numeric_node'
30
- require_relative 'rubocop/ast/node/mixin/parameterized_node'
31
- require_relative 'rubocop/ast/node/mixin/predicate_operator_node'
32
- require_relative 'rubocop/ast/node/mixin/basic_literal_node'
33
- require_relative 'rubocop/ast/node/alias_node'
34
- require_relative 'rubocop/ast/node/and_node'
35
- require_relative 'rubocop/ast/node/args_node'
36
- require_relative 'rubocop/ast/node/array_node'
37
- require_relative 'rubocop/ast/node/block_node'
38
- require_relative 'rubocop/ast/node/break_node'
39
- require_relative 'rubocop/ast/node/case_match_node'
40
- require_relative 'rubocop/ast/node/case_node'
41
- require_relative 'rubocop/ast/node/class_node'
42
- require_relative 'rubocop/ast/node/def_node'
43
- require_relative 'rubocop/ast/node/defined_node'
44
- require_relative 'rubocop/ast/node/ensure_node'
45
- require_relative 'rubocop/ast/node/for_node'
46
- require_relative 'rubocop/ast/node/forward_args_node'
47
- require_relative 'rubocop/ast/node/float_node'
48
- require_relative 'rubocop/ast/node/hash_node'
49
- require_relative 'rubocop/ast/node/if_node'
50
- require_relative 'rubocop/ast/node/int_node'
51
- require_relative 'rubocop/ast/node/keyword_splat_node'
52
- require_relative 'rubocop/ast/node/module_node'
53
- require_relative 'rubocop/ast/node/or_node'
54
- require_relative 'rubocop/ast/node/pair_node'
55
- require_relative 'rubocop/ast/node/range_node'
56
- require_relative 'rubocop/ast/node/regexp_node'
57
- require_relative 'rubocop/ast/node/resbody_node'
58
- require_relative 'rubocop/ast/node/retry_node'
59
- require_relative 'rubocop/ast/node/return_node'
60
- require_relative 'rubocop/ast/node/self_class_node'
61
- require_relative 'rubocop/ast/node/send_node'
62
- require_relative 'rubocop/ast/node/str_node'
63
- require_relative 'rubocop/ast/node/super_node'
64
- require_relative 'rubocop/ast/node/symbol_node'
65
- require_relative 'rubocop/ast/node/until_node'
66
- require_relative 'rubocop/ast/node/when_node'
67
- require_relative 'rubocop/ast/node/while_node'
68
- require_relative 'rubocop/ast/node/yield_node'
69
- require_relative 'rubocop/ast/builder'
70
- require_relative 'rubocop/ast/traversal'
71
23
  require_relative 'rubocop/error'
72
24
  require_relative 'rubocop/warning'
73
25
 
@@ -78,6 +30,7 @@ require_relative 'rubocop/cop/ignored_node'
78
30
  require_relative 'rubocop/cop/autocorrect_logic'
79
31
  require_relative 'rubocop/cop/badge'
80
32
  require_relative 'rubocop/cop/registry'
33
+ require_relative 'rubocop/cop/base'
81
34
  require_relative 'rubocop/cop/cop'
82
35
  require_relative 'rubocop/cop/commissioner'
83
36
  require_relative 'rubocop/cop/corrector'
@@ -100,11 +53,12 @@ require_relative 'rubocop/cop/mixin/annotation_comment'
100
53
  require_relative 'rubocop/cop/mixin/array_min_size'
101
54
  require_relative 'rubocop/cop/mixin/array_syntax'
102
55
  require_relative 'rubocop/cop/mixin/alignment'
56
+ require_relative 'rubocop/cop/mixin/allowed_methods'
57
+ require_relative 'rubocop/cop/mixin/auto_corrector'
103
58
  require_relative 'rubocop/cop/mixin/check_assignment'
104
59
  require_relative 'rubocop/cop/mixin/check_line_breakable'
105
60
  require_relative 'rubocop/cop/mixin/configurable_max'
106
61
  require_relative 'rubocop/cop/mixin/code_length' # relies on configurable_max
107
- require_relative 'rubocop/cop/mixin/classish_length' # relies on code_length
108
62
  require_relative 'rubocop/cop/mixin/configurable_enforced_style'
109
63
  require_relative 'rubocop/cop/mixin/configurable_formatting'
110
64
  require_relative 'rubocop/cop/mixin/configurable_naming'
@@ -146,6 +100,7 @@ require_relative 'rubocop/cop/mixin/percent_literal'
146
100
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
147
101
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
148
102
  require_relative 'rubocop/cop/mixin/rational_literal'
103
+ require_relative 'rubocop/cop/mixin/regexp_literal_help'
149
104
  require_relative 'rubocop/cop/mixin/rescue_node'
150
105
  require_relative 'rubocop/cop/mixin/safe_assignment'
151
106
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
@@ -216,7 +171,7 @@ require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
216
171
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
217
172
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
218
173
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
219
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
174
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
220
175
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
221
176
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
222
177
  require_relative 'rubocop/cop/layout/empty_lines'
@@ -289,8 +244,10 @@ require_relative 'rubocop/cop/lint/assignment_in_condition'
289
244
  require_relative 'rubocop/cop/lint/big_decimal_new'
290
245
  require_relative 'rubocop/cop/lint/boolean_symbol'
291
246
  require_relative 'rubocop/cop/lint/circular_argument_reference'
247
+ require_relative 'rubocop/cop/lint/constant_resolution'
292
248
  require_relative 'rubocop/cop/lint/debugger'
293
249
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
250
+ require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
294
251
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
295
252
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
296
253
  require_relative 'rubocop/cop/lint/duplicate_hash_key'
@@ -315,6 +272,7 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
315
272
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
316
273
  require_relative 'rubocop/cop/lint/loop'
317
274
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
275
+ require_relative 'rubocop/cop/lint/mixed_regexp_capture_types'
318
276
  require_relative 'rubocop/cop/lint/multiple_comparison'
319
277
  require_relative 'rubocop/cop/lint/nested_method_definition'
320
278
  require_relative 'rubocop/cop/lint/nested_percent_literal'
@@ -366,9 +324,11 @@ require_relative 'rubocop/cop/lint/useless_else_without_rescue'
366
324
  require_relative 'rubocop/cop/lint/useless_setter_call'
367
325
  require_relative 'rubocop/cop/lint/void'
368
326
 
327
+ require_relative 'rubocop/cop/metrics/utils/iterating_block'
369
328
  require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
370
329
  # relies on cyclomatic_complexity
371
330
  require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
331
+ require_relative 'rubocop/cop/metrics/utils/code_length_calculator'
372
332
  require_relative 'rubocop/cop/metrics/abc_size'
373
333
  require_relative 'rubocop/cop/metrics/block_length'
374
334
  require_relative 'rubocop/cop/metrics/block_nesting'
@@ -396,6 +356,7 @@ require_relative 'rubocop/cop/naming/variable_name'
396
356
  require_relative 'rubocop/cop/naming/variable_number'
397
357
 
398
358
  require_relative 'rubocop/cop/style/access_modifier_declarations'
359
+ require_relative 'rubocop/cop/style/accessor_grouping'
399
360
  require_relative 'rubocop/cop/style/alias'
400
361
  require_relative 'rubocop/cop/style/and_or'
401
362
  require_relative 'rubocop/cop/style/array_join'
@@ -404,6 +365,7 @@ require_relative 'rubocop/cop/style/attr'
404
365
  require_relative 'rubocop/cop/style/auto_resource_cleanup'
405
366
  require_relative 'rubocop/cop/style/bare_percent_literals'
406
367
  require_relative 'rubocop/cop/style/begin_block'
368
+ require_relative 'rubocop/cop/style/bisected_attr_accessor'
407
369
  require_relative 'rubocop/cop/style/block_comments'
408
370
  require_relative 'rubocop/cop/style/block_delimiters'
409
371
  require_relative 'rubocop/cop/style/case_equality'
@@ -468,11 +430,11 @@ require_relative 'rubocop/cop/style/lambda'
468
430
  require_relative 'rubocop/cop/style/lambda_call'
469
431
  require_relative 'rubocop/cop/style/line_end_concatenation'
470
432
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
471
- # rubocop:disable Layout/LineLength
472
433
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
434
+ require_relative 'rubocop/cop/style/redundant_assignment'
435
+ require_relative 'rubocop/cop/style/redundant_fetch_block'
473
436
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
474
437
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
475
- # rubocop:enable Layout/LineLength
476
438
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
477
439
  require_relative 'rubocop/cop/style/method_def_parentheses'
478
440
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -526,6 +488,8 @@ require_relative 'rubocop/cop/style/redundant_freeze'
526
488
  require_relative 'rubocop/cop/style/redundant_interpolation'
527
489
  require_relative 'rubocop/cop/style/redundant_parentheses'
528
490
  require_relative 'rubocop/cop/style/redundant_percent_q'
491
+ require_relative 'rubocop/cop/style/redundant_regexp_character_class'
492
+ require_relative 'rubocop/cop/style/redundant_regexp_escape'
529
493
  require_relative 'rubocop/cop/style/redundant_return'
530
494
  require_relative 'rubocop/cop/style/redundant_self'
531
495
  require_relative 'rubocop/cop/style/redundant_sort'
@@ -614,10 +578,8 @@ require_relative 'rubocop/config_obsoletion'
614
578
  require_relative 'rubocop/config_store'
615
579
  require_relative 'rubocop/config_validator'
616
580
  require_relative 'rubocop/target_finder'
617
- require_relative 'rubocop/token'
618
581
  require_relative 'rubocop/comment_config'
619
582
  require_relative 'rubocop/magic_comment'
620
- require_relative 'rubocop/processed_source'
621
583
  require_relative 'rubocop/result_cache'
622
584
  require_relative 'rubocop/runner'
623
585
  require_relative 'rubocop/cli'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These aliases are for compatibility.
4
+ module RuboCop
5
+ NodePattern = AST::NodePattern
6
+ ProcessedSource = AST::ProcessedSource
7
+ Token = AST::Token
8
+ end
@@ -75,7 +75,7 @@ module RuboCop
75
75
 
76
76
  def validate_options_vs_config
77
77
  if @options[:parallel] &&
78
- !@config_store.for(Dir.pwd).for_all_cops['UseCache']
78
+ !@config_store.for_dir(Dir.pwd).for_all_cops['UseCache']
79
79
  raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \
80
80
  'execution, so combining with AllCops: ' \
81
81
  'UseCache: false is not allowed.'
@@ -101,11 +101,9 @@ module RuboCop
101
101
 
102
102
  def set_options_to_config_loader
103
103
  ConfigLoader.debug = @options[:debug]
104
- ConfigLoader.auto_gen_config = @options[:auto_gen_config]
105
104
  ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
106
105
  ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
107
106
  ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
108
- ConfigLoader.options_config = @options[:config]
109
107
  end
110
108
 
111
109
  def handle_exiting_options
@@ -123,7 +121,7 @@ module RuboCop
123
121
  if @options[:auto_gen_config]
124
122
  formatter = 'autogenconf'
125
123
  else
126
- cfg = @config_store.for(Dir.pwd).for_all_cops
124
+ cfg = @config_store.for_dir(Dir.pwd).for_all_cops
127
125
  formatter = cfg['DefaultFormatter'] || 'progress'
128
126
  end
129
127
  [[formatter, @options[:output_path]]]
@@ -7,6 +7,8 @@ module RuboCop
7
7
  class AutoGenerateConfig < Base
8
8
  self.command_name = :auto_gen_config
9
9
 
10
+ AUTO_GENERATED_FILE = '.rubocop_todo.yml'
11
+
10
12
  PHASE_1 = 'Phase 1 of 2: run Layout/LineLength cop'
11
13
  PHASE_2 = 'Phase 2 of 2: run all cops'
12
14
 
@@ -25,10 +27,10 @@ module RuboCop
25
27
  private
26
28
 
27
29
  def maybe_run_line_length_cop
28
- if !line_length_enabled?(@config_store.for(Dir.pwd))
30
+ if !line_length_enabled?(@config_store.for_dir(Dir.pwd))
29
31
  skip_line_length_cop(PHASE_1_DISABLED)
30
32
  elsif !same_max_line_length?(
31
- @config_store.for(Dir.pwd), ConfigLoader.default_configuration
33
+ @config_store.for_dir(Dir.pwd), ConfigLoader.default_configuration
32
34
  )
33
35
  skip_line_length_cop(PHASE_1_OVERRIDDEN)
34
36
  else
@@ -67,7 +69,7 @@ module RuboCop
67
69
  @options.delete(:only)
68
70
  @config_store = ConfigStore.new
69
71
  # Save the todo configuration of the LineLength cop.
70
- IO.read(ConfigLoader::AUTO_GENERATED_FILE)
72
+ IO.read(AUTO_GENERATED_FILE)
71
73
  .lines
72
74
  .drop_while { |line| line.start_with?('#') }
73
75
  .join
@@ -78,7 +80,7 @@ module RuboCop
78
80
  result = execute_runner
79
81
  # This run was made with the current maximum length allowed, so append
80
82
  # the saved setting for LineLength.
81
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'a') do |f|
83
+ File.open(AUTO_GENERATED_FILE, 'a') do |f|
82
84
  f.write(line_length_contents)
83
85
  end
84
86
  result
@@ -87,18 +89,51 @@ module RuboCop
87
89
  def reset_config_and_auto_gen_file
88
90
  @config_store = ConfigStore.new
89
91
  @config_store.options_config = @options[:config] if @options[:config]
90
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'w') {}
91
- ConfigLoader.add_inheritance_from_auto_generated_file
92
+ File.open(AUTO_GENERATED_FILE, 'w') {}
93
+ add_inheritance_from_auto_generated_file(@options[:config])
92
94
  end
93
95
 
94
96
  def add_formatter
95
97
  @options[:formatters] << [Formatter::DisabledConfigFormatter,
96
- ConfigLoader::AUTO_GENERATED_FILE]
98
+ AUTO_GENERATED_FILE]
97
99
  end
98
100
 
99
101
  def execute_runner
100
102
  Environment.new(@options, @config_store, @paths).run(:execute_runner)
101
103
  end
104
+
105
+ def add_inheritance_from_auto_generated_file(config_file)
106
+ file_string = " #{AUTO_GENERATED_FILE}"
107
+
108
+ config_file ||= ConfigLoader::DOTFILE
109
+
110
+ if File.exist?(config_file)
111
+ files = Array(ConfigLoader.load_yaml_configuration(config_file)['inherit_from'])
112
+
113
+ return if files.include?(AUTO_GENERATED_FILE)
114
+
115
+ files.unshift(AUTO_GENERATED_FILE)
116
+ file_string = "\n - " + files.join("\n - ") if files.size > 1
117
+ rubocop_yml_contents = existing_configuration(config_file)
118
+ end
119
+
120
+ write_config_file(config_file, file_string, rubocop_yml_contents)
121
+
122
+ puts "Added inheritance from `#{AUTO_GENERATED_FILE}` in `#{ConfigLoader::DOTFILE}`."
123
+ end
124
+
125
+ def existing_configuration(config_file)
126
+ IO.read(config_file, encoding: Encoding::UTF_8)
127
+ .sub(/^inherit_from: *[^\n]+/, '')
128
+ .sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
129
+ end
130
+
131
+ def write_config_file(file_name, file_string, rubocop_yml_contents)
132
+ File.open(file_name, 'w') do |f|
133
+ f.write "inherit_from:#{file_string}\n"
134
+ f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
135
+ end
136
+ end
102
137
  end
103
138
  end
104
139
  end
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # RuboCop will start looking for the configuration file in the directory
28
28
  # where the inspected file is and continue its way up to the root directory.
29
29
  #
30
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
30
+ # See https://docs.rubocop.org/rubocop/configuration
31
31
  DESC
32
32
 
33
33
  File.open(DOTFILE, 'w') do |f|
@@ -42,18 +42,14 @@ module RuboCop
42
42
  selected_cops_of_department(registry, department)
43
43
  end
44
44
 
45
- if show_all
46
- puts "# Department '#{department}' (#{selected_cops.length}):"
47
- end
45
+ puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
48
46
 
49
47
  print_cop_details(selected_cops)
50
48
  end
51
49
 
52
50
  def print_cop_details(cops)
53
51
  cops.each do |cop|
54
- if cop.new(@config).support_autocorrect?
55
- puts '# Supports --auto-correct'
56
- end
52
+ puts '# Supports --auto-correct' if cop.support_autocorrect?
57
53
  puts "#{cop.cop_name}:"
58
54
  puts config_lines(cop)
59
55
  puts
@@ -124,7 +124,7 @@ module RuboCop
124
124
  end
125
125
 
126
126
  def directive_on_comment_line?(comment)
127
- comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
127
+ comment.text[1..-1].match?(COMMENT_DIRECTIVE_REGEXP)
128
128
  end
129
129
 
130
130
  def each_directive
@@ -152,7 +152,7 @@ module RuboCop
152
152
  return true if File.extname(file) == '.gemspec'
153
153
 
154
154
  file_to_include?(file) do |pattern, relative_path, absolute_path|
155
- pattern.to_s =~ /[A-Z]/ &&
155
+ /[A-Z]/.match?(pattern.to_s) &&
156
156
  (match_path?(pattern, relative_path) ||
157
157
  match_path?(pattern, absolute_path))
158
158
  end
@@ -18,21 +18,19 @@ module RuboCop
18
18
  XDG_CONFIG = 'config.yml'
19
19
  RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
20
20
  DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
21
- AUTO_GENERATED_FILE = '.rubocop_todo.yml'
22
21
 
23
22
  class << self
24
23
  include FileFinder
25
24
 
26
- attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion,
27
- :options_config, :disable_pending_cops, :enable_pending_cops
25
+ attr_accessor :debug, :ignore_parent_exclusion,
26
+ :disable_pending_cops, :enable_pending_cops
28
27
  attr_writer :default_configuration
29
28
 
30
29
  alias debug? debug
31
- alias auto_gen_config? auto_gen_config
32
30
  alias ignore_parent_exclusion? ignore_parent_exclusion
33
31
 
34
32
  def clear_options
35
- @debug = @auto_gen_config = @options_config = nil
33
+ @debug = nil
36
34
  FileFinder.root_level = nil
37
35
  end
38
36
 
@@ -55,6 +53,21 @@ module RuboCop
55
53
  Config.create(hash, path)
56
54
  end
57
55
 
56
+ def load_yaml_configuration(absolute_path)
57
+ file_contents = read_file(absolute_path)
58
+ yaml_code = Dir.chdir(File.dirname(absolute_path)) do
59
+ ERB.new(file_contents).result
60
+ end
61
+ check_duplication(yaml_code, absolute_path)
62
+ hash = yaml_safe_load(yaml_code, absolute_path) || {}
63
+
64
+ puts "configuration from #{absolute_path}" if debug?
65
+
66
+ raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
67
+
68
+ hash
69
+ end
70
+
58
71
  def add_missing_namespaces(path, hash)
59
72
  # Using `hash.each_key` will cause the
60
73
  # `can't add a new key into hash during iteration` error
@@ -85,7 +98,7 @@ module RuboCop
85
98
  end
86
99
 
87
100
  def configuration_from_file(config_file)
88
- return ConfigLoader.default_configuration if config_file == DEFAULT_FILE
101
+ return default_configuration if config_file == DEFAULT_FILE
89
102
 
90
103
  config = load_file(config_file)
91
104
  if ignore_parent_exclusion?
@@ -95,9 +108,7 @@ module RuboCop
95
108
  end
96
109
 
97
110
  merge_with_default(config, config_file).tap do |merged_config|
98
- unless possible_new_cops?(config)
99
- warn_on_pending_cops(merged_config.pending_cops)
100
- end
111
+ warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
101
112
  end
102
113
  end
103
114
 
@@ -107,8 +118,8 @@ module RuboCop
107
118
  end
108
119
 
109
120
  def add_excludes_from_files(config, config_file)
110
- found_files = find_files_upwards(DOTFILE, config_file) +
111
- [find_user_dotfile, find_user_xdg_config].compact
121
+ found_files = find_files_upwards(DOTFILE, config_file)
122
+ found_files = [find_user_dotfile, find_user_xdg_config].compact if found_files.empty?
112
123
 
113
124
  return if found_files.empty?
114
125
  return if PathUtil.relative_path(found_files.last) ==
@@ -138,39 +149,14 @@ module RuboCop
138
149
  warn Rainbow(" - #{cop.name} (#{version})").yellow
139
150
  end
140
151
 
141
- warn Rainbow('For more information: https://docs.rubocop.org/en/latest/versioning/').yellow
152
+ warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
142
153
  end
143
154
 
144
- # Merges the given configuration with the default one. If
145
- # AllCops:DisabledByDefault is true, it changes the Enabled params so
146
- # that only cops from user configuration are enabled.
147
- # If AllCops::EnabledByDefault is true, it changes the Enabled params
148
- # so that only cops explicitly disabled in user configuration are
149
- # disabled.
155
+ # Merges the given configuration with the default one.
150
156
  def merge_with_default(config, config_file, unset_nil: true)
151
157
  resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
152
158
  end
153
159
 
154
- def add_inheritance_from_auto_generated_file
155
- file_string = " #{AUTO_GENERATED_FILE}"
156
-
157
- config_file = options_config || DOTFILE
158
-
159
- if File.exist?(config_file)
160
- files = Array(load_yaml_configuration(config_file)['inherit_from'])
161
-
162
- return if files.include?(AUTO_GENERATED_FILE)
163
-
164
- files.unshift(AUTO_GENERATED_FILE)
165
- file_string = "\n - " + files.join("\n - ") if files.size > 1
166
- rubocop_yml_contents = existing_configuration(config_file)
167
- end
168
-
169
- write_config_file(config_file, file_string, rubocop_yml_contents)
170
-
171
- puts "Added inheritance from `#{AUTO_GENERATED_FILE}` in `#{DOTFILE}`."
172
- end
173
-
174
160
  private
175
161
 
176
162
  def find_project_dotfile(target_dir)
@@ -198,42 +184,10 @@ module RuboCop
198
184
  path
199
185
  end
200
186
 
201
- def existing_configuration(config_file)
202
- IO.read(config_file, encoding: Encoding::UTF_8)
203
- .sub(/^inherit_from: *[^\n]+/, '')
204
- .sub(/^inherit_from: *(\n *- *[^\n]+)+/, '')
205
- end
206
-
207
- def write_config_file(file_name, file_string, rubocop_yml_contents)
208
- File.open(file_name, 'w') do |f|
209
- f.write "inherit_from:#{file_string}\n"
210
- if /\S/.match?(rubocop_yml_contents)
211
- f.write "\n#{rubocop_yml_contents}"
212
- end
213
- end
214
- end
215
-
216
187
  def resolver
217
188
  @resolver ||= ConfigLoaderResolver.new
218
189
  end
219
190
 
220
- def load_yaml_configuration(absolute_path)
221
- file_contents = read_file(absolute_path)
222
- yaml_code = Dir.chdir(File.dirname(absolute_path)) do
223
- ERB.new(file_contents).result
224
- end
225
- check_duplication(yaml_code, absolute_path)
226
- hash = yaml_safe_load(yaml_code, absolute_path) || {}
227
-
228
- puts "configuration from #{absolute_path}" if debug?
229
-
230
- unless hash.is_a?(Hash)
231
- raise(TypeError, "Malformed configuration in #{absolute_path}")
232
- end
233
-
234
- hash
235
- end
236
-
237
191
  def check_duplication(yaml_code, absolute_path)
238
192
  smart_path = PathUtil.smart_path(absolute_path)
239
193
  YAMLDuplicationChecker.check(yaml_code, absolute_path) do |key1, key2|