rubocop 0.80.0 → 0.84.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/config/default.yml +171 -34
  4. data/lib/rubocop.rb +15 -62
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli.rb +11 -5
  7. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  8. data/lib/rubocop/config.rb +41 -13
  9. data/lib/rubocop/config_loader.rb +40 -36
  10. data/lib/rubocop/config_loader_resolver.rb +27 -4
  11. data/lib/rubocop/config_obsoletion.rb +2 -0
  12. data/lib/rubocop/config_validator.rb +18 -1
  13. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  14. data/lib/rubocop/cop/badge.rb +5 -5
  15. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  16. data/lib/rubocop/cop/corrector.rb +49 -27
  17. data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
  18. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
  19. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
  20. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
  21. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  22. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -3
  23. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  24. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  25. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
  26. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  27. data/lib/rubocop/cop/generator.rb +4 -3
  28. data/lib/rubocop/cop/ignored_node.rb +1 -3
  29. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
  30. data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
  31. data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
  32. data/lib/rubocop/cop/layout/condition_position.rb +12 -2
  33. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  34. data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
  35. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  36. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
  37. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  38. data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
  39. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
  40. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  41. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  42. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -8
  43. data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
  44. data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
  45. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  46. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  47. data/lib/rubocop/cop/layout/line_length.rb +7 -4
  48. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -4
  49. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  50. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  51. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
  52. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
  53. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +129 -0
  54. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
  55. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  56. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  57. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
  58. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  59. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
  60. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
  61. data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
  62. data/lib/rubocop/cop/lint/ambiguous_operator.rb +40 -0
  63. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
  64. data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
  65. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  66. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
  67. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
  68. data/lib/rubocop/cop/lint/empty_when.rb +29 -6
  69. data/lib/rubocop/cop/lint/ensure_return.rb +18 -1
  70. data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -7
  71. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  72. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  73. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
  74. data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
  75. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  76. data/lib/rubocop/cop/lint/loop.rb +6 -4
  77. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
  78. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  79. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  80. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  81. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +31 -11
  82. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
  83. data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
  84. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
  85. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  86. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  87. data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
  88. data/lib/rubocop/cop/lint/suppressed_exception.rb +20 -25
  89. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  90. data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
  91. data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
  92. data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
  93. data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
  94. data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
  95. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +5 -0
  96. data/lib/rubocop/cop/migration/department_name.rb +21 -12
  97. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  98. data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
  99. data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
  100. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  101. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
  102. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
  103. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
  104. data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -3
  105. data/lib/rubocop/cop/mixin/line_length_help.rb +2 -1
  106. data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
  107. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -3
  108. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
  109. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
  110. data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -3
  111. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  112. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  113. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  114. data/lib/rubocop/cop/naming/constant_name.rb +2 -1
  115. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  116. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  117. data/lib/rubocop/cop/naming/method_name.rb +26 -0
  118. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  119. data/lib/rubocop/cop/registry.rb +13 -10
  120. data/lib/rubocop/cop/severity.rb +1 -3
  121. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
  122. data/lib/rubocop/cop/style/alias.rb +4 -4
  123. data/lib/rubocop/cop/style/and_or.rb +7 -8
  124. data/lib/rubocop/cop/style/array_join.rb +1 -1
  125. data/lib/rubocop/cop/style/attr.rb +1 -3
  126. data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
  127. data/lib/rubocop/cop/style/case_equality.rb +24 -1
  128. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  129. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  130. data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
  131. data/lib/rubocop/cop/style/copyright.rb +1 -1
  132. data/lib/rubocop/cop/style/dir.rb +1 -1
  133. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
  134. data/lib/rubocop/cop/style/documentation.rb +43 -5
  135. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
  136. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  137. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  138. data/lib/rubocop/cop/style/each_with_object.rb +3 -3
  139. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  140. data/lib/rubocop/cop/style/empty_method.rb +1 -5
  141. data/lib/rubocop/cop/style/end_block.rb +6 -0
  142. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  143. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  144. data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
  145. data/lib/rubocop/cop/style/format_string.rb +2 -2
  146. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -4
  147. data/lib/rubocop/cop/style/guard_clause.rb +25 -2
  148. data/lib/rubocop/cop/style/hash_each_methods.rb +5 -3
  149. data/lib/rubocop/cop/style/hash_syntax.rb +15 -10
  150. data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
  151. data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
  152. data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
  153. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
  154. data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
  155. data/lib/rubocop/cop/style/lambda.rb +3 -2
  156. data/lib/rubocop/cop/style/lambda_call.rb +1 -21
  157. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  158. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  159. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  160. data/lib/rubocop/cop/style/module_function.rb +58 -12
  161. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  162. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  163. data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
  164. data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
  165. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -4
  166. data/lib/rubocop/cop/style/next.rb +2 -2
  167. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  168. data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
  169. data/lib/rubocop/cop/style/not.rb +1 -1
  170. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  171. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  172. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  173. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
  174. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  175. data/lib/rubocop/cop/style/or_assignment.rb +1 -1
  176. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  177. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  178. data/lib/rubocop/cop/style/proc.rb +1 -1
  179. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  180. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  181. data/lib/rubocop/cop/style/redundant_condition.rb +18 -6
  182. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  183. data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
  184. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  185. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
  186. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  187. data/lib/rubocop/cop/style/redundant_return.rb +5 -7
  188. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  189. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  190. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  191. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  192. data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
  193. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  194. data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
  195. data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
  196. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
  197. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
  198. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  199. data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
  200. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
  201. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
  202. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
  203. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
  204. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
  205. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -6
  206. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  207. data/lib/rubocop/cop/style/unpack_first.rb +0 -4
  208. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  209. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  210. data/lib/rubocop/cop/style/word_array.rb +1 -1
  211. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
  212. data/lib/rubocop/cop/util.rb +24 -0
  213. data/lib/rubocop/cop/variable_force.rb +3 -9
  214. data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
  215. data/lib/rubocop/cop/variable_force/branch.rb +2 -6
  216. data/lib/rubocop/cop/variable_force/scope.rb +1 -0
  217. data/lib/rubocop/cop/variable_force/variable.rb +3 -6
  218. data/lib/rubocop/ext/processed_source.rb +18 -0
  219. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  220. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  221. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
  222. data/lib/rubocop/formatter/formatter_set.rb +1 -4
  223. data/lib/rubocop/formatter/junit_formatter.rb +17 -6
  224. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  225. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  226. data/lib/rubocop/name_similarity.rb +12 -9
  227. data/lib/rubocop/options.rb +20 -13
  228. data/lib/rubocop/remote_config.rb +1 -3
  229. data/lib/rubocop/result_cache.rb +1 -3
  230. data/lib/rubocop/rspec/cop_helper.rb +2 -4
  231. data/lib/rubocop/rspec/expect_offense.rb +4 -10
  232. data/lib/rubocop/rspec/shared_contexts.rb +54 -20
  233. data/lib/rubocop/runner.rb +15 -12
  234. data/lib/rubocop/target_finder.rb +5 -7
  235. data/lib/rubocop/target_ruby.rb +2 -2
  236. data/lib/rubocop/version.rb +5 -3
  237. metadata +32 -77
  238. data/lib/rubocop/ast/builder.rb +0 -83
  239. data/lib/rubocop/ast/node.rb +0 -632
  240. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  241. data/lib/rubocop/ast/node/and_node.rb +0 -29
  242. data/lib/rubocop/ast/node/args_node.rb +0 -29
  243. data/lib/rubocop/ast/node/array_node.rb +0 -57
  244. data/lib/rubocop/ast/node/block_node.rb +0 -117
  245. data/lib/rubocop/ast/node/break_node.rb +0 -17
  246. data/lib/rubocop/ast/node/case_node.rb +0 -56
  247. data/lib/rubocop/ast/node/class_node.rb +0 -31
  248. data/lib/rubocop/ast/node/def_node.rb +0 -82
  249. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  250. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  251. data/lib/rubocop/ast/node/float_node.rb +0 -12
  252. data/lib/rubocop/ast/node/for_node.rb +0 -53
  253. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  254. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  255. data/lib/rubocop/ast/node/if_node.rb +0 -175
  256. data/lib/rubocop/ast/node/int_node.rb +0 -12
  257. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  258. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  259. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  260. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  261. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  262. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  263. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
  264. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  265. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  266. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  267. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  268. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  269. data/lib/rubocop/ast/node/module_node.rb +0 -24
  270. data/lib/rubocop/ast/node/or_node.rb +0 -29
  271. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  272. data/lib/rubocop/ast/node/range_node.rb +0 -18
  273. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  274. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  275. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  276. data/lib/rubocop/ast/node/return_node.rb +0 -24
  277. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  278. data/lib/rubocop/ast/node/send_node.rb +0 -13
  279. data/lib/rubocop/ast/node/str_node.rb +0 -16
  280. data/lib/rubocop/ast/node/super_node.rb +0 -21
  281. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  282. data/lib/rubocop/ast/node/until_node.rb +0 -35
  283. data/lib/rubocop/ast/node/when_node.rb +0 -53
  284. data/lib/rubocop/ast/node/while_node.rb +0 -35
  285. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  286. data/lib/rubocop/ast/sexp.rb +0 -16
  287. data/lib/rubocop/ast/traversal.rb +0 -200
  288. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  289. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
  290. data/lib/rubocop/node_pattern.rb +0 -887
  291. data/lib/rubocop/processed_source.rb +0 -216
  292. data/lib/rubocop/string_util.rb +0 -14
  293. data/lib/rubocop/token.rb +0 -114
@@ -1,73 +1,23 @@
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
- require 'forwardable'
9
7
  require 'unicode/display_width/no_string_ext'
8
+ require 'rubocop-ast'
9
+ require_relative 'rubocop/ast_aliases'
10
10
 
11
11
  require_relative 'rubocop/version'
12
12
 
13
13
  require_relative 'rubocop/core_ext/string'
14
+ require_relative 'rubocop/ext/processed_source'
15
+
14
16
  require_relative 'rubocop/path_util'
15
17
  require_relative 'rubocop/file_finder'
16
18
  require_relative 'rubocop/platform'
17
- require_relative 'rubocop/string_util'
18
19
  require_relative 'rubocop/name_similarity'
19
- require_relative 'rubocop/node_pattern'
20
20
  require_relative 'rubocop/string_interpreter'
21
- require_relative 'rubocop/ast/sexp'
22
- require_relative 'rubocop/ast/node'
23
- require_relative 'rubocop/ast/node/mixin/method_identifier_predicates'
24
- require_relative 'rubocop/ast/node/mixin/binary_operator_node'
25
- require_relative 'rubocop/ast/node/mixin/collection_node'
26
- require_relative 'rubocop/ast/node/mixin/conditional_node'
27
- require_relative 'rubocop/ast/node/mixin/hash_element_node'
28
- require_relative 'rubocop/ast/node/mixin/method_dispatch_node'
29
- require_relative 'rubocop/ast/node/mixin/modifier_node'
30
- require_relative 'rubocop/ast/node/mixin/numeric_node'
31
- require_relative 'rubocop/ast/node/mixin/parameterized_node'
32
- require_relative 'rubocop/ast/node/mixin/predicate_operator_node'
33
- require_relative 'rubocop/ast/node/mixin/basic_literal_node'
34
- require_relative 'rubocop/ast/node/alias_node'
35
- require_relative 'rubocop/ast/node/and_node'
36
- require_relative 'rubocop/ast/node/args_node'
37
- require_relative 'rubocop/ast/node/array_node'
38
- require_relative 'rubocop/ast/node/block_node'
39
- require_relative 'rubocop/ast/node/break_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
21
  require_relative 'rubocop/error'
72
22
  require_relative 'rubocop/warning'
73
23
 
@@ -212,10 +162,11 @@ require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
212
162
  require_relative 'rubocop/cop/layout/empty_line_between_defs'
213
163
  require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
214
164
  require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
165
+ require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
215
166
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
216
167
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
217
168
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
218
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
169
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
219
170
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
220
171
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
221
172
  require_relative 'rubocop/cop/layout/empty_lines'
@@ -234,6 +185,7 @@ require_relative 'rubocop/cop/layout/hash_alignment'
234
185
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
235
186
  require_relative 'rubocop/cop/layout/heredoc_indentation'
236
187
  require_relative 'rubocop/cop/layout/indentation_consistency'
188
+ require_relative 'rubocop/cop/layout/indentation_style'
237
189
  require_relative 'rubocop/cop/layout/indentation_width'
238
190
  require_relative 'rubocop/cop/layout/initial_indentation'
239
191
  require_relative 'rubocop/cop/layout/leading_comment_space'
@@ -260,6 +212,7 @@ require_relative 'rubocop/cop/layout/space_after_semicolon'
260
212
  require_relative 'rubocop/cop/layout/space_around_block_parameters'
261
213
  require_relative 'rubocop/cop/layout/space_around_equals_in_parameter_default'
262
214
  require_relative 'rubocop/cop/layout/space_around_keyword'
215
+ require_relative 'rubocop/cop/layout/space_around_method_call_operator'
263
216
  require_relative 'rubocop/cop/layout/space_around_operators'
264
217
  require_relative 'rubocop/cop/layout/space_before_block_braces'
265
218
  require_relative 'rubocop/cop/layout/space_before_comma'
@@ -276,7 +229,6 @@ require_relative 'rubocop/cop/layout/space_inside_percent_literal_delimiters'
276
229
  require_relative 'rubocop/cop/layout/space_inside_range_literal'
277
230
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
278
231
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
279
- require_relative 'rubocop/cop/layout/tab'
280
232
  require_relative 'rubocop/cop/layout/trailing_empty_lines'
281
233
  require_relative 'rubocop/cop/layout/trailing_whitespace'
282
234
 
@@ -289,6 +241,7 @@ require_relative 'rubocop/cop/lint/boolean_symbol'
289
241
  require_relative 'rubocop/cop/lint/circular_argument_reference'
290
242
  require_relative 'rubocop/cop/lint/debugger'
291
243
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
244
+ require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
292
245
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
293
246
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
294
247
  require_relative 'rubocop/cop/lint/duplicate_hash_key'
@@ -299,7 +252,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
299
252
  require_relative 'rubocop/cop/lint/empty_expression'
300
253
  require_relative 'rubocop/cop/lint/empty_interpolation'
301
254
  require_relative 'rubocop/cop/lint/empty_when'
302
- require_relative 'rubocop/cop/lint/end_in_method'
303
255
  require_relative 'rubocop/cop/lint/ensure_return'
304
256
  require_relative 'rubocop/cop/lint/erb_new_arguments'
305
257
  require_relative 'rubocop/cop/lint/flip_flop'
@@ -325,6 +277,7 @@ require_relative 'rubocop/cop/lint/ordered_magic_comments'
325
277
  require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
326
278
  require_relative 'rubocop/cop/lint/percent_string_array'
327
279
  require_relative 'rubocop/cop/lint/percent_symbol_array'
280
+ require_relative 'rubocop/cop/lint/raise_exception'
328
281
  require_relative 'rubocop/cop/lint/rand_one'
329
282
  require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
330
283
  require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
@@ -346,6 +299,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
346
299
  require_relative 'rubocop/cop/lint/shadowed_argument'
347
300
  require_relative 'rubocop/cop/lint/shadowed_exception'
348
301
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
302
+ require_relative 'rubocop/cop/lint/struct_new_override'
349
303
  require_relative 'rubocop/cop/lint/suppressed_exception'
350
304
  require_relative 'rubocop/cop/lint/syntax'
351
305
  require_relative 'rubocop/cop/lint/to_json'
@@ -421,6 +375,7 @@ require_relative 'rubocop/cop/style/copyright'
421
375
  require_relative 'rubocop/cop/style/date_time'
422
376
  require_relative 'rubocop/cop/style/def_with_parentheses'
423
377
  require_relative 'rubocop/cop/style/dir'
378
+ require_relative 'rubocop/cop/style/disable_cops_within_source_code_directive'
424
379
  require_relative 'rubocop/cop/style/documentation_method'
425
380
  require_relative 'rubocop/cop/style/documentation'
426
381
  require_relative 'rubocop/cop/style/double_cop_disable_directive'
@@ -438,6 +393,7 @@ require_relative 'rubocop/cop/style/end_block'
438
393
  require_relative 'rubocop/cop/style/eval_with_location'
439
394
  require_relative 'rubocop/cop/style/even_odd'
440
395
  require_relative 'rubocop/cop/style/expand_path_arguments'
396
+ require_relative 'rubocop/cop/style/exponential_notation'
441
397
  require_relative 'rubocop/cop/style/float_division'
442
398
  require_relative 'rubocop/cop/style/for'
443
399
  require_relative 'rubocop/cop/style/format_string'
@@ -463,11 +419,9 @@ require_relative 'rubocop/cop/style/lambda'
463
419
  require_relative 'rubocop/cop/style/lambda_call'
464
420
  require_relative 'rubocop/cop/style/line_end_concatenation'
465
421
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
466
- # rubocop:disable Layout/LineLength
467
422
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
468
423
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
469
424
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
470
- # rubocop:enable Layout/LineLength
471
425
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
472
426
  require_relative 'rubocop/cop/style/method_def_parentheses'
473
427
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -537,6 +491,7 @@ require_relative 'rubocop/cop/style/send'
537
491
  require_relative 'rubocop/cop/style/signal_exception'
538
492
  require_relative 'rubocop/cop/style/single_line_block_params'
539
493
  require_relative 'rubocop/cop/style/single_line_methods'
494
+ require_relative 'rubocop/cop/style/slicing_with_range'
540
495
  require_relative 'rubocop/cop/style/special_global_vars'
541
496
  require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
542
497
  require_relative 'rubocop/cop/style/stderr_puts'
@@ -555,6 +510,7 @@ require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
555
510
  require_relative 'rubocop/cop/style/trailing_body_on_module'
556
511
  require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
557
512
  require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
513
+ require_relative 'rubocop/cop/style/trailing_comma_in_block_args'
558
514
  require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
559
515
  require_relative 'rubocop/cop/style/trailing_method_end_statement'
560
516
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
@@ -582,7 +538,6 @@ require_relative 'rubocop/formatter/simple_text_formatter'
582
538
  # relies on simple text
583
539
  require_relative 'rubocop/formatter/clang_style_formatter'
584
540
  require_relative 'rubocop/formatter/disabled_config_formatter'
585
- require_relative 'rubocop/formatter/disabled_lines_formatter'
586
541
  require_relative 'rubocop/formatter/emacs_style_formatter'
587
542
  require_relative 'rubocop/formatter/file_list_formatter'
588
543
  require_relative 'rubocop/formatter/fuubar_style_formatter'
@@ -608,10 +563,8 @@ require_relative 'rubocop/config_obsoletion'
608
563
  require_relative 'rubocop/config_store'
609
564
  require_relative 'rubocop/config_validator'
610
565
  require_relative 'rubocop/target_finder'
611
- require_relative 'rubocop/token'
612
566
  require_relative 'rubocop/comment_config'
613
567
  require_relative 'rubocop/magic_comment'
614
- require_relative 'rubocop/processed_source'
615
568
  require_relative 'rubocop/result_cache'
616
569
  require_relative 'rubocop/runner'
617
570
  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
@@ -35,8 +35,8 @@ module RuboCop
35
35
  if @options[:init]
36
36
  run_command(:init)
37
37
  else
38
- validate_options_vs_config
39
38
  act_on_options
39
+ validate_options_vs_config
40
40
  apply_default_formatter
41
41
  execute_runners
42
42
  end
@@ -83,10 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def act_on_options
86
- ConfigLoader.debug = @options[:debug]
87
- ConfigLoader.auto_gen_config = @options[:auto_gen_config]
88
- ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
89
- ConfigLoader.options_config = @options[:config]
86
+ set_options_to_config_loader
90
87
 
91
88
  @config_store.options_config = @options[:config] if @options[:config]
92
89
  @config_store.force_default_config! if @options[:force_default_config]
@@ -102,6 +99,15 @@ module RuboCop
102
99
  end
103
100
  end
104
101
 
102
+ def set_options_to_config_loader
103
+ ConfigLoader.debug = @options[:debug]
104
+ ConfigLoader.auto_gen_config = @options[:auto_gen_config]
105
+ ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
106
+ ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
107
+ ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
108
+ ConfigLoader.options_config = @options[:config]
109
+ end
110
+
105
111
  def handle_exiting_options
106
112
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
107
113
 
@@ -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.new(@config).support_autocorrect?
57
53
  puts "#{cop.cop_name}:"
58
54
  puts config_lines(cop)
59
55
  puts
@@ -2,6 +2,9 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
+ # FIXME: Moving Rails department code to RuboCop Rails will remove
6
+ # the following rubocop:disable comment.
7
+ # rubocop:disable Metrics/ClassLength
5
8
  module RuboCop
6
9
  # This class represents the configuration of the RuboCop application
7
10
  # and all its cops. A Config is associated with a YAML configuration
@@ -13,6 +16,8 @@ module RuboCop
13
16
  include FileFinder
14
17
  extend Forwardable
15
18
 
19
+ CopConfig = Struct.new(:name, :metadata)
20
+
16
21
  DEFAULT_RAILS_VERSION = 5.0
17
22
  attr_reader :loaded_path
18
23
 
@@ -42,7 +47,7 @@ module RuboCop
42
47
  end
43
48
 
44
49
  def_delegators :@hash, :[], :[]=, :delete, :each, :key?, :keys, :each_key,
45
- :map, :merge, :to_h, :to_hash
50
+ :map, :merge, :to_h, :to_hash, :transform_values
46
51
  def_delegators :@validator, :validate, :target_ruby_version
47
52
 
48
53
  def to_s
@@ -81,9 +86,7 @@ module RuboCop
81
86
 
82
87
  excludes = for_all_cops['Exclude'] ||= []
83
88
  highest_config.for_all_cops['Exclude'].each do |path|
84
- unless path.is_a?(Regexp) || absolute?(path)
85
- path = File.join(File.dirname(highest_config.loaded_path), path)
86
- end
89
+ path = File.join(File.dirname(highest_config.loaded_path), path) unless path.is_a?(Regexp) || absolute?(path)
87
90
  excludes << path unless excludes.include?(path)
88
91
  end
89
92
  end
@@ -111,6 +114,14 @@ module RuboCop
111
114
  @for_all_cops ||= self['AllCops'] || {}
112
115
  end
113
116
 
117
+ def disabled_new_cops?
118
+ for_all_cops['NewCops'] == 'disable'
119
+ end
120
+
121
+ def enabled_new_cops?
122
+ for_all_cops['NewCops'] == 'enable'
123
+ end
124
+
114
125
  def file_to_include?(file)
115
126
  relative_file_path = path_relative_to_config(file)
116
127
 
@@ -215,6 +226,18 @@ module RuboCop
215
226
  nil
216
227
  end
217
228
 
229
+ def pending_cops
230
+ keys.each_with_object([]) do |qualified_cop_name, pending_cops|
231
+ department = department_of(qualified_cop_name)
232
+ next if department && department['Enabled'] == false
233
+
234
+ cop_metadata = self[qualified_cop_name]
235
+ next unless cop_metadata['Enabled'] == 'pending'
236
+
237
+ pending_cops << CopConfig.new(qualified_cop_name, cop_metadata)
238
+ end
239
+ end
240
+
218
241
  private
219
242
 
220
243
  def target_rails_version_from_bundler_lock_file
@@ -235,17 +258,22 @@ module RuboCop
235
258
  end
236
259
 
237
260
  def enable_cop?(qualified_cop_name, cop_options)
238
- cop_department, cop_name = qualified_cop_name.split('/')
239
- department = cop_name.nil?
240
-
241
- unless department
242
- department_options = self[cop_department]
243
- if department_options && department_options['Enabled'] == false
244
- return false
245
- end
261
+ department = department_of(qualified_cop_name)
262
+ cop_enabled = cop_options.fetch('Enabled') do
263
+ !for_all_cops['DisabledByDefault']
246
264
  end
265
+ return true if cop_enabled == 'override_department'
266
+ return false if department && department['Enabled'] == false
267
+
268
+ cop_enabled
269
+ end
270
+
271
+ def department_of(qualified_cop_name)
272
+ cop_department, cop_name = qualified_cop_name.split('/')
273
+ return nil if cop_name.nil?
247
274
 
248
- cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
275
+ self[cop_department]
249
276
  end
250
277
  end
251
278
  end
279
+ # rubocop:enable Metrics/ClassLength
@@ -24,7 +24,7 @@ module RuboCop
24
24
  include FileFinder
25
25
 
26
26
  attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion,
27
- :options_config
27
+ :options_config, :disable_pending_cops, :enable_pending_cops
28
28
  attr_writer :default_configuration
29
29
 
30
30
  alias debug? debug
@@ -36,7 +36,7 @@ module RuboCop
36
36
  FileFinder.root_level = nil
37
37
  end
38
38
 
39
- def load_file(file)
39
+ def load_file(file) # rubocop:disable Metrics/AbcSize
40
40
  path = File.absolute_path(file.is_a?(RemoteConfig) ? file.file : file)
41
41
 
42
42
  hash = load_yaml_configuration(path)
@@ -46,6 +46,7 @@ module RuboCop
46
46
 
47
47
  add_missing_namespaces(path, hash)
48
48
 
49
+ resolver.override_department_setting_for_cops({}, hash)
49
50
  resolver.resolve_inheritance_from_gems(hash)
50
51
  resolver.resolve_inheritance(path, hash, file, debug?)
51
52
 
@@ -55,7 +56,10 @@ module RuboCop
55
56
  end
56
57
 
57
58
  def add_missing_namespaces(path, hash)
58
- hash.keys.each do |key|
59
+ # Using `hash.each_key` will cause the
60
+ # `can't add a new key into hash during iteration` error
61
+ hash_keys = hash.keys
62
+ hash_keys.each do |key|
59
63
  q = Cop::Cop.qualified_cop_name(key, path)
60
64
  next if q == key
61
65
 
@@ -76,30 +80,33 @@ module RuboCop
76
80
  # user's home directory is checked. If there's no .rubocop.yml
77
81
  # there either, the path to the default file is returned.
78
82
  def configuration_file_for(target_dir)
79
- find_project_dotfile(target_dir) ||
80
- find_user_dotfile ||
81
- find_user_xdg_config ||
82
- DEFAULT_FILE
83
+ find_project_dotfile(target_dir) || find_user_dotfile ||
84
+ find_user_xdg_config || DEFAULT_FILE
83
85
  end
84
86
 
85
87
  def configuration_from_file(config_file)
86
- config = load_file(config_file)
87
- return config if config_file == DEFAULT_FILE
88
+ return ConfigLoader.default_configuration if config_file == DEFAULT_FILE
88
89
 
90
+ config = load_file(config_file)
89
91
  if ignore_parent_exclusion?
90
92
  print 'Ignoring AllCops/Exclude from parent folders' if debug?
91
93
  else
92
94
  add_excludes_from_files(config, config_file)
93
95
  end
96
+
94
97
  merge_with_default(config, config_file).tap do |merged_config|
95
- warn_on_pending_cops(merged_config)
98
+ warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
96
99
  end
97
100
  end
98
101
 
102
+ def possible_new_cops?(config)
103
+ disable_pending_cops || enable_pending_cops ||
104
+ config.disabled_new_cops? || config.enabled_new_cops?
105
+ end
106
+
99
107
  def add_excludes_from_files(config, config_file)
100
- found_files =
101
- find_files_upwards(DOTFILE, config_file) +
102
- [find_user_dotfile, find_user_xdg_config].compact
108
+ found_files = find_files_upwards(DOTFILE, config_file) +
109
+ [find_user_dotfile, find_user_xdg_config].compact
103
110
 
104
111
  return if found_files.empty?
105
112
  return if PathUtil.relative_path(found_files.last) ==
@@ -116,20 +123,20 @@ module RuboCop
116
123
  end
117
124
  end
118
125
 
119
- def warn_on_pending_cops(config)
120
- pending_cops = config.keys.select do |key|
121
- config[key]['Enabled'] == 'pending'
122
- end
123
-
124
- return if pending_cops.none?
126
+ def warn_on_pending_cops(pending_cops)
127
+ return if pending_cops.empty?
125
128
 
126
129
  warn Rainbow('The following cops were added to RuboCop, but are not ' \
127
130
  'configured. Please set Enabled to either `true` or ' \
128
131
  '`false` in your `.rubocop.yml` file:').yellow
129
132
 
130
133
  pending_cops.each do |cop|
131
- warn Rainbow(" - #{cop}").yellow
134
+ version = cop.metadata['VersionAdded'] || 'N/A'
135
+
136
+ warn Rainbow(" - #{cop.name} (#{version})").yellow
132
137
  end
138
+
139
+ warn Rainbow('For more information: https://docs.rubocop.org/en/latest/versioning/').yellow
133
140
  end
134
141
 
135
142
  # Merges the given configuration with the default one. If
@@ -198,7 +205,7 @@ module RuboCop
198
205
  def write_config_file(file_name, file_string, rubocop_yml_contents)
199
206
  File.open(file_name, 'w') do |f|
200
207
  f.write "inherit_from:#{file_string}\n"
201
- f.write "\n#{rubocop_yml_contents}" if rubocop_yml_contents =~ /\S/
208
+ f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
202
209
  end
203
210
  end
204
211
 
@@ -207,15 +214,16 @@ module RuboCop
207
214
  end
208
215
 
209
216
  def load_yaml_configuration(absolute_path)
210
- yaml_code = read_file(absolute_path)
217
+ file_contents = read_file(absolute_path)
218
+ yaml_code = Dir.chdir(File.dirname(absolute_path)) do
219
+ ERB.new(file_contents).result
220
+ end
211
221
  check_duplication(yaml_code, absolute_path)
212
222
  hash = yaml_safe_load(yaml_code, absolute_path) || {}
213
223
 
214
224
  puts "configuration from #{absolute_path}" if debug?
215
225
 
216
- unless hash.is_a?(Hash)
217
- raise(TypeError, "Malformed configuration in #{absolute_path}")
218
- end
226
+ raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
219
227
 
220
228
  hash
221
229
  end
@@ -231,8 +239,7 @@ module RuboCop
231
239
  "#{smart_path}:#{line1}: " \
232
240
  "`#{value}` is concealed by line #{line2}"
233
241
  else
234
- "#{smart_path}: " \
235
- "`#{value}` is concealed by duplicate"
242
+ "#{smart_path}: `#{value}` is concealed by duplicate"
236
243
  end
237
244
  warn Rainbow(message).yellow
238
245
  end
@@ -250,17 +257,14 @@ module RuboCop
250
257
 
251
258
  def yaml_safe_load(yaml_code, filename)
252
259
  if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
253
- SafeYAML.load(yaml_code, filename,
254
- whitelisted_tags: %w[!ruby/regexp])
260
+ SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
255
261
  # Ruby 2.6+
256
262
  elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
257
- YAML.safe_load(
258
- yaml_code,
259
- permitted_classes: [Regexp, Symbol],
260
- permitted_symbols: [],
261
- aliases: true,
262
- filename: filename
263
- )
263
+ YAML.safe_load(yaml_code,
264
+ permitted_classes: [Regexp, Symbol],
265
+ permitted_symbols: [],
266
+ aliases: true,
267
+ filename: filename)
264
268
  else
265
269
  YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
266
270
  end