rubocop 0.82.0 → 0.86.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -19
  3. data/config/default.yml +111 -23
  4. data/lib/rubocop.rb +16 -59
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli.rb +3 -3
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
  8. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  9. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  10. data/lib/rubocop/comment_config.rb +1 -1
  11. data/lib/rubocop/config.rb +6 -2
  12. data/lib/rubocop/config_loader.rb +19 -24
  13. data/lib/rubocop/config_loader_resolver.rb +45 -6
  14. data/lib/rubocop/config_store.rb +12 -2
  15. data/lib/rubocop/config_validator.rb +2 -1
  16. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  17. data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
  18. data/lib/rubocop/cop/commissioner.rb +0 -21
  19. data/lib/rubocop/cop/cop.rb +36 -21
  20. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
  21. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
  22. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  23. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  24. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  25. data/lib/rubocop/cop/generator.rb +4 -3
  26. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  27. data/lib/rubocop/cop/ignored_node.rb +1 -3
  28. data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
  29. data/lib/rubocop/cop/layout/class_structure.rb +19 -16
  30. data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
  31. data/lib/rubocop/cop/layout/condition_position.rb +12 -2
  32. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  33. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  34. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +128 -0
  35. data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
  36. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -4
  37. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
  38. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  39. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  40. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  41. data/lib/rubocop/cop/layout/hash_alignment.rb +7 -7
  42. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
  43. data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
  44. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  45. data/lib/rubocop/cop/layout/line_length.rb +21 -18
  46. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  47. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  48. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
  49. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  50. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  51. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
  52. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
  53. data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
  54. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  55. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
  56. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  57. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  58. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
  59. data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
  60. data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
  61. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
  62. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  63. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
  64. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
  65. data/lib/rubocop/cop/lint/empty_when.rb +29 -6
  66. data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
  67. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
  68. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  69. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
  70. data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
  71. data/lib/rubocop/cop/lint/loop.rb +1 -1
  72. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
  73. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  74. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  75. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
  76. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
  77. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  78. data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
  79. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +5 -8
  80. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  81. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  82. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  83. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  84. data/lib/rubocop/cop/lint/suppressed_exception.rb +11 -4
  85. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  86. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  87. data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
  88. data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
  89. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
  90. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  91. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
  92. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  93. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  94. data/lib/rubocop/cop/migration/department_name.rb +7 -7
  95. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  96. data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
  97. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
  98. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  99. data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
  100. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  101. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  102. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  103. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  104. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
  105. data/lib/rubocop/cop/mixin/hash_transform_method.rb +8 -1
  106. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  107. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
  108. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  109. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  110. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
  111. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  112. data/lib/rubocop/cop/mixin/range_help.rb +1 -1
  113. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
  114. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -23
  115. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  116. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  117. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  118. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  119. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +3 -3
  120. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  121. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  122. data/lib/rubocop/cop/naming/file_name.rb +28 -17
  123. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  124. data/lib/rubocop/cop/naming/method_name.rb +1 -5
  125. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  126. data/lib/rubocop/cop/registry.rb +63 -10
  127. data/lib/rubocop/cop/severity.rb +1 -3
  128. data/lib/rubocop/cop/style/and_or.rb +2 -2
  129. data/lib/rubocop/cop/style/array_join.rb +1 -1
  130. data/lib/rubocop/cop/style/attr.rb +1 -3
  131. data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
  132. data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
  133. data/lib/rubocop/cop/style/case_equality.rb +1 -1
  134. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  135. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  136. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  137. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
  138. data/lib/rubocop/cop/style/copyright.rb +5 -5
  139. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  140. data/lib/rubocop/cop/style/documentation.rb +2 -2
  141. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  142. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
  143. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  144. data/lib/rubocop/cop/style/empty_method.rb +1 -5
  145. data/lib/rubocop/cop/style/encoding.rb +1 -1
  146. data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
  147. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  148. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
  149. data/lib/rubocop/cop/style/guard_clause.rb +25 -2
  150. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
  151. data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
  152. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  153. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  154. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
  155. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  156. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  157. data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
  158. data/lib/rubocop/cop/style/lambda_call.rb +0 -20
  159. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  160. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  161. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  162. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  163. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
  164. data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
  165. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  166. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  167. data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
  168. data/lib/rubocop/cop/style/next.rb +2 -2
  169. data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
  170. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
  171. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
  172. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  173. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  174. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
  175. data/lib/rubocop/cop/style/redundant_fetch_block.rb +103 -0
  176. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -7
  177. data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
  178. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
  179. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
  180. data/lib/rubocop/cop/style/redundant_self.rb +6 -9
  181. data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
  182. data/lib/rubocop/cop/style/sample.rb +1 -1
  183. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  184. data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
  185. data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
  186. data/lib/rubocop/cop/style/struct_inheritance.rb +21 -0
  187. data/lib/rubocop/cop/style/symbol_array.rb +5 -5
  188. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
  189. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
  190. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
  191. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
  192. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
  193. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
  194. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  195. data/lib/rubocop/cop/style/when_then.rb +1 -1
  196. data/lib/rubocop/cop/style/word_array.rb +1 -1
  197. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  198. data/lib/rubocop/cop/team.rb +69 -25
  199. data/lib/rubocop/cop/util.rb +27 -3
  200. data/lib/rubocop/cop/utils/format_string.rb +18 -0
  201. data/lib/rubocop/cop/variable_force.rb +3 -9
  202. data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
  203. data/lib/rubocop/cop/variable_force/branch.rb +1 -3
  204. data/lib/rubocop/cop/variable_force/scope.rb +1 -0
  205. data/lib/rubocop/cop/variable_force/variable.rb +3 -6
  206. data/lib/rubocop/ext/processed_source.rb +18 -0
  207. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  208. data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
  209. data/lib/rubocop/formatter/formatter_set.rb +2 -4
  210. data/lib/rubocop/formatter/junit_formatter.rb +14 -4
  211. data/lib/rubocop/magic_comment.rb +1 -1
  212. data/lib/rubocop/name_similarity.rb +18 -9
  213. data/lib/rubocop/options.rb +26 -11
  214. data/lib/rubocop/path_util.rb +2 -2
  215. data/lib/rubocop/platform.rb +1 -1
  216. data/lib/rubocop/remote_config.rb +1 -3
  217. data/lib/rubocop/result_cache.rb +5 -7
  218. data/lib/rubocop/rspec/cop_helper.rb +2 -25
  219. data/lib/rubocop/rspec/expect_offense.rb +58 -15
  220. data/lib/rubocop/rspec/shared_contexts.rb +54 -16
  221. data/lib/rubocop/runner.rb +20 -13
  222. data/lib/rubocop/target_finder.rb +8 -8
  223. data/lib/rubocop/target_ruby.rb +4 -1
  224. data/lib/rubocop/version.rb +5 -3
  225. metadata +51 -74
  226. data/lib/rubocop/ast/builder.rb +0 -85
  227. data/lib/rubocop/ast/node.rb +0 -637
  228. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  229. data/lib/rubocop/ast/node/and_node.rb +0 -29
  230. data/lib/rubocop/ast/node/args_node.rb +0 -29
  231. data/lib/rubocop/ast/node/array_node.rb +0 -70
  232. data/lib/rubocop/ast/node/block_node.rb +0 -121
  233. data/lib/rubocop/ast/node/break_node.rb +0 -17
  234. data/lib/rubocop/ast/node/case_match_node.rb +0 -56
  235. data/lib/rubocop/ast/node/case_node.rb +0 -56
  236. data/lib/rubocop/ast/node/class_node.rb +0 -31
  237. data/lib/rubocop/ast/node/def_node.rb +0 -82
  238. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  239. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  240. data/lib/rubocop/ast/node/float_node.rb +0 -12
  241. data/lib/rubocop/ast/node/for_node.rb +0 -53
  242. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  243. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  244. data/lib/rubocop/ast/node/if_node.rb +0 -175
  245. data/lib/rubocop/ast/node/int_node.rb +0 -12
  246. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  247. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  248. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  249. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  250. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  251. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  252. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
  253. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  254. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  255. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  256. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  257. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  258. data/lib/rubocop/ast/node/module_node.rb +0 -24
  259. data/lib/rubocop/ast/node/or_node.rb +0 -29
  260. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  261. data/lib/rubocop/ast/node/range_node.rb +0 -18
  262. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  263. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  264. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  265. data/lib/rubocop/ast/node/return_node.rb +0 -24
  266. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  267. data/lib/rubocop/ast/node/send_node.rb +0 -13
  268. data/lib/rubocop/ast/node/str_node.rb +0 -16
  269. data/lib/rubocop/ast/node/super_node.rb +0 -21
  270. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  271. data/lib/rubocop/ast/node/until_node.rb +0 -35
  272. data/lib/rubocop/ast/node/when_node.rb +0 -53
  273. data/lib/rubocop/ast/node/while_node.rb +0 -35
  274. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  275. data/lib/rubocop/ast/sexp.rb +0 -16
  276. data/lib/rubocop/ast/traversal.rb +0 -202
  277. data/lib/rubocop/node_pattern.rb +0 -887
  278. data/lib/rubocop/processed_source.rb +0 -213
  279. data/lib/rubocop/string_util.rb +0 -14
  280. data/lib/rubocop/token.rb +0 -114
@@ -1,74 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser'
4
3
  require 'rainbow'
5
4
 
6
5
  require 'English'
7
6
  require 'set'
8
7
  require 'forwardable'
8
+ require 'regexp_parser'
9
9
  require 'unicode/display_width/no_string_ext'
10
+ require 'rubocop-ast'
11
+ require_relative 'rubocop/ast_aliases'
10
12
 
11
13
  require_relative 'rubocop/version'
12
14
 
13
15
  require_relative 'rubocop/core_ext/string'
16
+ require_relative 'rubocop/ext/processed_source'
17
+
14
18
  require_relative 'rubocop/path_util'
15
19
  require_relative 'rubocop/file_finder'
16
20
  require_relative 'rubocop/platform'
17
- require_relative 'rubocop/string_util'
18
21
  require_relative 'rubocop/name_similarity'
19
- require_relative 'rubocop/node_pattern'
20
22
  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_match_node'
41
- require_relative 'rubocop/ast/node/case_node'
42
- require_relative 'rubocop/ast/node/class_node'
43
- require_relative 'rubocop/ast/node/def_node'
44
- require_relative 'rubocop/ast/node/defined_node'
45
- require_relative 'rubocop/ast/node/ensure_node'
46
- require_relative 'rubocop/ast/node/for_node'
47
- require_relative 'rubocop/ast/node/forward_args_node'
48
- require_relative 'rubocop/ast/node/float_node'
49
- require_relative 'rubocop/ast/node/hash_node'
50
- require_relative 'rubocop/ast/node/if_node'
51
- require_relative 'rubocop/ast/node/int_node'
52
- require_relative 'rubocop/ast/node/keyword_splat_node'
53
- require_relative 'rubocop/ast/node/module_node'
54
- require_relative 'rubocop/ast/node/or_node'
55
- require_relative 'rubocop/ast/node/pair_node'
56
- require_relative 'rubocop/ast/node/range_node'
57
- require_relative 'rubocop/ast/node/regexp_node'
58
- require_relative 'rubocop/ast/node/resbody_node'
59
- require_relative 'rubocop/ast/node/retry_node'
60
- require_relative 'rubocop/ast/node/return_node'
61
- require_relative 'rubocop/ast/node/self_class_node'
62
- require_relative 'rubocop/ast/node/send_node'
63
- require_relative 'rubocop/ast/node/str_node'
64
- require_relative 'rubocop/ast/node/super_node'
65
- require_relative 'rubocop/ast/node/symbol_node'
66
- require_relative 'rubocop/ast/node/until_node'
67
- require_relative 'rubocop/ast/node/when_node'
68
- require_relative 'rubocop/ast/node/while_node'
69
- require_relative 'rubocop/ast/node/yield_node'
70
- require_relative 'rubocop/ast/builder'
71
- require_relative 'rubocop/ast/traversal'
72
23
  require_relative 'rubocop/error'
73
24
  require_relative 'rubocop/warning'
74
25
 
@@ -147,6 +98,7 @@ require_relative 'rubocop/cop/mixin/percent_literal'
147
98
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
148
99
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
149
100
  require_relative 'rubocop/cop/mixin/rational_literal'
101
+ require_relative 'rubocop/cop/mixin/regexp_literal_help'
150
102
  require_relative 'rubocop/cop/mixin/rescue_node'
151
103
  require_relative 'rubocop/cop/mixin/safe_assignment'
152
104
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
@@ -213,10 +165,11 @@ require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
213
165
  require_relative 'rubocop/cop/layout/empty_line_between_defs'
214
166
  require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
215
167
  require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
168
+ require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
216
169
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
217
170
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
218
171
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
219
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
172
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
220
173
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
221
174
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
222
175
  require_relative 'rubocop/cop/layout/empty_lines'
@@ -289,8 +242,10 @@ require_relative 'rubocop/cop/lint/assignment_in_condition'
289
242
  require_relative 'rubocop/cop/lint/big_decimal_new'
290
243
  require_relative 'rubocop/cop/lint/boolean_symbol'
291
244
  require_relative 'rubocop/cop/lint/circular_argument_reference'
245
+ require_relative 'rubocop/cop/lint/constant_resolution'
292
246
  require_relative 'rubocop/cop/lint/debugger'
293
247
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
248
+ require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
294
249
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
295
250
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
296
251
  require_relative 'rubocop/cop/lint/duplicate_hash_key'
@@ -315,6 +270,7 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
315
270
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
316
271
  require_relative 'rubocop/cop/lint/loop'
317
272
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
273
+ require_relative 'rubocop/cop/lint/mixed_regexp_capture_types'
318
274
  require_relative 'rubocop/cop/lint/multiple_comparison'
319
275
  require_relative 'rubocop/cop/lint/nested_method_definition'
320
276
  require_relative 'rubocop/cop/lint/nested_percent_literal'
@@ -366,6 +322,7 @@ require_relative 'rubocop/cop/lint/useless_else_without_rescue'
366
322
  require_relative 'rubocop/cop/lint/useless_setter_call'
367
323
  require_relative 'rubocop/cop/lint/void'
368
324
 
325
+ require_relative 'rubocop/cop/metrics/utils/iterating_block'
369
326
  require_relative 'rubocop/cop/metrics/cyclomatic_complexity'
370
327
  # relies on cyclomatic_complexity
371
328
  require_relative 'rubocop/cop/metrics/utils/abc_size_calculator'
@@ -468,11 +425,10 @@ require_relative 'rubocop/cop/style/lambda'
468
425
  require_relative 'rubocop/cop/style/lambda_call'
469
426
  require_relative 'rubocop/cop/style/line_end_concatenation'
470
427
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
471
- # rubocop:disable Layout/LineLength
472
428
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
429
+ require_relative 'rubocop/cop/style/redundant_fetch_block'
473
430
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
474
431
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
475
- # rubocop:enable Layout/LineLength
476
432
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
477
433
  require_relative 'rubocop/cop/style/method_def_parentheses'
478
434
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -526,6 +482,8 @@ require_relative 'rubocop/cop/style/redundant_freeze'
526
482
  require_relative 'rubocop/cop/style/redundant_interpolation'
527
483
  require_relative 'rubocop/cop/style/redundant_parentheses'
528
484
  require_relative 'rubocop/cop/style/redundant_percent_q'
485
+ require_relative 'rubocop/cop/style/redundant_regexp_character_class'
486
+ require_relative 'rubocop/cop/style/redundant_regexp_escape'
529
487
  require_relative 'rubocop/cop/style/redundant_return'
530
488
  require_relative 'rubocop/cop/style/redundant_self'
531
489
  require_relative 'rubocop/cop/style/redundant_sort'
@@ -542,6 +500,7 @@ require_relative 'rubocop/cop/style/send'
542
500
  require_relative 'rubocop/cop/style/signal_exception'
543
501
  require_relative 'rubocop/cop/style/single_line_block_params'
544
502
  require_relative 'rubocop/cop/style/single_line_methods'
503
+ require_relative 'rubocop/cop/style/slicing_with_range'
545
504
  require_relative 'rubocop/cop/style/special_global_vars'
546
505
  require_relative 'rubocop/cop/style/stabby_lambda_parentheses'
547
506
  require_relative 'rubocop/cop/style/stderr_puts'
@@ -613,10 +572,8 @@ require_relative 'rubocop/config_obsoletion'
613
572
  require_relative 'rubocop/config_store'
614
573
  require_relative 'rubocop/config_validator'
615
574
  require_relative 'rubocop/target_finder'
616
- require_relative 'rubocop/token'
617
575
  require_relative 'rubocop/comment_config'
618
576
  require_relative 'rubocop/magic_comment'
619
- require_relative 'rubocop/processed_source'
620
577
  require_relative 'rubocop/result_cache'
621
578
  require_relative 'rubocop/runner'
622
579
  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
@@ -75,7 +75,7 @@ module RuboCop
75
75
 
76
76
  def validate_options_vs_config
77
77
  if @options[:parallel] &&
78
- !@config_store.for(Dir.pwd).for_all_cops['UseCache']
78
+ !@config_store.for_dir(Dir.pwd).for_all_cops['UseCache']
79
79
  raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \
80
80
  'execution, so combining with AllCops: ' \
81
81
  'UseCache: false is not allowed.'
@@ -123,7 +123,7 @@ module RuboCop
123
123
  if @options[:auto_gen_config]
124
124
  formatter = 'autogenconf'
125
125
  else
126
- cfg = @config_store.for(Dir.pwd).for_all_cops
126
+ cfg = @config_store.for_dir(Dir.pwd).for_all_cops
127
127
  formatter = cfg['DefaultFormatter'] || 'progress'
128
128
  end
129
129
  [[formatter, @options[:output_path]]]
@@ -25,10 +25,10 @@ module RuboCop
25
25
  private
26
26
 
27
27
  def maybe_run_line_length_cop
28
- if !line_length_enabled?(@config_store.for(Dir.pwd))
28
+ if !line_length_enabled?(@config_store.for_dir(Dir.pwd))
29
29
  skip_line_length_cop(PHASE_1_DISABLED)
30
30
  elsif !same_max_line_length?(
31
- @config_store.for(Dir.pwd), ConfigLoader.default_configuration
31
+ @config_store.for_dir(Dir.pwd), ConfigLoader.default_configuration
32
32
  )
33
33
  skip_line_length_cop(PHASE_1_OVERRIDDEN)
34
34
  else
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # RuboCop will start looking for the configuration file in the directory
28
28
  # where the inspected file is and continue its way up to the root directory.
29
29
  #
30
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
30
+ # See https://docs.rubocop.org/rubocop/configuration
31
31
  DESC
32
32
 
33
33
  File.open(DOTFILE, 'w') do |f|
@@ -42,18 +42,14 @@ module RuboCop
42
42
  selected_cops_of_department(registry, department)
43
43
  end
44
44
 
45
- if show_all
46
- puts "# Department '#{department}' (#{selected_cops.length}):"
47
- end
45
+ puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
48
46
 
49
47
  print_cop_details(selected_cops)
50
48
  end
51
49
 
52
50
  def print_cop_details(cops)
53
51
  cops.each do |cop|
54
- if cop.new(@config).support_autocorrect?
55
- puts '# Supports --auto-correct'
56
- end
52
+ puts '# Supports --auto-correct' if cop.new(@config).support_autocorrect?
57
53
  puts "#{cop.cop_name}:"
58
54
  puts config_lines(cop)
59
55
  puts
@@ -124,7 +124,7 @@ module RuboCop
124
124
  end
125
125
 
126
126
  def directive_on_comment_line?(comment)
127
- comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
127
+ comment.text[1..-1].match?(COMMENT_DIRECTIVE_REGEXP)
128
128
  end
129
129
 
130
130
  def each_directive
@@ -152,7 +152,7 @@ module RuboCop
152
152
  return true if File.extname(file) == '.gemspec'
153
153
 
154
154
  file_to_include?(file) do |pattern, relative_path, absolute_path|
155
- pattern.to_s =~ /[A-Z]/ &&
155
+ /[A-Z]/.match?(pattern.to_s) &&
156
156
  (match_path?(pattern, relative_path) ||
157
157
  match_path?(pattern, absolute_path))
158
158
  end
@@ -261,9 +261,13 @@ module RuboCop
261
261
 
262
262
  def enable_cop?(qualified_cop_name, cop_options)
263
263
  department = department_of(qualified_cop_name)
264
+ cop_enabled = cop_options.fetch('Enabled') do
265
+ !for_all_cops['DisabledByDefault']
266
+ end
267
+ return true if cop_enabled == 'override_department'
264
268
  return false if department && department['Enabled'] == false
265
269
 
266
- cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
270
+ cop_enabled
267
271
  end
268
272
 
269
273
  def department_of(qualified_cop_name)
@@ -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
 
@@ -94,9 +95,7 @@ module RuboCop
94
95
  end
95
96
 
96
97
  merge_with_default(config, config_file).tap do |merged_config|
97
- unless possible_new_cops?(config)
98
- warn_on_pending_cops(merged_config.pending_cops)
99
- end
98
+ warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
100
99
  end
101
100
  end
102
101
 
@@ -132,12 +131,12 @@ module RuboCop
132
131
  '`false` in your `.rubocop.yml` file:').yellow
133
132
 
134
133
  pending_cops.each do |cop|
135
- warn Rainbow(
136
- " - #{cop.name} (#{cop.metadata['VersionAdded']})"
137
- ).yellow
134
+ version = cop.metadata['VersionAdded'] || 'N/A'
135
+
136
+ warn Rainbow(" - #{cop.name} (#{version})").yellow
138
137
  end
139
138
 
140
- warn Rainbow('For more information: https://docs.rubocop.org/en/latest/versioning/').yellow
139
+ warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
141
140
  end
142
141
 
143
142
  # Merges the given configuration with the default one. If
@@ -206,9 +205,7 @@ module RuboCop
206
205
  def write_config_file(file_name, file_string, rubocop_yml_contents)
207
206
  File.open(file_name, 'w') do |f|
208
207
  f.write "inherit_from:#{file_string}\n"
209
- if /\S/.match?(rubocop_yml_contents)
210
- f.write "\n#{rubocop_yml_contents}"
211
- end
208
+ f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
212
209
  end
213
210
  end
214
211
 
@@ -217,15 +214,16 @@ module RuboCop
217
214
  end
218
215
 
219
216
  def load_yaml_configuration(absolute_path)
220
- 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
221
221
  check_duplication(yaml_code, absolute_path)
222
222
  hash = yaml_safe_load(yaml_code, absolute_path) || {}
223
223
 
224
224
  puts "configuration from #{absolute_path}" if debug?
225
225
 
226
- unless hash.is_a?(Hash)
227
- raise(TypeError, "Malformed configuration in #{absolute_path}")
228
- end
226
+ raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
229
227
 
230
228
  hash
231
229
  end
@@ -241,8 +239,7 @@ module RuboCop
241
239
  "#{smart_path}:#{line1}: " \
242
240
  "`#{value}` is concealed by line #{line2}"
243
241
  else
244
- "#{smart_path}: " \
245
- "`#{value}` is concealed by duplicate"
242
+ "#{smart_path}: `#{value}` is concealed by duplicate"
246
243
  end
247
244
  warn Rainbow(message).yellow
248
245
  end
@@ -263,13 +260,11 @@ module RuboCop
263
260
  SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
264
261
  # Ruby 2.6+
265
262
  elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
266
- YAML.safe_load(
267
- yaml_code,
268
- permitted_classes: [Regexp, Symbol],
269
- permitted_symbols: [],
270
- aliases: true,
271
- filename: filename
272
- )
263
+ YAML.safe_load(yaml_code,
264
+ permitted_classes: [Regexp, Symbol],
265
+ permitted_symbols: [],
266
+ aliases: true,
267
+ filename: filename)
273
268
  else
274
269
  YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
275
270
  end
@@ -17,10 +17,12 @@ module RuboCop
17
17
  end
18
18
  end
19
19
 
20
+ # rubocop:disable Metrics/MethodLength
20
21
  def resolve_inheritance(path, hash, file, debug)
21
22
  inherited_files = Array(hash['inherit_from'])
22
23
  base_configs(path, inherited_files, file)
23
24
  .reverse.each_with_index do |base_config, index|
25
+ override_department_setting_for_cops(base_config, hash)
24
26
  base_config.each do |k, v|
25
27
  next unless v.is_a?(Hash)
26
28
 
@@ -34,6 +36,7 @@ module RuboCop
34
36
  end
35
37
  end
36
38
  end
39
+ # rubocop:enable Metrics/MethodLength
37
40
 
38
41
  def resolve_inheritance_from_gems(hash)
39
42
  gems = hash.delete('inherit_gem')
@@ -68,9 +71,7 @@ module RuboCop
68
71
  end
69
72
  end
70
73
 
71
- if disabled_by_default
72
- config = handle_disabled_by_default(config, default_configuration)
73
- end
74
+ config = handle_disabled_by_default(config, default_configuration) if disabled_by_default
74
75
 
75
76
  opts = { inherit_mode: config['inherit_mode'] || {},
76
77
  unset_nil: unset_nil }
@@ -100,8 +101,30 @@ module RuboCop
100
101
  end
101
102
  # rubocop:enable Metrics/AbcSize
102
103
 
104
+ # An `Enabled: true` setting in user configuration for a cop overrides an
105
+ # `Enabled: false` setting for its department.
106
+ def override_department_setting_for_cops(base_hash, derived_hash)
107
+ derived_hash.each_key do |key|
108
+ next unless key =~ %r{(.*)/.*}
109
+
110
+ department = Regexp.last_match(1)
111
+ next unless disabled?(derived_hash, department) ||
112
+ disabled?(base_hash, department)
113
+
114
+ # The `override_department` setting for the `Enabled` parameter is an
115
+ # internal setting that's not documented in the manual. It will cause a
116
+ # cop to be enabled later, when logic surrounding enabled/disabled it
117
+ # run, even though its department is disabled.
118
+ derived_hash[key]['Enabled'] = 'override_department' if derived_hash[key]['Enabled']
119
+ end
120
+ end
121
+
103
122
  private
104
123
 
124
+ def disabled?(hash, department)
125
+ hash[department] && hash[department]['Enabled'] == false
126
+ end
127
+
105
128
  def duplicate_setting?(base_hash, derived_hash, key, inherited_file)
106
129
  return false if inherited_file.nil? # Not inheritance resolving merge
107
130
  return false if inherited_file.start_with?('..') # Legitimate override
@@ -148,10 +171,20 @@ module RuboCop
148
171
 
149
172
  def inherited_file(path, inherit_from, file)
150
173
  if remote_file?(inherit_from)
174
+ # A remote configuration, e.g. `inherit_from: http://example.com/rubocop.yml`.
151
175
  RemoteConfig.new(inherit_from, File.dirname(path))
176
+ elsif Pathname.new(inherit_from).absolute?
177
+ # An absolute path to a config, e.g. `inherit_from: /Users/me/rubocop.yml`.
178
+ # The path may come from `inherit_gem` option, where a gem name is expanded
179
+ # to an absolute path to that gem.
180
+ print 'Inheriting ' if ConfigLoader.debug?
181
+ inherit_from
152
182
  elsif file.is_a?(RemoteConfig)
183
+ # A path relative to a URL, e.g. `inherit_from: configs/default.yml`
184
+ # in a config included with `inherit_from: http://example.com/rubocop.yml`
153
185
  file.inherit_from_remote(inherit_from, path)
154
186
  else
187
+ # A local relative path, e.g. `inherit_from: default.yml`
155
188
  print 'Inheriting ' if ConfigLoader.debug?
156
189
  File.expand_path(inherit_from, File.dirname(path))
157
190
  end
@@ -159,7 +192,7 @@ module RuboCop
159
192
 
160
193
  def remote_file?(uri)
161
194
  regex = URI::DEFAULT_PARSER.make_regexp(%w[http https])
162
- uri =~ /\A#{regex}\z/
195
+ /\A#{regex}\z/.match?(uri)
163
196
  end
164
197
 
165
198
  def handle_disabled_by_default(config, new_default_configuration)
@@ -185,8 +218,14 @@ module RuboCop
185
218
  end
186
219
 
187
220
  def gem_config_path(gem_name, relative_config_path)
188
- spec = Gem::Specification.find_by_name(gem_name)
189
- File.join(spec.gem_dir, relative_config_path)
221
+ if defined?(Bundler)
222
+ gem = Bundler.load.specs[gem_name].first
223
+ gem_path = gem.full_gem_path if gem
224
+ end
225
+
226
+ gem_path ||= Gem::Specification.find_by_name(gem_name).gem_dir
227
+
228
+ File.join(gem_path, relative_config_path)
190
229
  rescue Gem::LoadError => e
191
230
  raise Gem::LoadError,
192
231
  "Unable to find gem #{gem_name}; is the gem installed? #{e}"