rubocop 1.59.0 → 1.65.1

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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +3 -4
  4. data/assets/output.css.erb +159 -0
  5. data/assets/output.html.erb +1 -160
  6. data/config/default.yml +93 -17
  7. data/lib/rubocop/cached_data.rb +11 -3
  8. data/lib/rubocop/cli/command/auto_generate_config.rb +12 -3
  9. data/lib/rubocop/cli/command/lsp.rb +2 -2
  10. data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
  11. data/lib/rubocop/cli.rb +10 -1
  12. data/lib/rubocop/config.rb +36 -12
  13. data/lib/rubocop/config_finder.rb +12 -2
  14. data/lib/rubocop/config_loader.rb +1 -2
  15. data/lib/rubocop/config_loader_resolver.rb +9 -3
  16. data/lib/rubocop/config_obsoletion.rb +1 -1
  17. data/lib/rubocop/config_validator.rb +14 -7
  18. data/lib/rubocop/cop/autocorrect_logic.rb +6 -1
  19. data/lib/rubocop/cop/base.rb +63 -16
  20. data/lib/rubocop/cop/bundler/gem_version.rb +3 -5
  21. data/lib/rubocop/cop/cop.rb +22 -4
  22. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
  23. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
  24. data/lib/rubocop/cop/documentation.rb +16 -6
  25. data/lib/rubocop/cop/exclude_limit.rb +1 -1
  26. data/lib/rubocop/cop/force.rb +12 -0
  27. data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
  28. data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
  29. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  30. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
  31. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
  32. data/lib/rubocop/cop/internal_affairs/example_description.rb +6 -5
  33. data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
  34. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +122 -28
  35. data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
  36. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  37. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  38. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  39. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  40. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  41. data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
  42. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
  43. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
  44. data/lib/rubocop/cop/layout/end_alignment.rb +8 -2
  45. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
  46. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +18 -1
  47. data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
  48. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  49. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -1
  50. data/lib/rubocop/cop/layout/line_length.rb +20 -20
  51. data/lib/rubocop/cop/layout/redundant_line_break.rb +14 -2
  52. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -0
  53. data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
  54. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
  55. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
  56. data/lib/rubocop/cop/legacy/corrector.rb +12 -2
  57. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  58. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  59. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  60. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
  61. data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
  62. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  63. data/lib/rubocop/cop/lint/debugger.rb +27 -6
  64. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  65. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  66. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
  67. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  68. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  69. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  70. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  71. data/lib/rubocop/cop/lint/empty_conditional_body.rb +2 -2
  72. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  73. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  74. data/lib/rubocop/cop/lint/empty_when.rb +1 -3
  75. data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
  76. data/lib/rubocop/cop/lint/erb_new_arguments.rb +21 -14
  77. data/lib/rubocop/cop/lint/float_comparison.rb +3 -1
  78. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  79. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  80. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +15 -12
  81. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  82. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  83. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  84. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +13 -6
  85. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
  86. data/lib/rubocop/cop/lint/loop.rb +6 -12
  87. data/lib/rubocop/cop/lint/mixed_case_range.rb +9 -4
  88. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -7
  89. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  90. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  91. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
  92. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  93. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  94. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  95. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  96. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +14 -9
  97. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  98. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  99. data/lib/rubocop/cop/lint/redundant_with_index.rb +4 -0
  100. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  101. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  102. data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
  103. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  104. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
  105. data/lib/rubocop/cop/lint/script_permission.rb +3 -3
  106. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  107. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  108. data/lib/rubocop/cop/lint/syntax.rb +6 -3
  109. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -3
  110. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  111. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  112. data/lib/rubocop/cop/lint/unreachable_code.rb +4 -7
  113. data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
  114. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -5
  115. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  116. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  117. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  118. data/lib/rubocop/cop/lint/void.rb +11 -1
  119. data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
  120. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -5
  121. data/lib/rubocop/cop/mixin/alignment.rb +5 -1
  122. data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
  123. data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
  124. data/lib/rubocop/cop/mixin/code_length.rb +12 -1
  125. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
  126. data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
  127. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +9 -2
  128. data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
  129. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  130. data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
  131. data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
  132. data/lib/rubocop/cop/naming/block_forwarding.rb +32 -5
  133. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  134. data/lib/rubocop/cop/naming/inclusive_language.rb +1 -2
  135. data/lib/rubocop/cop/naming/predicate_name.rb +54 -28
  136. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  137. data/lib/rubocop/cop/registry.rb +1 -1
  138. data/lib/rubocop/cop/security/compound_hash.rb +2 -2
  139. data/lib/rubocop/cop/security/open.rb +2 -2
  140. data/lib/rubocop/cop/style/access_modifier_declarations.rb +50 -0
  141. data/lib/rubocop/cop/style/alias.rb +1 -0
  142. data/lib/rubocop/cop/style/arguments_forwarding.rb +89 -17
  143. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  144. data/lib/rubocop/cop/style/class_vars.rb +3 -3
  145. data/lib/rubocop/cop/style/collection_compact.rb +14 -5
  146. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  147. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -7
  148. data/lib/rubocop/cop/style/copyright.rb +31 -21
  149. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  150. data/lib/rubocop/cop/style/documentation.rb +24 -24
  151. data/lib/rubocop/cop/style/documentation_method.rb +20 -0
  152. data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -8
  153. data/lib/rubocop/cop/style/eval_with_location.rb +15 -23
  154. data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
  155. data/lib/rubocop/cop/style/file_read.rb +2 -5
  156. data/lib/rubocop/cop/style/file_write.rb +2 -5
  157. data/lib/rubocop/cop/style/for.rb +2 -0
  158. data/lib/rubocop/cop/style/format_string.rb +9 -9
  159. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  160. data/lib/rubocop/cop/style/hash_each_methods.rb +29 -8
  161. data/lib/rubocop/cop/style/hash_except.rb +8 -5
  162. data/lib/rubocop/cop/style/hash_syntax.rb +24 -2
  163. data/lib/rubocop/cop/style/identical_conditional_branches.rb +4 -1
  164. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -4
  165. data/lib/rubocop/cop/style/inverse_methods.rb +8 -8
  166. data/lib/rubocop/cop/style/invertible_unless_condition.rb +46 -4
  167. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +81 -50
  168. data/lib/rubocop/cop/style/map_into_array.rb +175 -0
  169. data/lib/rubocop/cop/style/map_to_hash.rb +10 -6
  170. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  171. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +18 -5
  172. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
  173. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  174. data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
  175. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
  176. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  177. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  178. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  179. data/lib/rubocop/cop/style/numeric_predicate.rb +10 -2
  180. data/lib/rubocop/cop/style/object_then.rb +5 -3
  181. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  182. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -5
  183. data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
  184. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  185. data/lib/rubocop/cop/style/raise_args.rb +4 -1
  186. data/lib/rubocop/cop/style/redundant_argument.rb +25 -2
  187. data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
  188. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  189. data/lib/rubocop/cop/style/redundant_condition.rb +0 -1
  190. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
  191. data/lib/rubocop/cop/style/redundant_each.rb +7 -4
  192. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
  193. data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
  194. data/lib/rubocop/cop/style/redundant_line_continuation.rb +17 -2
  195. data/lib/rubocop/cop/style/redundant_parentheses.rb +18 -2
  196. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  197. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  198. data/lib/rubocop/cop/style/redundant_return.rb +6 -0
  199. data/lib/rubocop/cop/style/require_order.rb +1 -1
  200. data/lib/rubocop/cop/style/sample.rb +1 -3
  201. data/lib/rubocop/cop/style/send.rb +4 -4
  202. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +104 -0
  203. data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
  204. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  205. data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
  206. data/lib/rubocop/cop/style/super_arguments.rb +174 -0
  207. data/lib/rubocop/cop/style/symbol_proc.rb +75 -5
  208. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  209. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  210. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  211. data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
  212. data/lib/rubocop/cop/team.rb +13 -0
  213. data/lib/rubocop/cop/util.rb +7 -1
  214. data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
  215. data/lib/rubocop/cop/variable_force.rb +13 -1
  216. data/lib/rubocop/cops_documentation_generator.rb +16 -4
  217. data/lib/rubocop/core_ext/string.rb +2 -6
  218. data/lib/rubocop/directive_comment.rb +10 -8
  219. data/lib/rubocop/ext/regexp_node.rb +18 -35
  220. data/lib/rubocop/ext/regexp_parser.rb +4 -21
  221. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
  222. data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -8
  223. data/lib/rubocop/formatter/formatter_set.rb +7 -1
  224. data/lib/rubocop/formatter/html_formatter.rb +32 -10
  225. data/lib/rubocop/formatter/json_formatter.rb +0 -1
  226. data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
  227. data/lib/rubocop/formatter/tap_formatter.rb +3 -7
  228. data/lib/rubocop/formatter.rb +1 -1
  229. data/lib/rubocop/lockfile.rb +56 -7
  230. data/lib/rubocop/lsp/logger.rb +1 -1
  231. data/lib/rubocop/lsp/routes.rb +12 -15
  232. data/lib/rubocop/lsp/runtime.rb +1 -1
  233. data/lib/rubocop/lsp/server.rb +7 -2
  234. data/lib/rubocop/lsp/severity.rb +1 -1
  235. data/lib/rubocop/lsp.rb +36 -0
  236. data/lib/rubocop/magic_comment.rb +1 -1
  237. data/lib/rubocop/options.rb +17 -12
  238. data/lib/rubocop/path_util.rb +6 -2
  239. data/lib/rubocop/rake_task.rb +1 -1
  240. data/lib/rubocop/rspec/cop_helper.rb +8 -2
  241. data/lib/rubocop/rspec/expect_offense.rb +16 -8
  242. data/lib/rubocop/rspec/shared_contexts.rb +73 -16
  243. data/lib/rubocop/rspec/support.rb +3 -0
  244. data/lib/rubocop/runner.rb +14 -3
  245. data/lib/rubocop/server/cache.rb +11 -2
  246. data/lib/rubocop/server/client_command/exec.rb +2 -3
  247. data/lib/rubocop/server/client_command/start.rb +1 -1
  248. data/lib/rubocop/server/core.rb +4 -0
  249. data/lib/rubocop/server/server_command/exec.rb +0 -1
  250. data/lib/rubocop/target_finder.rb +84 -78
  251. data/lib/rubocop/target_ruby.rb +82 -80
  252. data/lib/rubocop/version.rb +19 -4
  253. data/lib/rubocop.rb +9 -0
  254. metadata +18 -11
  255. /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
data/config/default.yml CHANGED
@@ -144,6 +144,12 @@ AllCops:
144
144
  # Ruby version is still unresolved, RuboCop will use the oldest officially
145
145
  # supported Ruby version (currently Ruby 2.7).
146
146
  TargetRubyVersion: ~
147
+ # You can specify the parser engine. There are two options available:
148
+ # - `parser_whitequark` ... https://github.com/whitequark/parser
149
+ # - `parser_prism` ... https://github.com/ruby/prism (`Prism::Translation::Parser`)
150
+ # By default, `parser` is used. For the `TargetRubyVersion` value, `parser` can be specified for versions `2.0` and above.
151
+ # `parser_prism` can be specified for versions `3.3` and above. `parser_prism` is faster but still considered experimental.
152
+ ParserEngine: parser_whitequark
147
153
  # Determines if a notification for extension libraries should be shown when
148
154
  # rubocop is run. Keys are the name of the extension, and values are an array
149
155
  # of gems in the Gemfile that the extension is suggested for, if not already
@@ -157,6 +163,7 @@ AllCops:
157
163
  rubocop-graphql: [graphql]
158
164
  rubocop-capybara: [capybara]
159
165
  rubocop-factory_bot: [factory_bot, factory_bot_rails]
166
+ rubocop-rspec_rails: [rspec-rails]
160
167
  # Enable/Disable checking the methods extended by Active Support.
161
168
  ActiveSupportExtensionsEnabled: false
162
169
 
@@ -255,6 +262,15 @@ Bundler/OrderedGems:
255
262
 
256
263
  #################### Gemspec ###############################
257
264
 
265
+ Gemspec/AddRuntimeDependency:
266
+ Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
267
+ StyleGuide: '#add_dependency_vs_add_runtime_dependency'
268
+ Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
269
+ Enabled: pending
270
+ VersionAdded: '1.65'
271
+ Include:
272
+ - '**/*.gemspec'
273
+
258
274
  Gemspec/DependencyVersion:
259
275
  Description: 'Requires or forbids specifying gem dependency versions.'
260
276
  Enabled: false
@@ -556,7 +572,9 @@ Layout/ElseAlignment:
556
572
  Layout/EmptyComment:
557
573
  Description: 'Checks empty comment.'
558
574
  Enabled: true
575
+ AutoCorrect: contextual
559
576
  VersionAdded: '0.53'
577
+ VersionChanged: '1.61'
560
578
  AllowBorderComment: true
561
579
  AllowMarginComment: true
562
580
 
@@ -1649,7 +1667,7 @@ Lint/Debugger:
1649
1667
  Description: 'Check for debugger calls.'
1650
1668
  Enabled: true
1651
1669
  VersionAdded: '0.14'
1652
- VersionChanged: '1.46'
1670
+ VersionChanged: '1.63'
1653
1671
  DebuggerMethods:
1654
1672
  # Groups are available so that a specific group can be disabled in
1655
1673
  # a user's configuration, but are otherwise not significant.
@@ -1662,8 +1680,14 @@ Lint/Debugger:
1662
1680
  - Kernel.byebug
1663
1681
  - Kernel.remote_byebug
1664
1682
  Capybara:
1683
+ - page.save_and_open_page
1684
+ - page.save_and_open_screenshot
1685
+ - page.save_page
1686
+ - page.save_screenshot
1665
1687
  - save_and_open_page
1666
1688
  - save_and_open_screenshot
1689
+ - save_page
1690
+ - save_screenshot
1667
1691
  debug.rb:
1668
1692
  - binding.b
1669
1693
  - binding.break
@@ -1685,6 +1709,10 @@ Lint/Debugger:
1685
1709
  - jard
1686
1710
  WebConsole:
1687
1711
  - binding.console
1712
+ DebuggerRequires:
1713
+ debug.rb:
1714
+ - debug/open
1715
+ - debug/start
1688
1716
 
1689
1717
  Lint/DeprecatedClassMethods:
1690
1718
  Description: 'Check for deprecated class method calls.'
@@ -1825,16 +1853,18 @@ Lint/EmptyClass:
1825
1853
  Lint/EmptyConditionalBody:
1826
1854
  Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1827
1855
  Enabled: true
1856
+ AutoCorrect: contextual
1828
1857
  SafeAutoCorrect: false
1829
1858
  AllowComments: true
1830
1859
  VersionAdded: '0.89'
1831
- VersionChanged: '1.34'
1860
+ VersionChanged: '1.61'
1832
1861
 
1833
1862
  Lint/EmptyEnsure:
1834
1863
  Description: 'Checks for empty ensure block.'
1835
1864
  Enabled: true
1865
+ AutoCorrect: contextual
1836
1866
  VersionAdded: '0.10'
1837
- VersionChanged: '0.48'
1867
+ VersionChanged: '1.61'
1838
1868
 
1839
1869
  Lint/EmptyExpression:
1840
1870
  Description: 'Checks for empty expressions.'
@@ -1856,8 +1886,9 @@ Lint/EmptyInPattern:
1856
1886
  Lint/EmptyInterpolation:
1857
1887
  Description: 'Checks for empty string interpolation.'
1858
1888
  Enabled: true
1889
+ AutoCorrect: contextual
1859
1890
  VersionAdded: '0.20'
1860
- VersionChanged: '0.45'
1891
+ VersionChanged: '1.61'
1861
1892
 
1862
1893
  Lint/EmptyWhen:
1863
1894
  Description: 'Checks for `when` branches with empty bodies.'
@@ -2395,7 +2426,9 @@ Lint/TopLevelReturnWithArgument:
2395
2426
  Lint/TrailingCommaInAttributeDeclaration:
2396
2427
  Description: 'Checks for trailing commas in attribute declarations.'
2397
2428
  Enabled: true
2429
+ AutoCorrect: contextual
2398
2430
  VersionAdded: '0.90'
2431
+ VersionChanged: '1.61'
2399
2432
 
2400
2433
  Lint/TripleQuotes:
2401
2434
  Description: 'Checks for useless triple quote constructs.'
@@ -2455,8 +2488,9 @@ Lint/UnusedBlockArgument:
2455
2488
  Description: 'Checks for unused block arguments.'
2456
2489
  StyleGuide: '#underscore-unused-vars'
2457
2490
  Enabled: true
2491
+ AutoCorrect: contextual
2458
2492
  VersionAdded: '0.21'
2459
- VersionChanged: '0.22'
2493
+ VersionChanged: '1.61'
2460
2494
  IgnoreEmptyBlocks: true
2461
2495
  AllowUnusedKeywordArguments: false
2462
2496
 
@@ -2464,8 +2498,9 @@ Lint/UnusedMethodArgument:
2464
2498
  Description: 'Checks for unused method arguments.'
2465
2499
  StyleGuide: '#underscore-unused-vars'
2466
2500
  Enabled: true
2501
+ AutoCorrect: contextual
2467
2502
  VersionAdded: '0.21'
2468
- VersionChanged: '0.81'
2503
+ VersionChanged: '1.61'
2469
2504
  AllowUnusedKeywordArguments: false
2470
2505
  IgnoreEmptyMethods: true
2471
2506
  IgnoreNotImplementedMethods: true
@@ -2489,8 +2524,9 @@ Lint/UriRegexp:
2489
2524
  Lint/UselessAccessModifier:
2490
2525
  Description: 'Checks for useless access modifiers.'
2491
2526
  Enabled: true
2527
+ AutoCorrect: contextual
2492
2528
  VersionAdded: '0.20'
2493
- VersionChanged: '0.83'
2529
+ VersionChanged: '1.61'
2494
2530
  ContextCreatingMethods: []
2495
2531
  MethodCreatingMethods: []
2496
2532
 
@@ -2498,8 +2534,9 @@ Lint/UselessAssignment:
2498
2534
  Description: 'Checks for useless assignment to a local variable.'
2499
2535
  StyleGuide: '#underscore-unused-vars'
2500
2536
  Enabled: true
2537
+ AutoCorrect: contextual
2501
2538
  VersionAdded: '0.11'
2502
- VersionChanged: '1.51'
2539
+ VersionChanged: '1.61'
2503
2540
  SafeAutoCorrect: false
2504
2541
 
2505
2542
  Lint/UselessElseWithoutRescue:
@@ -2511,8 +2548,9 @@ Lint/UselessElseWithoutRescue:
2511
2548
  Lint/UselessMethodDefinition:
2512
2549
  Description: 'Checks for useless method definitions.'
2513
2550
  Enabled: true
2551
+ AutoCorrect: contextual
2514
2552
  VersionAdded: '0.90'
2515
- VersionChanged: '0.91'
2553
+ VersionChanged: '1.61'
2516
2554
  Safe: false
2517
2555
 
2518
2556
  Lint/UselessRescue:
@@ -2535,13 +2573,17 @@ Lint/UselessSetterCall:
2535
2573
  Lint/UselessTimes:
2536
2574
  Description: 'Checks for useless `Integer#times` calls.'
2537
2575
  Enabled: true
2538
- VersionAdded: '0.91'
2539
2576
  Safe: false
2577
+ AutoCorrect: contextual
2578
+ VersionAdded: '0.91'
2579
+ VersionChanged: '1.61'
2540
2580
 
2541
2581
  Lint/Void:
2542
2582
  Description: 'Possible use of operator/literal/variable in void context.'
2543
2583
  Enabled: true
2584
+ AutoCorrect: contextual
2544
2585
  VersionAdded: '0.9'
2586
+ VersionChanged: '1.61'
2545
2587
  CheckForMethodsWithNoSideEffects: false
2546
2588
 
2547
2589
  #################### Metrics ###############################
@@ -2584,8 +2626,9 @@ Metrics/BlockNesting:
2584
2626
  StyleGuide: '#three-is-the-number-thou-shalt-count'
2585
2627
  Enabled: true
2586
2628
  VersionAdded: '0.25'
2587
- VersionChanged: '0.47'
2629
+ VersionChanged: '1.65'
2588
2630
  CountBlocks: false
2631
+ CountModifierForms: false
2589
2632
  Max: 3
2590
2633
 
2591
2634
  Metrics/ClassLength:
@@ -2740,7 +2783,8 @@ Naming/FileName:
2740
2783
  VersionChanged: '1.23'
2741
2784
  # Camel case file names listed in `AllCops:Include` and all file names listed
2742
2785
  # in `AllCops:Exclude` are excluded by default. Add extra excludes here.
2743
- Exclude: []
2786
+ Exclude:
2787
+ - Rakefile.rb
2744
2788
  # When `true`, requires that each source file should define a class or module
2745
2789
  # with a name which matches the file name (converted to ... case).
2746
2790
  # It further expects it to be nested inside modules which match the names
@@ -3056,6 +3100,7 @@ Style/AccessModifierDeclarations:
3056
3100
  - inline
3057
3101
  - group
3058
3102
  AllowModifiersOnSymbols: true
3103
+ AllowModifiersOnAttrs: true
3059
3104
  SafeAutoCorrect: false
3060
3105
 
3061
3106
  Style/AccessorGrouping:
@@ -3653,6 +3698,7 @@ Style/DocumentationMethod:
3653
3698
  Description: 'Checks for missing documentation comment for public methods.'
3654
3699
  Enabled: false
3655
3700
  VersionAdded: '0.43'
3701
+ AllowedMethods: []
3656
3702
  Exclude:
3657
3703
  - 'spec/**/*'
3658
3704
  - 'test/**/*'
@@ -3701,8 +3747,9 @@ Style/EmptyCaseCondition:
3701
3747
  Style/EmptyElse:
3702
3748
  Description: 'Avoid empty else-clauses.'
3703
3749
  Enabled: true
3750
+ AutoCorrect: contextual
3704
3751
  VersionAdded: '0.28'
3705
- VersionChanged: '0.32'
3752
+ VersionChanged: '1.61'
3706
3753
  EnforcedStyle: both
3707
3754
  # empty - warn only on empty `else`
3708
3755
  # nil - warn on `else` with nil in it
@@ -3716,7 +3763,9 @@ Style/EmptyElse:
3716
3763
  Style/EmptyHeredoc:
3717
3764
  Description: 'Checks for using empty heredoc to reduce redundancy.'
3718
3765
  Enabled: pending
3766
+ AutoCorrect: contextual
3719
3767
  VersionAdded: '1.32'
3768
+ VersionChanged: '1.61'
3720
3769
 
3721
3770
  Style/EmptyLambdaParameter:
3722
3771
  Description: 'Omit parens for empty lambda parameters.'
@@ -3734,7 +3783,9 @@ Style/EmptyMethod:
3734
3783
  Description: 'Checks the formatting of empty method definitions.'
3735
3784
  StyleGuide: '#no-single-line-methods'
3736
3785
  Enabled: true
3786
+ AutoCorrect: contextual
3737
3787
  VersionAdded: '0.46'
3788
+ VersionChanged: '1.61'
3738
3789
  EnforcedStyle: compact
3739
3790
  SupportedStyles:
3740
3791
  - compact
@@ -4029,6 +4080,8 @@ Style/HashSyntax:
4029
4080
  - either
4030
4081
  # forces use of the 3.1 syntax only if all values can be omitted in the hash.
4031
4082
  - consistent
4083
+ # allow either (implicit or explicit) syntax but enforce consistency within a single hash
4084
+ - either_consistent
4032
4085
  # Force hashes that have a symbol value to use hash rockets
4033
4086
  UseHashRocketsWithSymbolValues: false
4034
4087
  # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
@@ -4249,6 +4302,13 @@ Style/MapCompactWithConditionalBlock:
4249
4302
  Enabled: pending
4250
4303
  VersionAdded: '1.30'
4251
4304
 
4305
+ Style/MapIntoArray:
4306
+ Description: 'Checks for usages of `each` with `<<`, `push`, or `append` which can be replaced by `map`.'
4307
+ StyleGuide: '#functional-code'
4308
+ Enabled: pending
4309
+ VersionAdded: '1.63'
4310
+ Safe: false
4311
+
4252
4312
  Style/MapToHash:
4253
4313
  Description: 'Prefer `to_h` with a block over `map.to_h`.'
4254
4314
  Enabled: pending
@@ -4712,6 +4772,7 @@ Style/OperatorMethodCall:
4712
4772
 
4713
4773
  Style/OptionHash:
4714
4774
  Description: "Don't use option hashes when you can use keyword arguments."
4775
+ StyleGuide: '#keyword-arguments-vs-option-hashes'
4715
4776
  Enabled: false
4716
4777
  VersionAdded: '0.33'
4717
4778
  VersionChanged: '0.34'
@@ -4834,8 +4895,9 @@ Style/RaiseArgs:
4834
4895
  Description: 'Checks the arguments passed to raise/fail.'
4835
4896
  StyleGuide: '#exception-class-messages'
4836
4897
  Enabled: true
4898
+ Safe: false
4837
4899
  VersionAdded: '0.14'
4838
- VersionChanged: '1.2'
4900
+ VersionChanged: '1.61'
4839
4901
  EnforcedStyle: exploded
4840
4902
  SupportedStyles:
4841
4903
  - compact # raise Exception.new(msg)
@@ -4976,10 +5038,11 @@ Style/RedundantHeredocDelimiterQuotes:
4976
5038
  Style/RedundantInitialize:
4977
5039
  Description: 'Checks for redundant `initialize` methods.'
4978
5040
  Enabled: pending
5041
+ AutoCorrect: contextual
4979
5042
  Safe: false
4980
5043
  AllowComments: true
4981
5044
  VersionAdded: '1.27'
4982
- VersionChanged: '1.28'
5045
+ VersionChanged: '1.61'
4983
5046
 
4984
5047
  Style/RedundantInterpolation:
4985
5048
  Description: 'Checks for strings that are just an interpolated expression.'
@@ -5191,6 +5254,13 @@ Style/Send:
5191
5254
  Enabled: false
5192
5255
  VersionAdded: '0.33'
5193
5256
 
5257
+ Style/SendWithLiteralMethodName:
5258
+ Description: 'Detects the use of the `public_send` method with a static method name argument.'
5259
+ Enabled: pending
5260
+ Safe: false
5261
+ AllowSend: true
5262
+ VersionAdded: '1.64'
5263
+
5194
5264
  Style/SignalException:
5195
5265
  Description: 'Checks for proper usage of fail and raise.'
5196
5266
  StyleGuide: '#prefer-raise-over-fail'
@@ -5237,7 +5307,8 @@ Style/SingleLineMethods:
5237
5307
  AllowIfMethodIsEmpty: true
5238
5308
 
5239
5309
  Style/SlicingWithRange:
5240
- Description: 'Checks array slicing is done with endless ranges when suitable.'
5310
+ Description: 'Checks array slicing is done with redundant, endless, and beginless ranges when suitable.'
5311
+ StyleGuide: '#slicing-with-ranges'
5241
5312
  Enabled: true
5242
5313
  VersionAdded: '0.83'
5243
5314
  Safe: false
@@ -5364,6 +5435,11 @@ Style/StructInheritance:
5364
5435
  VersionAdded: '0.29'
5365
5436
  VersionChanged: '1.20'
5366
5437
 
5438
+ Style/SuperArguments:
5439
+ Description: 'Call `super` without arguments and parentheses when the signature is identical.'
5440
+ Enabled: pending
5441
+ VersionAdded: '1.64'
5442
+
5367
5443
  Style/SuperWithArgsParentheses:
5368
5444
  Description: 'Use parentheses for `super` with arguments.'
5369
5445
  StyleGuide: '#super-with-args'
@@ -5399,7 +5475,7 @@ Style/SymbolProc:
5399
5475
  Enabled: true
5400
5476
  Safe: false
5401
5477
  VersionAdded: '0.26'
5402
- VersionChanged: '1.40'
5478
+ VersionChanged: '1.64'
5403
5479
  AllowMethodsWithArguments: false
5404
5480
  # A list of method names to be always allowed by the check.
5405
5481
  # The names should be fairly unique, otherwise you'll end up ignoring lots of code.
@@ -48,11 +48,19 @@ module RuboCop
48
48
  source_buffer = Parser::Source::Buffer.new(@filename)
49
49
  source_buffer.source = File.read(@filename, encoding: Encoding::UTF_8)
50
50
  offenses.map! do |o|
51
- location = Parser::Source::Range.new(source_buffer,
52
- o['location']['begin_pos'],
53
- o['location']['end_pos'])
51
+ location = location_from_source_buffer(o, source_buffer)
54
52
  Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym)
55
53
  end
56
54
  end
55
+
56
+ def location_from_source_buffer(offense, source_buffer)
57
+ begin_pos = offense['location']['begin_pos']
58
+ end_pos = offense['location']['end_pos']
59
+ if begin_pos.zero? && end_pos.zero?
60
+ Cop::Offense::NO_LOCATION
61
+ else
62
+ Parser::Source::Range.new(source_buffer, begin_pos, end_pos)
63
+ end
64
+ end
57
65
  end
58
66
  end
@@ -17,7 +17,10 @@ module RuboCop
17
17
 
18
18
  PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
19
19
  PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
20
- PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
20
+ PHASE_1_SKIPPED_ONLY_COPS =
21
+ '(skipped because a list of cops is passed to the `--only` flag)'
22
+ PHASE_1_SKIPPED_ONLY_EXCLUDE =
23
+ '(skipped because only excludes will be generated due to `--auto-gen-only-exclude` flag)'
21
24
 
22
25
  def run
23
26
  add_formatter
@@ -29,12 +32,14 @@ module RuboCop
29
32
  private
30
33
 
31
34
  def maybe_run_line_length_cop
32
- if !line_length_enabled?(@config_store.for_pwd)
35
+ if only_exclude?
36
+ skip_line_length_cop(PHASE_1_SKIPPED_ONLY_EXCLUDE)
37
+ elsif !line_length_enabled?(@config_store.for_pwd)
33
38
  skip_line_length_cop(PHASE_1_DISABLED)
34
39
  elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
35
40
  skip_line_length_cop(PHASE_1_OVERRIDDEN)
36
41
  elsif options_has_only_flag?
37
- skip_line_length_cop(PHASE_1_SKIPPED)
42
+ skip_line_length_cop(PHASE_1_SKIPPED_ONLY_COPS)
38
43
  else
39
44
  run_line_length_cop
40
45
  end
@@ -65,6 +70,10 @@ module RuboCop
65
70
  @options[:only]
66
71
  end
67
72
 
73
+ def only_exclude?
74
+ @options[:auto_gen_only_exclude]
75
+ end
76
+
68
77
  # Do an initial run with only Layout/LineLength so that cops that
69
78
  # depend on Layout/LineLength:Max get the correct value for that
70
79
  # parameter.
@@ -7,11 +7,11 @@ module RuboCop
7
7
  module Command
8
8
  # Start Language Server Protocol of RuboCop.
9
9
  # @api private
10
- class Lsp < Base
10
+ class LSP < Base
11
11
  self.command_name = :lsp
12
12
 
13
13
  def run
14
- RuboCop::Lsp::Server.new(@config_store).start
14
+ RuboCop::LSP::Server.new(@config_store).start
15
15
  end
16
16
  end
17
17
  end
@@ -26,10 +26,10 @@ module RuboCop
26
26
 
27
27
  cops_array.each do |cop_name|
28
28
  cop = registry_hash[cop_name]
29
-
30
29
  next if cop.empty?
31
30
 
32
- puts Cop::Documentation.url_for(cop.first, @config)
31
+ url = Cop::Documentation.url_for(cop.first, @config)
32
+ puts url if url
33
33
  end
34
34
 
35
35
  puts
data/lib/rubocop/cli.rb CHANGED
@@ -12,7 +12,7 @@ module RuboCop
12
12
  STATUS_INTERRUPTED = Signal.list['INT'] + 128
13
13
  DEFAULT_PARALLEL_OPTIONS = %i[
14
14
  color config debug display_style_guide display_time display_only_fail_level_offenses
15
- display_only_failed except extra_details fail_level fix_layout format
15
+ display_only_failed editor_mode except extra_details fail_level fix_layout format
16
16
  ignore_disable_comments lint only only_guide_cops require safe
17
17
  autocorrect safe_autocorrect autocorrect_all
18
18
  ].freeze
@@ -57,6 +57,10 @@ module RuboCop
57
57
  rescue RuboCop::Error => e
58
58
  warn Rainbow("Error: #{e.message}").red
59
59
  STATUS_ERROR
60
+ rescue Interrupt
61
+ warn ''
62
+ warn 'Exiting...'
63
+ STATUS_INTERRUPTED
60
64
  rescue Finished
61
65
  STATUS_SUCCESS
62
66
  rescue OptionParser::InvalidOption => e
@@ -151,6 +155,7 @@ module RuboCop
151
155
 
152
156
  def act_on_options
153
157
  set_options_to_config_loader
158
+ handle_editor_mode
154
159
 
155
160
  @config_store.options_config = @options[:config] if @options[:config]
156
161
  @config_store.force_default_config! if @options[:force_default_config]
@@ -174,6 +179,10 @@ module RuboCop
174
179
  ConfigLoader.ignore_unrecognized_cops = @options[:ignore_unrecognized_cops]
175
180
  end
176
181
 
182
+ def handle_editor_mode
183
+ RuboCop::LSP.enable if @options[:editor_mode]
184
+ end
185
+
177
186
  # rubocop:disable Metrics/CyclomaticComplexity
178
187
  def handle_exiting_options
179
188
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
-
5
3
  # FIXME: Moving Rails department code to RuboCop Rails will remove
6
4
  # the following rubocop:disable comment.
7
5
  # rubocop:disable Metrics/ClassLength
@@ -246,6 +244,10 @@ module RuboCop
246
244
  end
247
245
  end
248
246
 
247
+ def parser_engine
248
+ @parser_engine ||= for_all_cops.fetch('ParserEngine', :parser_whitequark).to_sym
249
+ end
250
+
249
251
  def target_rails_version
250
252
  @target_rails_version ||=
251
253
  if for_all_cops['TargetRailsVersion']
@@ -261,6 +263,7 @@ module RuboCop
261
263
  PathUtil.smart_path(@loaded_path)
262
264
  end
263
265
 
266
+ # @return [String, nil]
264
267
  def bundler_lock_file_path
265
268
  return nil unless loaded_path
266
269
 
@@ -284,27 +287,48 @@ module RuboCop
284
287
  end
285
288
  end
286
289
 
290
+ # Returns target's locked gem versions (i.e. from Gemfile.lock or gems.locked)
291
+ # @returns [Hash{String => Gem::Version}] The locked gem versions, keyed by the gems' names.
292
+ def gem_versions_in_target
293
+ @gem_versions_in_target ||= read_gem_versions_from_target_lockfile
294
+ end
295
+
287
296
  def inspect # :nodoc:
288
297
  "#<#{self.class.name}:#{object_id} @loaded_path=#{loaded_path}>"
289
298
  end
290
299
 
291
300
  private
292
301
 
302
+ # @return [Float, nil] The Rails version as a `major.minor` Float.
293
303
  def target_rails_version_from_bundler_lock_file
294
304
  @target_rails_version_from_bundler_lock_file ||= read_rails_version_from_bundler_lock_file
295
305
  end
296
306
 
307
+ # @return [Float, nil] The Rails version as a `major.minor` Float.
297
308
  def read_rails_version_from_bundler_lock_file
298
- lock_file_path = bundler_lock_file_path
299
- return nil unless lock_file_path
300
-
301
- File.foreach(lock_file_path) do |line|
302
- # If Rails (or one of its frameworks) is in Gemfile.lock or gems.lock, there should be
303
- # a line like:
304
- # railties (X.X.X)
305
- result = line.match(/^\s+railties\s+\((\d+\.\d+)/)
306
- return result.captures.first.to_f if result
307
- end
309
+ return nil unless gem_versions_in_target
310
+
311
+ # Look for `railties` instead of `rails`, to support apps that only use a subset of `rails`
312
+ # See https://github.com/rubocop/rubocop/pull/11289
313
+ rails_version_in_target = gem_versions_in_target['railties']
314
+ return nil unless rails_version_in_target
315
+
316
+ gem_version_to_major_minor_float(rails_version_in_target)
317
+ end
318
+
319
+ # @param [Gem::Version] gem_version an object like `Gem::Version.new("7.1.2.3")`
320
+ # @return [Float] The major and minor version, like `7.1`
321
+ def gem_version_to_major_minor_float(gem_version)
322
+ segments = gem_version.segments
323
+ Float("#{segments[0]}.#{segments[1]}")
324
+ end
325
+
326
+ # @returns [Hash{String => Gem::Version}] The locked gem versions, keyed by the gems' names.
327
+ def read_gem_versions_from_target_lockfile
328
+ lockfile_path = bundler_lock_file_path
329
+ return nil unless lockfile_path
330
+
331
+ Lockfile.new(lockfile_path).gem_versions
308
332
  end
309
333
 
310
334
  def enable_cop?(qualified_cop_name, cop_options)
@@ -17,8 +17,8 @@ module RuboCop
17
17
  attr_writer :project_root
18
18
 
19
19
  def find_config_path(target_dir)
20
- find_project_dotfile(target_dir) || find_user_dotfile || find_user_xdg_config ||
21
- DEFAULT_FILE
20
+ find_project_dotfile(target_dir) || find_project_root_dot_config ||
21
+ find_user_dotfile || find_user_xdg_config || DEFAULT_FILE
22
22
  end
23
23
 
24
24
  # Returns the path RuboCop inferred as the root of the project. No file
@@ -41,6 +41,16 @@ module RuboCop
41
41
  find_file_upwards(DOTFILE, target_dir, project_root)
42
42
  end
43
43
 
44
+ def find_project_root_dot_config
45
+ return unless project_root
46
+
47
+ dotfile = File.join(project_root, '.config', DOTFILE)
48
+ return dotfile if File.exist?(dotfile)
49
+
50
+ xdg_config = File.join(project_root, '.config', 'rubocop', XDG_CONFIG)
51
+ xdg_config if File.exist?(xdg_config)
52
+ end
53
+
44
54
  def find_user_dotfile
45
55
  return unless ENV.key?('HOME')
46
56
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'erb'
4
- require 'pathname'
5
4
  require 'yaml'
6
5
  require_relative 'config_finder'
7
6
 
@@ -165,7 +164,7 @@ module RuboCop
165
164
  # searches will go past this directory.
166
165
  # @deprecated Use `RuboCop::ConfigFinder.project_root` instead.
167
166
  def project_root
168
- warn Rainbow(<<~WARNING).yellow
167
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
169
168
  `RuboCop::ConfigLoader.project_root` is deprecated and will be removed in RuboCop 2.0. \
170
169
  Use `RuboCop::ConfigFinder.project_root` instead.
171
170
  WARNING
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  module RuboCop
7
7
  # A help class for ConfigLoader that handles configuration resolution.
8
8
  # @api private
9
- class ConfigLoaderResolver
9
+ class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
10
10
  def resolve_requires(path, hash)
11
11
  config_dir = File.dirname(path)
12
12
  hash.delete('require').tap do |loaded_features|
@@ -267,8 +267,14 @@ module RuboCop
267
267
 
268
268
  def gem_config_path(gem_name, relative_config_path)
269
269
  if defined?(Bundler)
270
- gem = Bundler.load.specs[gem_name].first
271
- gem_path = gem.full_gem_path if gem
270
+ begin
271
+ gem = Bundler.load.specs[gem_name].first
272
+ gem_path = gem.full_gem_path if gem
273
+ rescue Bundler::GemfileNotFound
274
+ # No Gemfile found. Bundler may be loaded manually
275
+ rescue Bundler::GitError
276
+ # The Gemfile exists but contains an uninstalled git source
277
+ end
272
278
  end
273
279
 
274
280
  gem_path ||= Gem::Specification.find_by_name(gem_name).gem_dir
@@ -52,7 +52,7 @@ module RuboCop
52
52
  def load_rules # rubocop:disable Metrics/AbcSize
53
53
  rules = LOAD_RULES_CACHE[self.class.files] ||=
54
54
  self.class.files.each_with_object({}) do |filename, hash|
55
- hash.merge!(YAML.safe_load(File.read(filename))) do |_key, first, second|
55
+ hash.merge!(YAML.safe_load(File.read(filename)) || {}) do |_key, first, second|
56
56
  case first
57
57
  when Hash
58
58
  first.merge(second)