rubocop 0.72.0 → 0.76.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/bin/console +1 -0
  4. data/config/default.yml +93 -56
  5. data/lib/rubocop.rb +21 -10
  6. data/lib/rubocop/ast/builder.rb +1 -0
  7. data/lib/rubocop/ast/node.rb +12 -14
  8. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +4 -4
  9. data/lib/rubocop/ast/node/return_node.rb +24 -0
  10. data/lib/rubocop/ast/traversal.rb +3 -3
  11. data/lib/rubocop/cli.rb +7 -4
  12. data/lib/rubocop/comment_config.rb +5 -4
  13. data/lib/rubocop/config.rb +28 -537
  14. data/lib/rubocop/config_loader.rb +21 -3
  15. data/lib/rubocop/config_loader_resolver.rb +4 -3
  16. data/lib/rubocop/config_obsoletion.rb +222 -0
  17. data/lib/rubocop/config_validator.rb +248 -0
  18. data/lib/rubocop/cop/autocorrect_logic.rb +71 -1
  19. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  20. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  21. data/lib/rubocop/cop/commissioner.rb +18 -16
  22. data/lib/rubocop/cop/cop.rb +49 -14
  23. data/lib/rubocop/cop/corrector.rb +10 -10
  24. data/lib/rubocop/cop/correctors/alignment_corrector.rb +43 -17
  25. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +2 -2
  26. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
  27. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  28. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  29. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  30. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  31. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  32. data/lib/rubocop/cop/generator.rb +4 -4
  33. data/lib/rubocop/cop/generator/configuration_injector.rb +9 -4
  34. data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
  35. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -2
  36. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  37. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -2
  38. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
  39. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +2 -2
  40. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
  41. data/lib/rubocop/cop/layout/align_hash.rb +6 -2
  42. data/lib/rubocop/cop/layout/block_alignment.rb +3 -3
  43. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  44. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  45. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  46. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  47. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
  48. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
  49. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
  50. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  51. data/lib/rubocop/cop/layout/extra_spacing.rb +14 -59
  52. data/lib/rubocop/cop/layout/indent_assignment.rb +10 -1
  53. data/lib/rubocop/cop/layout/indent_first_argument.rb +10 -8
  54. data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
  55. data/lib/rubocop/cop/layout/indent_heredoc.rb +4 -3
  56. data/lib/rubocop/cop/layout/indentation_width.rb +20 -6
  57. data/lib/rubocop/cop/layout/leading_comment_space.rb +28 -0
  58. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_block_layout.rb +24 -2
  60. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +20 -4
  61. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +5 -1
  62. data/lib/rubocop/cop/layout/space_around_operators.rb +42 -23
  63. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  64. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +8 -5
  65. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +21 -2
  66. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  67. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +24 -40
  68. data/lib/rubocop/cop/layout/tab.rb +10 -22
  69. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  70. data/lib/rubocop/cop/lint/assignment_in_condition.rb +17 -4
  71. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -1
  72. data/lib/rubocop/cop/lint/debugger.rb +4 -6
  73. data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -3
  74. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  75. data/lib/rubocop/cop/lint/empty_interpolation.rb +4 -4
  76. data/lib/rubocop/cop/lint/erb_new_arguments.rb +62 -5
  77. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +11 -37
  78. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  79. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  80. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +7 -8
  81. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  82. data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
  83. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
  84. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  85. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  86. data/lib/rubocop/cop/lint/number_conversion.rb +3 -3
  87. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  88. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +24 -24
  89. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
  90. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +2 -2
  91. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +12 -7
  92. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  93. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
  94. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +10 -11
  95. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  96. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +91 -0
  97. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -6
  98. data/lib/rubocop/cop/lint/unified_integer.rb +1 -1
  99. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  100. data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
  101. data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
  102. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
  103. data/lib/rubocop/cop/lint/uri_regexp.rb +2 -2
  104. data/lib/rubocop/cop/lint/useless_access_modifier.rb +6 -6
  105. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  106. data/lib/rubocop/cop/lint/void.rb +7 -26
  107. data/lib/rubocop/cop/message_annotator.rb +16 -7
  108. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  109. data/lib/rubocop/cop/metrics/class_length.rb +1 -1
  110. data/lib/rubocop/cop/metrics/line_length.rb +7 -4
  111. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  112. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  113. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  114. data/lib/rubocop/cop/migration/department_name.rb +44 -0
  115. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  116. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  117. data/lib/rubocop/cop/mixin/documentation_comment.rb +0 -2
  118. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -1
  119. data/lib/rubocop/cop/mixin/enforce_superclass.rb +4 -4
  120. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  121. data/lib/rubocop/cop/mixin/interpolation.rb +27 -0
  122. data/lib/rubocop/cop/mixin/method_complexity.rb +3 -2
  123. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
  124. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +87 -0
  125. data/lib/rubocop/cop/mixin/safe_mode.rb +2 -0
  126. data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
  127. data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -5
  128. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
  129. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  130. data/lib/rubocop/cop/naming/constant_name.rb +2 -2
  131. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  132. data/lib/rubocop/cop/naming/method_name.rb +12 -1
  133. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  134. data/lib/rubocop/cop/naming/variable_name.rb +1 -0
  135. data/lib/rubocop/cop/offense.rb +18 -7
  136. data/lib/rubocop/cop/registry.rb +22 -1
  137. data/lib/rubocop/cop/security/eval.rb +1 -1
  138. data/lib/rubocop/cop/security/json_load.rb +1 -1
  139. data/lib/rubocop/cop/security/marshal_load.rb +1 -1
  140. data/lib/rubocop/cop/security/open.rb +1 -1
  141. data/lib/rubocop/cop/security/yaml_load.rb +1 -1
  142. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
  143. data/lib/rubocop/cop/style/alias.rb +1 -1
  144. data/lib/rubocop/cop/style/attr.rb +2 -2
  145. data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
  146. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +35 -16
  147. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  148. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  149. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  150. data/lib/rubocop/cop/style/commented_keyword.rb +16 -30
  151. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -8
  152. data/lib/rubocop/cop/style/constant_visibility.rb +14 -3
  153. data/lib/rubocop/cop/style/copyright.rb +11 -7
  154. data/lib/rubocop/cop/style/date_time.rb +3 -3
  155. data/lib/rubocop/cop/style/dir.rb +1 -1
  156. data/lib/rubocop/cop/style/documentation_method.rb +45 -1
  157. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +55 -0
  158. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  159. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  160. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  161. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  162. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  163. data/lib/rubocop/cop/style/eval_with_location.rb +2 -2
  164. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  165. data/lib/rubocop/cop/style/expand_path_arguments.rb +4 -4
  166. data/lib/rubocop/cop/style/float_division.rb +4 -4
  167. data/lib/rubocop/cop/style/format_string.rb +17 -14
  168. data/lib/rubocop/cop/style/format_string_token.rb +19 -68
  169. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +28 -33
  170. data/lib/rubocop/cop/style/guard_clause.rb +39 -10
  171. data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
  172. data/lib/rubocop/cop/style/if_unless_modifier.rb +58 -15
  173. data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
  174. data/lib/rubocop/cop/style/inverse_methods.rb +21 -15
  175. data/lib/rubocop/cop/style/lambda.rb +0 -2
  176. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  177. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +25 -25
  178. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  179. data/lib/rubocop/cop/style/min_max.rb +1 -1
  180. data/lib/rubocop/cop/style/mixin_usage.rb +12 -2
  181. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  182. data/lib/rubocop/cop/style/multiline_when_then.rb +55 -0
  183. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
  184. data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
  185. data/lib/rubocop/cop/style/nested_modifier.rb +22 -4
  186. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  187. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -3
  188. data/lib/rubocop/cop/style/option_hash.rb +1 -1
  189. data/lib/rubocop/cop/style/or_assignment.rb +8 -3
  190. data/lib/rubocop/cop/style/parentheses_around_condition.rb +15 -1
  191. data/lib/rubocop/cop/style/random_with_offset.rb +6 -6
  192. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  193. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  194. data/lib/rubocop/cop/style/redundant_conditional.rb +2 -2
  195. data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
  196. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  197. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  198. data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -6
  199. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  200. data/lib/rubocop/cop/style/redundant_return.rb +37 -21
  201. data/lib/rubocop/cop/style/redundant_self.rb +18 -1
  202. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
  203. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
  204. data/lib/rubocop/cop/style/rescue_modifier.rb +24 -0
  205. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
  206. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  207. data/lib/rubocop/cop/style/safe_navigation.rb +24 -4
  208. data/lib/rubocop/cop/style/sample.rb +1 -1
  209. data/lib/rubocop/cop/style/semicolon.rb +13 -2
  210. data/lib/rubocop/cop/style/single_line_methods.rb +8 -1
  211. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  212. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  213. data/lib/rubocop/cop/style/string_hash_keys.rb +2 -2
  214. data/lib/rubocop/cop/style/strip.rb +1 -1
  215. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
  216. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  217. data/lib/rubocop/cop/style/ternary_parentheses.rb +20 -1
  218. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +4 -6
  219. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  220. data/lib/rubocop/cop/style/unpack_first.rb +1 -1
  221. data/lib/rubocop/cop/style/variable_interpolation.rb +6 -16
  222. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -5
  223. data/lib/rubocop/cop/team.rb +15 -14
  224. data/lib/rubocop/cop/util.rb +1 -1
  225. data/lib/rubocop/cop/utils/format_string.rb +120 -0
  226. data/lib/rubocop/cop/variable_force.rb +7 -5
  227. data/lib/rubocop/cop/variable_force/variable.rb +15 -2
  228. data/lib/rubocop/core_ext/string.rb +0 -24
  229. data/lib/rubocop/error.rb +23 -0
  230. data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
  231. data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -9
  232. data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
  233. data/lib/rubocop/formatter/formatter_set.rb +16 -15
  234. data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
  235. data/lib/rubocop/formatter/simple_text_formatter.rb +16 -4
  236. data/lib/rubocop/formatter/tap_formatter.rb +17 -4
  237. data/lib/rubocop/magic_comment.rb +4 -0
  238. data/lib/rubocop/node_pattern.rb +5 -3
  239. data/lib/rubocop/options.rb +33 -21
  240. data/lib/rubocop/path_util.rb +1 -1
  241. data/lib/rubocop/processed_source.rb +4 -0
  242. data/lib/rubocop/result_cache.rb +1 -1
  243. data/lib/rubocop/rspec/expect_offense.rb +4 -1
  244. data/lib/rubocop/rspec/shared_contexts.rb +12 -0
  245. data/lib/rubocop/runner.rb +42 -31
  246. data/lib/rubocop/target_finder.rb +12 -4
  247. data/lib/rubocop/version.rb +1 -1
  248. metadata +21 -12
  249. data/lib/rubocop/cop/mixin/ignored_method_patterns.rb +0 -19
@@ -220,7 +220,7 @@ module RuboCop
220
220
 
221
221
  private
222
222
 
223
- def_node_matcher :macro_scope?, <<-PATTERN
223
+ def_node_matcher :macro_scope?, <<~PATTERN
224
224
  {^{({sclass class module block} ...) class_constructor?}
225
225
  ^^{({sclass class module block} ... ({begin if} ...)) class_constructor?}
226
226
  ^#macro_kwbegin_wrapper?
@@ -245,15 +245,15 @@ module RuboCop
245
245
  node.parent.nil?
246
246
  end
247
247
 
248
- def_node_matcher :adjacent_def_modifier?, <<-PATTERN
248
+ def_node_matcher :adjacent_def_modifier?, <<~PATTERN
249
249
  (send nil? _ ({def defs} ...))
250
250
  PATTERN
251
251
 
252
- def_node_matcher :bare_access_modifier_declaration?, <<-PATTERN
252
+ def_node_matcher :bare_access_modifier_declaration?, <<~PATTERN
253
253
  (send nil? {:public :protected :private :module_function})
254
254
  PATTERN
255
255
 
256
- def_node_matcher :non_bare_access_modifier_declaration?, <<-PATTERN
256
+ def_node_matcher :non_bare_access_modifier_declaration?, <<~PATTERN
257
257
  (send nil? {:public :protected :private :module_function} _)
258
258
  PATTERN
259
259
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `return` nodes. This will be used in place of a
6
+ # plain node when the builder constructs the AST, making its methods
7
+ # available to all `return` nodes within RuboCop.
8
+ class ReturnNode < Node
9
+ include MethodDispatchNode
10
+ include ParameterizedNode
11
+
12
+ # Returns the arguments of the `return`.
13
+ #
14
+ # @return [Array] The arguments of the `return`.
15
+ def arguments
16
+ if node_parts.one? && node_parts.first.begin_type?
17
+ node_parts.first.children
18
+ else
19
+ node_parts
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -35,7 +35,7 @@ module RuboCop
35
35
  end
36
36
 
37
37
  ONE_CHILD_NODE.each do |type|
38
- module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
38
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
39
39
  def on_#{type}(node)
40
40
  if (child = node.children[0])
41
41
  send(:"on_\#{child.type}", child)
@@ -45,7 +45,7 @@ module RuboCop
45
45
  end
46
46
 
47
47
  MANY_CHILD_NODES.each do |type|
48
- module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
48
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
49
49
  def on_#{type}(node)
50
50
  node.children.each { |child| send(:"on_\#{child.type}", child) }
51
51
  nil
@@ -55,7 +55,7 @@ module RuboCop
55
55
 
56
56
  SECOND_CHILD_ONLY.each do |type|
57
57
  # Guard clause is for nodes nested within mlhs
58
- module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
58
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
59
59
  def on_#{type}(node)
60
60
  if (child = node.children[1])
61
61
  send(:"on_\#{child.type}", child)
@@ -83,18 +83,21 @@ module RuboCop
83
83
 
84
84
  def maybe_run_line_length_cop(paths)
85
85
  if !line_length_enabled?(@config_store.for(Dir.pwd))
86
- puts Rainbow("#{PHASE_1} #{PHASE_1_DISABLED}").yellow
87
- ''
86
+ skip_line_length_cop(PHASE_1_DISABLED)
88
87
  elsif !same_max_line_length?(
89
88
  @config_store.for(Dir.pwd), ConfigLoader.default_configuration
90
89
  )
91
- puts Rainbow("#{PHASE_1} #{PHASE_1_OVERRIDDEN}").yellow
92
- ''
90
+ skip_line_length_cop(PHASE_1_OVERRIDDEN)
93
91
  else
94
92
  run_line_length_cop_auto_gen_config(paths)
95
93
  end
96
94
  end
97
95
 
96
+ def skip_line_length_cop(reason)
97
+ puts Rainbow("#{PHASE_1} #{reason}").yellow
98
+ ''
99
+ end
100
+
98
101
  def line_length_enabled?(config)
99
102
  line_length_cop(config)['Enabled']
100
103
  end
@@ -4,14 +4,15 @@ module RuboCop
4
4
  # This class parses the special `rubocop:disable` comments in a source
5
5
  # and provides a way to check if each cop is enabled at arbitrary line.
6
6
  class CommentConfig
7
- UNNEEDED_DISABLE = 'Lint/UnneededCopDisableDirective'
7
+ REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
8
8
 
9
9
  COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)'
10
10
  COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
11
11
  COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
12
12
 
13
13
  COMMENT_DIRECTIVE_REGEXP = Regexp.new(
14
- ('# rubocop : ((?:dis|en)able)\b ' + COPS_PATTERN).gsub(' ', '\s*')
14
+ ('# rubocop : ((?:disable|enable|todo))\b ' + COPS_PATTERN)
15
+ .gsub(' ', '\s*')
15
16
  )
16
17
 
17
18
  CopAnalysis = Struct.new(:line_ranges, :start_line_number)
@@ -141,7 +142,7 @@ module RuboCop
141
142
  cop_names =
142
143
  cops_string == 'all' ? all_cop_names : cops_string.split(/,\s*/)
143
144
 
144
- disabled = (switch == 'disable')
145
+ disabled = %w[disable todo].include?(switch)
145
146
 
146
147
  [cop_names, disabled]
147
148
  end
@@ -151,7 +152,7 @@ module RuboCop
151
152
  end
152
153
 
153
154
  def all_cop_names
154
- @all_cop_names ||= Cop::Cop.registry.names - [UNNEEDED_DISABLE]
155
+ @all_cop_names ||= Cop::Cop.registry.names - [REDUNDANT_DISABLE]
155
156
  end
156
157
 
157
158
  def comment_only_line?(line_number)
@@ -8,237 +8,12 @@ module RuboCop
8
8
  # file from which it was read. Several different Configs can be used
9
9
  # during a run of the rubocop program, if files in several
10
10
  # directories are inspected.
11
-
12
- # rubocop:disable Metrics/ClassLength
13
11
  class Config
14
12
  include PathUtil
15
13
  include FileFinder
14
+ extend Forwardable
16
15
 
17
- COMMON_PARAMS = %w[Exclude Include Severity inherit_mode
18
- AutoCorrect StyleGuide Details].freeze
19
- INTERNAL_PARAMS = %w[Description StyleGuide VersionAdded
20
- VersionChanged Reference Safe SafeAutoCorrect].freeze
21
-
22
- # 2.3 is the oldest officially supported Ruby version.
23
- DEFAULT_RUBY_VERSION = 2.3
24
- KNOWN_RUBIES = [2.3, 2.4, 2.5, 2.6, 2.7].freeze
25
- OBSOLETE_RUBIES = {
26
- 1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58', 2.2 => '0.69'
27
- }.freeze
28
- RUBY_VERSION_FILENAME = '.ruby-version'
29
16
  DEFAULT_RAILS_VERSION = 5.0
30
- OBSOLETE_COPS = {
31
- 'Style/FlipFlop' =>
32
- 'The `Style/FlipFlop` cop has been moved to `Lint/FlipFlop`.',
33
- 'Style/TrailingComma' =>
34
- 'The `Style/TrailingComma` cop no longer exists. Please use ' \
35
- '`Style/TrailingCommaInArguments`, ' \
36
- '`Style/TrailingCommaInArrayLiteral`, and/or ' \
37
- '`Style/TrailingCommaInHashLiteral` instead.',
38
- 'Style/TrailingCommaInLiteral' =>
39
- 'The `Style/TrailingCommaInLiteral` cop no longer exists. Please use ' \
40
- '`Style/TrailingCommaInArrayLiteral` and/or ' \
41
- '`Style/TrailingCommaInHashLiteral` instead.',
42
- 'Rails/DefaultScope' =>
43
- 'The `Rails/DefaultScope` cop no longer exists.',
44
- 'Lint/InvalidCharacterLiteral' =>
45
- 'The `Lint/InvalidCharacterLiteral` cop has been removed since it ' \
46
- 'was never being actually triggered.',
47
- 'Style/SingleSpaceBeforeFirstArg' =>
48
- 'The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to ' \
49
- '`Layout/SpaceBeforeFirstArg`.',
50
- 'Lint/RescueWithoutErrorClass' =>
51
- 'The `Lint/RescueWithoutErrorClass` cop has been replaced by ' \
52
- '`Style/RescueStandardError`.',
53
- 'Lint/SpaceBeforeFirstArg' =>
54
- 'The `Lint/SpaceBeforeFirstArg` cop has been removed, since it was a ' \
55
- 'duplicate of `Layout/SpaceBeforeFirstArg`. Please use ' \
56
- '`Layout/SpaceBeforeFirstArg` instead.',
57
- 'Layout/FirstParameterIndentation' =>
58
- 'The `Layout/FirstParameterIndentation` cop has been renamed to ' \
59
- '`Layout/IndentFirstArgument`.',
60
- 'Layout/IndentArray' =>
61
- 'The `Layout/IndentArray` cop has been renamed to ' \
62
- '`Layout/IndentFirstArrayElement`.',
63
- 'Layout/IndentHash' =>
64
- 'The `Layout/IndentHash` cop has been renamed to ' \
65
- '`Layout/IndentFirstHashElement`.',
66
- 'Layout/SpaceAfterControlKeyword' =>
67
- 'The `Layout/SpaceAfterControlKeyword` cop has been removed. Please ' \
68
- 'use `Layout/SpaceAroundKeyword` instead.',
69
- 'Layout/SpaceBeforeModifierKeyword' =>
70
- 'The `Layout/SpaceBeforeModifierKeyword` cop has been removed. ' \
71
- 'Please use `Layout/SpaceAroundKeyword` instead.',
72
- 'Style/SpaceAfterControlKeyword' =>
73
- 'The `Style/SpaceAfterControlKeyword` cop has been removed. Please ' \
74
- 'use `Layout/SpaceAroundKeyword` instead.',
75
- 'Style/SpaceBeforeModifierKeyword' =>
76
- 'The `Style/SpaceBeforeModifierKeyword` cop has been removed. Please ' \
77
- 'use `Layout/SpaceAroundKeyword` instead.',
78
- 'Style/MethodCallParentheses' =>
79
- 'The `Style/MethodCallParentheses` cop has been renamed to ' \
80
- '`Style/MethodCallWithoutArgsParentheses`.',
81
- 'Lint/Eval' =>
82
- 'The `Lint/Eval` cop has been renamed to `Security/Eval`.',
83
- 'Style/DeprecatedHashMethods' =>
84
- 'The `Style/DeprecatedHashMethods` cop has been renamed to ' \
85
- '`Style/PreferredHashMethods`.',
86
- 'Style/AccessorMethodName' =>
87
- 'The `Style/AccessorMethodName` cop has been moved to ' \
88
- '`Naming/AccessorMethodName`.',
89
- 'Style/AsciiIdentifiers' =>
90
- 'The `Style/AsciiIdentifiers` cop has been moved to ' \
91
- '`Naming/AccessorMethodName`.',
92
- 'Style/OpMethod' =>
93
- 'The `Style/OpMethod` cop has been renamed and moved to ' \
94
- '`Naming/BinaryOperatorParameterName`.',
95
- 'Style/ClassAndModuleCamelCase' =>
96
- 'The `Style/ClassAndModuleCamelCase` cop has been renamed to ' \
97
- '`Naming/ClassAndModuleCamelCase`.',
98
- 'Style/ConstantName' =>
99
- 'The `Style/ConstantName` cop has been renamed to ' \
100
- '`Naming/ConstantName`.',
101
- 'Style/FileName' =>
102
- 'The `Style/FileName` cop has been renamed to `Naming/FileName`.',
103
- 'Style/MethodName' =>
104
- 'The `Style/MethodName` cop has been renamed to ' \
105
- '`Naming/MethodName`.',
106
- 'Style/PredicateName' =>
107
- 'The `Style/PredicateName` cop has been renamed to ' \
108
- '`Naming/PredicateName`.',
109
- 'Style/VariableName' =>
110
- 'The `Style/VariableName` cop has been renamed to ' \
111
- '`Naming/VariableName`.',
112
- 'Style/VariableNumber' =>
113
- 'The `Style/VariableNumber` cop has been renamed to ' \
114
- '`Naming/VariableNumber`.',
115
- 'Lint/BlockAlignment' =>
116
- 'The `Lint/BlockAlignment` cop has been renamed to ' \
117
- '`Layout/BlockAlignment`.',
118
- 'Lint/EndAlignment' =>
119
- 'The `Lint/EndAlignment` cop has been renamed to ' \
120
- '`Layout/EndAlignment`.',
121
- 'Lint/DefEndAlignment' =>
122
- 'The `Lint/DefEndAlignment` cop has been renamed to ' \
123
- '`Layout/DefEndAlignment`.',
124
- 'Style/MethodMissing' =>
125
- 'The `Style/MethodMissing` cop has been split into ' \
126
- '`Style/MethodMissingSuper` and `Style/MissingRespondToMissing`.'
127
- }.freeze
128
-
129
- OBSOLETE_PARAMETERS = [
130
- {
131
- cop: 'Layout/SpaceAroundOperators',
132
- parameter: 'MultiSpaceAllowedForOperators',
133
- alternative: 'If your intention was to allow extra spaces ' \
134
- 'for alignment, please use AllowForAlignment: ' \
135
- 'true instead.'
136
- },
137
- {
138
- cop: 'Style/Encoding',
139
- parameter: 'EnforcedStyle',
140
- alternative: 'Style/Encoding no longer supports styles. ' \
141
- 'The "never" behavior is always assumed.'
142
- },
143
- {
144
- cop: 'Style/Encoding',
145
- parameter: 'SupportedStyles',
146
- alternative: 'Style/Encoding no longer supports styles. ' \
147
- 'The "never" behavior is always assumed.'
148
- },
149
- {
150
- cop: 'Style/Encoding',
151
- parameter: 'AutoCorrectEncodingComment',
152
- alternative: 'Style/Encoding no longer supports styles. ' \
153
- 'The "never" behavior is always assumed.'
154
- },
155
- {
156
- cop: 'Style/IfUnlessModifier',
157
- parameter: 'MaxLineLength',
158
- alternative:
159
- '`Style/IfUnlessModifier: MaxLineLength` has been removed. Use ' \
160
- '`Metrics/LineLength: Max` instead'
161
- },
162
- {
163
- cop: 'Style/SpaceAroundOperators',
164
- parameter: 'MultiSpaceAllowedForOperators',
165
- alternative: 'If your intention was to allow extra spaces ' \
166
- 'for alignment, please use AllowForAlignment: ' \
167
- 'true instead.'
168
- },
169
- {
170
- cop: 'Style/WhileUntilModifier',
171
- parameter: 'MaxLineLength',
172
- alternative:
173
- '`Style/WhileUntilModifier: MaxLineLength` has been removed. Use ' \
174
- '`Metrics/LineLength: Max` instead'
175
- },
176
- {
177
- cop: 'AllCops',
178
- parameter: 'RunRailsCops',
179
- alternative: "Use the following configuration instead:\n" \
180
- "Rails:\n Enabled: true"
181
- },
182
- {
183
- cop: 'Layout/CaseIndentation',
184
- parameter: 'IndentWhenRelativeTo',
185
- alternative: '`IndentWhenRelativeTo` has been renamed to ' \
186
- '`EnforcedStyle`'
187
- },
188
- {
189
- cop: 'Lint/BlockAlignment',
190
- parameter: 'AlignWith',
191
- alternative: '`AlignWith` has been renamed to ' \
192
- '`EnforcedStyleAlignWith`'
193
- },
194
- {
195
- cop: 'Layout/BlockAlignment',
196
- parameter: 'AlignWith',
197
- alternative: '`AlignWith` has been renamed to ' \
198
- '`EnforcedStyleAlignWith`'
199
- },
200
- {
201
- cop: 'Lint/EndAlignment',
202
- parameter: 'AlignWith',
203
- alternative: '`AlignWith` has been renamed to ' \
204
- '`EnforcedStyleAlignWith`'
205
- },
206
- {
207
- cop: 'Layout/EndAlignment',
208
- parameter: 'AlignWith',
209
- alternative: '`AlignWith` has been renamed to ' \
210
- '`EnforcedStyleAlignWith`'
211
- },
212
- {
213
- cop: 'Lint/DefEndAlignment',
214
- parameter: 'AlignWith',
215
- alternative: '`AlignWith` has been renamed to ' \
216
- '`EnforcedStyleAlignWith`'
217
- },
218
- {
219
- cop: 'Layout/DefEndAlignment',
220
- parameter: 'AlignWith',
221
- alternative: '`AlignWith` has been renamed to ' \
222
- '`EnforcedStyleAlignWith`'
223
- },
224
- {
225
- cop: 'Rails/UniqBeforePluck',
226
- parameter: 'EnforcedMode',
227
- alternative: '`EnforcedMode` has been renamed to ' \
228
- '`EnforcedStyle`'
229
- }
230
- ].freeze
231
-
232
- OBSOLETE_ENFORCED_STYLES = [
233
- {
234
- cop: 'Layout/IndentationConsistency',
235
- parameter: 'EnforcedStyle',
236
- enforced_style: 'rails',
237
- alternative: '`EnforcedStyle: rails` has been renamed to ' \
238
- '`EnforcedStyle: indented_internal_methods`'
239
- }
240
- ].freeze
241
-
242
17
  attr_reader :loaded_path
243
18
 
244
19
  def initialize(hash = {}, loaded_path = nil)
@@ -250,6 +25,7 @@ module RuboCop
250
25
  h[cop] = cop_options
251
26
  end
252
27
  @hash = hash
28
+ @validator = ConfigValidator.new(self)
253
29
  end
254
30
 
255
31
  def self.create(hash, path)
@@ -260,54 +36,14 @@ module RuboCop
260
36
  deprecation_check do |deprecation_message|
261
37
  warn("#{loaded_path} - #{deprecation_message}")
262
38
  end
263
- validate
39
+ @validator.validate
264
40
  make_excludes_absolute
265
41
  self
266
42
  end
267
43
 
268
- def [](key)
269
- @hash[key]
270
- end
271
-
272
- def []=(key, value)
273
- @hash[key] = value
274
- end
275
-
276
- def delete(key)
277
- @hash.delete(key)
278
- end
279
-
280
- def each(&block)
281
- @hash.each(&block)
282
- end
283
-
284
- def key?(key)
285
- @hash.key?(key)
286
- end
287
-
288
- def keys
289
- @hash.keys
290
- end
291
-
292
- def each_key(&block)
293
- @hash.each_key(&block)
294
- end
295
-
296
- def map(&block)
297
- @hash.map(&block)
298
- end
299
-
300
- def merge(other_hash)
301
- @hash.merge(other_hash)
302
- end
303
-
304
- def to_h
305
- @hash
306
- end
307
-
308
- def to_hash
309
- @hash
310
- end
44
+ def_delegators :@hash, :[], :[]=, :delete, :each, :key?, :keys, :each_key,
45
+ :map, :merge, :to_h, :to_hash
46
+ def_delegators :@validator, :validate, :target_ruby_version
311
47
 
312
48
  def to_s
313
49
  @to_s ||= @hash.to_s
@@ -317,9 +53,16 @@ module RuboCop
317
53
  @signature ||= Digest::SHA1.hexdigest(to_s)
318
54
  end
319
55
 
56
+ # True if this is a config file that is shipped with RuboCop
57
+ def internal?
58
+ base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
59
+ 'config'))
60
+ File.expand_path(loaded_path).start_with?(base_config_path)
61
+ end
62
+
320
63
  def make_excludes_absolute
321
64
  each_key do |key|
322
- validate_section_presence(key)
65
+ @validator.validate_section_presence(key)
323
66
  next unless self[key]['Exclude']
324
67
 
325
68
  self[key]['Exclude'].map! do |exclude_elem|
@@ -360,27 +103,12 @@ module RuboCop
360
103
  @for_cop[cop.respond_to?(:cop_name) ? cop.cop_name : cop]
361
104
  end
362
105
 
363
- def for_all_cops
364
- @for_all_cops ||= self['AllCops'] || {}
106
+ def for_department(department_name)
107
+ @for_cop[department_name]
365
108
  end
366
109
 
367
- def validate
368
- # Don't validate RuboCop's own files. Avoids infinite recursion.
369
- base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
370
- 'config'))
371
- return if File.expand_path(loaded_path).start_with?(base_config_path)
372
-
373
- valid_cop_names, invalid_cop_names = keys.partition do |key|
374
- ConfigLoader.default_configuration.key?(key)
375
- end
376
-
377
- reject_obsolete_cops_and_parameters
378
- warn_about_unrecognized_cops(invalid_cop_names)
379
- check_target_ruby
380
- validate_parameter_names(valid_cop_names)
381
- validate_enforced_styles(valid_cop_names)
382
- validate_syntax_cop
383
- reject_mutually_exclusive_defaults
110
+ def for_all_cops
111
+ @for_all_cops ||= self['AllCops'] || {}
384
112
  end
385
113
 
386
114
  def file_to_include?(file)
@@ -461,26 +189,6 @@ module RuboCop
461
189
  end
462
190
  end
463
191
 
464
- def target_ruby_version
465
- @target_ruby_version ||= begin
466
- if for_all_cops['TargetRubyVersion']
467
- @target_ruby_version_source = :rubocop_yml
468
-
469
- for_all_cops['TargetRubyVersion'].to_f
470
- elsif target_ruby_version_from_version_file
471
- @target_ruby_version_source = :ruby_version_file
472
-
473
- target_ruby_version_from_version_file
474
- elsif target_ruby_version_from_bundler_lock_file
475
- @target_ruby_version_source = :bundler_lock_file
476
-
477
- target_ruby_version_from_bundler_lock_file
478
- else
479
- DEFAULT_RUBY_VERSION
480
- end
481
- end
482
- end
483
-
484
192
  def target_rails_version
485
193
  @target_rails_version ||=
486
194
  if for_all_cops['TargetRailsVersion']
@@ -492,214 +200,22 @@ module RuboCop
492
200
  end
493
201
  end
494
202
 
495
- private
496
-
497
- def warn_about_unrecognized_cops(invalid_cop_names)
498
- invalid_cop_names.each do |name|
499
- # There could be a custom cop with this name. If so, don't warn
500
- next if Cop::Cop.registry.contains_cop_matching?([name])
501
-
502
- # Special case for inherit_mode, which is a directive that we keep in
503
- # the configuration (even though it's not a cop), because it's easier
504
- # to do so than to pass the value around to various methods.
505
- next if name == 'inherit_mode'
506
-
507
- warn Rainbow("Warning: unrecognized cop #{name} found in " \
508
- "#{smart_loaded_path}").yellow
509
- end
510
- end
511
-
512
- def validate_syntax_cop
513
- syntax_config = self['Lint/Syntax']
514
- default_config = ConfigLoader.default_configuration['Lint/Syntax']
515
-
516
- return unless syntax_config &&
517
- default_config.merge(syntax_config) != default_config
518
-
519
- raise ValidationError,
520
- "configuration for Syntax cop found in #{smart_loaded_path}\n" \
521
- 'It\'s not possible to disable this cop.'
522
- end
523
-
524
- def validate_section_presence(name)
525
- return unless key?(name) && self[name].nil?
526
-
527
- raise ValidationError,
528
- "empty section #{name} found in #{smart_loaded_path}"
529
- end
530
-
531
- def validate_parameter_names(valid_cop_names)
532
- valid_cop_names.each do |name|
533
- validate_section_presence(name)
534
- default_config = ConfigLoader.default_configuration[name]
535
-
536
- self[name].each_key do |param|
537
- next if COMMON_PARAMS.include?(param) || default_config.key?(param)
538
-
539
- message =
540
- "Warning: #{name} does not support #{param} parameter.\n\n" \
541
- "Supported parameters are:\n\n" \
542
- " - #{(default_config.keys - INTERNAL_PARAMS).join("\n - ")}\n"
543
-
544
- warn Rainbow(message).yellow.to_s
545
- end
546
- end
547
- end
548
-
549
- def validate_enforced_styles(valid_cop_names)
550
- valid_cop_names.each do |name|
551
- styles = self[name].select { |key, _| key.start_with?('Enforced') }
552
-
553
- styles.each do |style_name, style|
554
- supported_key = RuboCop::Cop::Util.to_supported_styles(style_name)
555
- valid = ConfigLoader.default_configuration[name][supported_key]
556
-
557
- next unless valid
558
- next if valid.include?(style)
559
- next if validate_support_and_has_list(name, style, valid)
560
-
561
- msg = "invalid #{style_name} '#{style}' for #{name} found in " \
562
- "#{smart_loaded_path}\n" \
563
- "Valid choices are: #{valid.join(', ')}"
564
- raise ValidationError, msg
565
- end
566
- end
567
- end
568
-
569
- def validate_support_and_has_list(name, formats, valid)
570
- ConfigLoader.default_configuration[name]['AllowMultipleStyles'] &&
571
- formats.is_a?(Array) &&
572
- formats.all? { |format| valid.include?(format) }
573
- end
574
-
575
- def reject_obsolete_cops_and_parameters
576
- messages = [
577
- obsolete_cops,
578
- obsolete_parameters,
579
- obsolete_enforced_style
580
- ].flatten.compact
581
- return if messages.empty?
582
-
583
- raise ValidationError, messages.join("\n")
584
- end
585
-
586
- def obsolete_parameters
587
- OBSOLETE_PARAMETERS.map do |params|
588
- obsolete_parameter_message(params[:cop], params[:parameter],
589
- params[:alternative])
590
- end
591
- end
592
-
593
- def obsolete_parameter_message(cop, parameter, alternative)
594
- return unless self[cop]&.key?(parameter)
595
-
596
- "obsolete parameter #{parameter} (for #{cop}) " \
597
- "found in #{smart_loaded_path}" \
598
- "\n#{alternative}"
599
- end
600
-
601
- def obsolete_cops
602
- OBSOLETE_COPS.map do |cop_name, message|
603
- next unless key?(cop_name) || key?(Cop::Badge.parse(cop_name).cop_name)
604
-
605
- message + "\n(obsolete configuration found in #{smart_loaded_path}," \
606
- ' please update it)'
607
- end
608
- end
609
-
610
- def obsolete_enforced_style
611
- OBSOLETE_ENFORCED_STYLES.map do |params|
612
- obsolete_enforced_style_message(params[:cop], params[:parameter],
613
- params[:enforced_style],
614
- params[:alternative])
615
- end
616
- end
617
-
618
- def obsolete_enforced_style_message(cop, param, enforced_style, alternative)
619
- style = self[cop]&.detect { |key, _| key.start_with?(param) }
620
-
621
- return unless style && style[1] == enforced_style
622
-
623
- "obsolete `#{param}: #{enforced_style}` (for #{cop}) " \
624
- "found in #{smart_loaded_path}" \
625
- "\n#{alternative}"
203
+ def smart_loaded_path
204
+ PathUtil.smart_path(@loaded_path)
626
205
  end
627
206
 
628
- def check_target_ruby
629
- return if KNOWN_RUBIES.include?(target_ruby_version)
630
-
631
- msg = if OBSOLETE_RUBIES.include?(target_ruby_version)
632
- "RuboCop found unsupported Ruby version #{target_ruby_version} " \
633
- "in #{target_ruby_source}. #{target_ruby_version}-compatible " \
634
- 'analysis was dropped after version ' \
635
- "#{OBSOLETE_RUBIES[target_ruby_version]}."
636
- else
637
- 'RuboCop found unknown Ruby version ' \
638
- "#{target_ruby_version.inspect} in #{target_ruby_source}."
639
- end
640
-
641
- msg += "\nSupported versions: #{KNOWN_RUBIES.join(', ')}"
642
-
643
- raise ValidationError, msg
644
- end
207
+ def bundler_lock_file_path
208
+ return nil unless loaded_path
645
209
 
646
- def target_ruby_source
647
- case @target_ruby_version_source
648
- when :ruby_version_file
649
- "`#{RUBY_VERSION_FILENAME}`"
650
- when :bundler_lock_file
651
- "`#{bundler_lock_file_path}`"
652
- when :rubocop_yml
653
- "`TargetRubyVersion` parameter (in #{smart_loaded_path})"
210
+ base_path = base_dir_for_path_parameters
211
+ ['gems.locked', 'Gemfile.lock'].each do |file_name|
212
+ path = find_file_upwards(file_name, base_path)
213
+ return path if path
654
214
  end
215
+ nil
655
216
  end
656
217
 
657
- def ruby_version_file
658
- @ruby_version_file ||=
659
- find_file_upwards(RUBY_VERSION_FILENAME, base_dir_for_path_parameters)
660
- end
661
-
662
- def target_ruby_version_from_version_file
663
- file = ruby_version_file
664
- return unless file && File.file?(file)
665
-
666
- @target_ruby_version_from_version_file ||=
667
- File.read(file).match(/\A(ruby-)?(?<version>\d+\.\d+)/) do |md|
668
- md[:version].to_f
669
- end
670
- end
671
-
672
- def target_ruby_version_from_bundler_lock_file
673
- @target_ruby_version_from_bundler_lock_file ||=
674
- read_ruby_version_from_bundler_lock_file
675
- end
676
-
677
- def read_ruby_version_from_bundler_lock_file
678
- lock_file_path = bundler_lock_file_path
679
- return nil unless lock_file_path
680
-
681
- in_ruby_section = false
682
- File.foreach(lock_file_path) do |line|
683
- # If ruby is in Gemfile.lock or gems.lock, there should be two lines
684
- # towards the bottom of the file that look like:
685
- # RUBY VERSION
686
- # ruby W.X.YpZ
687
- # We ultimately want to match the "ruby W.X.Y.pZ" line, but there's
688
- # extra logic to make sure we only start looking once we've seen the
689
- # "RUBY VERSION" line.
690
- in_ruby_section ||= line.match(/^\s*RUBY\s*VERSION\s*$/)
691
- next unless in_ruby_section
692
-
693
- # We currently only allow this feature to work with MRI ruby. If jruby
694
- # (or something else) is used by the project, it's lock file will have a
695
- # line that looks like:
696
- # RUBY VERSION
697
- # ruby W.X.YpZ (jruby x.x.x.x)
698
- # The regex won't match in this situation.
699
- result = line.match(/^\s*ruby\s+(\d+\.\d+)[p.\d]*\s*$/)
700
- return result.captures.first.to_f if result
701
- end
702
- end
218
+ private
703
219
 
704
220
  def target_rails_version_from_bundler_lock_file
705
221
  @target_rails_version_from_bundler_lock_file ||=
@@ -718,26 +234,6 @@ module RuboCop
718
234
  end
719
235
  end
720
236
 
721
- def bundler_lock_file_path
722
- return nil unless loaded_path
723
-
724
- base_path = base_dir_for_path_parameters
725
- ['gems.locked', 'Gemfile.lock'].each do |file_name|
726
- path = find_file_upwards(file_name, base_path)
727
- return path if path
728
- end
729
- nil
730
- end
731
-
732
- def reject_mutually_exclusive_defaults
733
- disabled_by_default = for_all_cops['DisabledByDefault']
734
- enabled_by_default = for_all_cops['EnabledByDefault']
735
- return unless disabled_by_default && enabled_by_default
736
-
737
- msg = 'Cops cannot be both enabled by default and disabled by default'
738
- raise ValidationError, msg
739
- end
740
-
741
237
  def enable_cop?(qualified_cop_name, cop_options)
742
238
  cop_department, cop_name = qualified_cop_name.split('/')
743
239
  department = cop_name.nil?
@@ -751,10 +247,5 @@ module RuboCop
751
247
 
752
248
  cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
753
249
  end
754
-
755
- def smart_loaded_path
756
- PathUtil.smart_path(@loaded_path)
757
- end
758
250
  end
759
- # rubocop:enable Metrics/ClassLength
760
251
  end