rubocop 0.48.1 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (851) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +84 -50
  4. data/assets/output.html.erb +1 -1
  5. data/config/default.yml +4311 -902
  6. data/config/obsoletion.yml +200 -0
  7. data/exe/rubocop +15 -0
  8. data/lib/rubocop.rb +679 -481
  9. data/lib/rubocop/ast_aliases.rb +8 -0
  10. data/lib/rubocop/cached_data.rb +5 -10
  11. data/lib/rubocop/cli.rb +73 -129
  12. data/lib/rubocop/cli/command.rb +22 -0
  13. data/lib/rubocop/cli/command/auto_genenerate_config.rb +132 -0
  14. data/lib/rubocop/cli/command/base.rb +35 -0
  15. data/lib/rubocop/cli/command/execute_runner.rb +100 -0
  16. data/lib/rubocop/cli/command/init_dotfile.rb +44 -0
  17. data/lib/rubocop/cli/command/show_cops.rb +74 -0
  18. data/lib/rubocop/cli/command/suggest_extensions.rb +81 -0
  19. data/lib/rubocop/cli/command/version.rb +18 -0
  20. data/lib/rubocop/cli/environment.rb +22 -0
  21. data/lib/rubocop/comment_config.rb +80 -78
  22. data/lib/rubocop/config.rb +124 -259
  23. data/lib/rubocop/config_loader.rb +182 -133
  24. data/lib/rubocop/config_loader_resolver.rb +237 -14
  25. data/lib/rubocop/config_obsoletion.rb +103 -0
  26. data/lib/rubocop/config_obsoletion/changed_enforced_styles.rb +33 -0
  27. data/lib/rubocop/config_obsoletion/changed_parameter.rb +21 -0
  28. data/lib/rubocop/config_obsoletion/cop_rule.rb +33 -0
  29. data/lib/rubocop/config_obsoletion/extracted_cop.rb +44 -0
  30. data/lib/rubocop/config_obsoletion/parameter_rule.rb +44 -0
  31. data/lib/rubocop/config_obsoletion/removed_cop.rb +41 -0
  32. data/lib/rubocop/config_obsoletion/renamed_cop.rb +34 -0
  33. data/lib/rubocop/config_obsoletion/rule.rb +41 -0
  34. data/lib/rubocop/config_obsoletion/split_cop.rb +27 -0
  35. data/lib/rubocop/config_regeneration.rb +33 -0
  36. data/lib/rubocop/config_store.rb +31 -7
  37. data/lib/rubocop/config_validator.rb +234 -0
  38. data/lib/rubocop/cop/autocorrect_logic.rb +83 -4
  39. data/lib/rubocop/cop/badge.rb +16 -32
  40. data/lib/rubocop/cop/base.rb +450 -0
  41. data/lib/rubocop/cop/bundler/duplicated_gem.rb +44 -16
  42. data/lib/rubocop/cop/bundler/gem_comment.rb +171 -0
  43. data/lib/rubocop/cop/bundler/gem_version.rb +99 -0
  44. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +62 -0
  45. data/lib/rubocop/cop/bundler/ordered_gems.rb +18 -60
  46. data/lib/rubocop/cop/commissioner.rb +119 -68
  47. data/lib/rubocop/cop/cop.rb +93 -169
  48. data/lib/rubocop/cop/corrector.rb +81 -98
  49. data/lib/rubocop/cop/correctors/alignment_corrector.rb +136 -0
  50. data/lib/rubocop/cop/correctors/condition_corrector.rb +25 -0
  51. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +51 -0
  52. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +25 -0
  53. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +72 -0
  54. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +136 -0
  55. data/lib/rubocop/cop/correctors/line_break_corrector.rb +58 -0
  56. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +97 -0
  57. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +42 -0
  58. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +28 -0
  59. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +106 -0
  60. data/lib/rubocop/cop/correctors/punctuation_corrector.rb +27 -0
  61. data/lib/rubocop/cop/correctors/space_corrector.rb +46 -0
  62. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +23 -0
  63. data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +40 -0
  64. data/lib/rubocop/cop/documentation.rb +22 -0
  65. data/lib/rubocop/cop/exclude_limit.rb +26 -0
  66. data/lib/rubocop/cop/force.rb +3 -1
  67. data/lib/rubocop/cop/gemspec/date_assignment.rb +57 -0
  68. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +105 -0
  69. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +102 -0
  70. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +113 -0
  71. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +57 -0
  72. data/lib/rubocop/cop/generator.rb +212 -0
  73. data/lib/rubocop/cop/generator/configuration_injector.rb +65 -0
  74. data/lib/rubocop/cop/generator/require_file_injector.rb +75 -0
  75. data/lib/rubocop/cop/ignored_node.rb +1 -3
  76. data/lib/rubocop/cop/internal_affairs.rb +15 -0
  77. data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +68 -0
  78. data/lib/rubocop/cop/internal_affairs/example_description.rb +92 -0
  79. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +50 -0
  80. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +44 -0
  81. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
  82. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +41 -0
  83. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +56 -0
  84. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +62 -0
  85. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +65 -0
  86. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +53 -0
  87. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +76 -0
  88. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +148 -0
  89. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +52 -0
  90. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +100 -0
  91. data/lib/rubocop/cop/layout/argument_alignment.rb +110 -0
  92. data/lib/rubocop/cop/layout/array_alignment.rb +84 -0
  93. data/lib/rubocop/cop/{style/indent_assignment.rb → layout/assignment_indentation.rb} +21 -7
  94. data/lib/rubocop/cop/layout/begin_end_alignment.rb +74 -0
  95. data/lib/rubocop/cop/{lint → layout}/block_alignment.rb +67 -60
  96. data/lib/rubocop/cop/layout/block_end_newline.rb +60 -0
  97. data/lib/rubocop/cop/layout/case_indentation.rb +203 -0
  98. data/lib/rubocop/cop/layout/class_structure.rb +324 -0
  99. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +124 -0
  100. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +191 -0
  101. data/lib/rubocop/cop/layout/comment_indentation.rb +137 -0
  102. data/lib/rubocop/cop/{lint → layout}/condition_position.rb +20 -8
  103. data/lib/rubocop/cop/{lint → layout}/def_end_alignment.rb +19 -24
  104. data/lib/rubocop/cop/{style → layout}/dot_position.rb +47 -27
  105. data/lib/rubocop/cop/layout/else_alignment.rb +156 -0
  106. data/lib/rubocop/cop/layout/empty_comment.rb +151 -0
  107. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +174 -0
  108. data/lib/rubocop/cop/{style → layout}/empty_line_after_magic_comment.rb +18 -17
  109. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +136 -0
  110. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +252 -0
  111. data/lib/rubocop/cop/{style → layout}/empty_lines.rb +26 -15
  112. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +206 -0
  113. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +103 -0
  114. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +118 -0
  115. data/lib/rubocop/cop/{style → layout}/empty_lines_around_begin_body.rb +7 -7
  116. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +38 -0
  117. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +85 -0
  118. data/lib/rubocop/cop/{style → layout}/empty_lines_around_exception_handling_keywords.rb +16 -17
  119. data/lib/rubocop/cop/{style → layout}/empty_lines_around_method_body.rb +10 -9
  120. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +59 -0
  121. data/lib/rubocop/cop/{lint → layout}/end_alignment.rb +59 -33
  122. data/lib/rubocop/cop/layout/end_of_line.rb +92 -0
  123. data/lib/rubocop/cop/layout/extra_spacing.rb +182 -0
  124. data/lib/rubocop/cop/layout/first_argument_indentation.rb +276 -0
  125. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +173 -0
  126. data/lib/rubocop/cop/{style → layout}/first_array_element_line_break.rb +5 -5
  127. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +200 -0
  128. data/lib/rubocop/cop/{style → layout}/first_hash_element_line_break.rb +4 -4
  129. data/lib/rubocop/cop/{style → layout}/first_method_argument_line_break.rb +9 -10
  130. data/lib/rubocop/cop/{style → layout}/first_method_parameter_line_break.rb +7 -7
  131. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +101 -0
  132. data/lib/rubocop/cop/layout/hash_alignment.rb +382 -0
  133. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +305 -0
  134. data/lib/rubocop/cop/layout/heredoc_indentation.rb +172 -0
  135. data/lib/rubocop/cop/layout/indentation_consistency.rb +205 -0
  136. data/lib/rubocop/cop/layout/indentation_style.rb +110 -0
  137. data/lib/rubocop/cop/{style → layout}/indentation_width.rb +138 -66
  138. data/lib/rubocop/cop/layout/initial_indentation.rb +55 -0
  139. data/lib/rubocop/cop/layout/leading_comment_space.rb +121 -0
  140. data/lib/rubocop/cop/layout/leading_empty_lines.rb +48 -0
  141. data/lib/rubocop/cop/layout/line_length.rb +267 -0
  142. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +115 -0
  143. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +35 -0
  144. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +117 -0
  145. data/lib/rubocop/cop/layout/multiline_block_layout.rb +159 -0
  146. data/lib/rubocop/cop/{style → layout}/multiline_hash_brace_layout.rb +53 -19
  147. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +46 -0
  148. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +47 -0
  149. data/lib/rubocop/cop/{style → layout}/multiline_method_call_brace_layout.rb +69 -35
  150. data/lib/rubocop/cop/{style → layout}/multiline_method_call_indentation.rb +57 -41
  151. data/lib/rubocop/cop/{style → layout}/multiline_method_definition_brace_layout.rb +84 -38
  152. data/lib/rubocop/cop/{style → layout}/multiline_operation_indentation.rb +51 -11
  153. data/lib/rubocop/cop/layout/parameter_alignment.rb +119 -0
  154. data/lib/rubocop/cop/layout/redundant_line_break.rb +137 -0
  155. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +198 -0
  156. data/lib/rubocop/cop/layout/single_line_block_chain.rb +53 -0
  157. data/lib/rubocop/cop/{style → layout}/space_after_colon.rb +19 -10
  158. data/lib/rubocop/cop/layout/space_after_comma.rb +32 -0
  159. data/lib/rubocop/cop/layout/space_after_method_name.rb +39 -0
  160. data/lib/rubocop/cop/{style → layout}/space_after_not.rb +14 -14
  161. data/lib/rubocop/cop/{style → layout}/space_after_semicolon.rb +12 -4
  162. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +162 -0
  163. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +88 -0
  164. data/lib/rubocop/cop/{style → layout}/space_around_keyword.rb +69 -37
  165. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +98 -0
  166. data/lib/rubocop/cop/layout/space_around_operators.rb +241 -0
  167. data/lib/rubocop/cop/layout/space_before_block_braces.rb +152 -0
  168. data/lib/rubocop/cop/layout/space_before_brackets.rb +65 -0
  169. data/lib/rubocop/cop/layout/space_before_comma.rb +29 -0
  170. data/lib/rubocop/cop/layout/space_before_comment.rb +34 -0
  171. data/lib/rubocop/cop/{style → layout}/space_before_first_arg.rb +24 -17
  172. data/lib/rubocop/cop/layout/space_before_semicolon.rb +24 -0
  173. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +72 -0
  174. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +222 -0
  175. data/lib/rubocop/cop/{style → layout}/space_inside_array_percent_literal.rb +10 -20
  176. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +243 -0
  177. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +181 -0
  178. data/lib/rubocop/cop/layout/space_inside_parens.rb +130 -0
  179. data/lib/rubocop/cop/{style → layout}/space_inside_percent_literal_delimiters.rb +16 -20
  180. data/lib/rubocop/cop/{style → layout}/space_inside_range_literal.rb +8 -17
  181. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +139 -0
  182. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +64 -0
  183. data/lib/rubocop/cop/layout/trailing_empty_lines.rb +108 -0
  184. data/lib/rubocop/cop/layout/trailing_whitespace.rb +101 -0
  185. data/lib/rubocop/cop/legacy/corrections_proxy.rb +43 -0
  186. data/lib/rubocop/cop/legacy/corrector.rb +27 -0
  187. data/lib/rubocop/cop/lint/ambiguous_assignment.rb +54 -0
  188. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +30 -22
  189. data/lib/rubocop/cop/lint/ambiguous_operator.rb +57 -9
  190. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +37 -7
  191. data/lib/rubocop/cop/lint/assignment_in_condition.rb +40 -23
  192. data/lib/rubocop/cop/lint/big_decimal_new.rb +44 -0
  193. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +55 -0
  194. data/lib/rubocop/cop/lint/boolean_symbol.rb +58 -0
  195. data/lib/rubocop/cop/lint/circular_argument_reference.rb +5 -16
  196. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +100 -0
  197. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  198. data/lib/rubocop/cop/lint/debugger.rb +63 -33
  199. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +101 -41
  200. data/lib/rubocop/cop/lint/deprecated_constants.rb +80 -0
  201. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +148 -0
  202. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +87 -0
  203. data/lib/rubocop/cop/lint/duplicate_branch.rb +154 -0
  204. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +4 -14
  205. data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
  206. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +3 -5
  207. data/lib/rubocop/cop/lint/duplicate_methods.rb +108 -24
  208. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +77 -0
  209. data/lib/rubocop/cop/lint/duplicate_require.rb +47 -0
  210. data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +47 -0
  211. data/lib/rubocop/cop/lint/each_with_object_argument.rb +9 -4
  212. data/lib/rubocop/cop/lint/else_layout.rb +33 -8
  213. data/lib/rubocop/cop/lint/empty_block.rb +98 -0
  214. data/lib/rubocop/cop/lint/empty_class.rb +93 -0
  215. data/lib/rubocop/cop/lint/empty_conditional_body.rb +67 -0
  216. data/lib/rubocop/cop/lint/empty_ensure.rb +6 -8
  217. data/lib/rubocop/cop/lint/empty_expression.rb +3 -3
  218. data/lib/rubocop/cop/lint/empty_file.rb +48 -0
  219. data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
  220. data/lib/rubocop/cop/lint/empty_interpolation.rb +8 -11
  221. data/lib/rubocop/cop/lint/empty_when.rb +32 -9
  222. data/lib/rubocop/cop/lint/ensure_return.rb +31 -15
  223. data/lib/rubocop/cop/lint/erb_new_arguments.rb +162 -0
  224. data/lib/rubocop/cop/lint/flip_flop.rb +38 -0
  225. data/lib/rubocop/cop/lint/float_comparison.rb +93 -0
  226. data/lib/rubocop/cop/lint/float_out_of_range.rb +6 -7
  227. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +93 -81
  228. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +38 -0
  229. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +154 -0
  230. data/lib/rubocop/cop/lint/identity_comparison.rb +51 -0
  231. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +27 -21
  232. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +44 -66
  233. data/lib/rubocop/cop/lint/inherit_exception.rb +43 -21
  234. data/lib/rubocop/cop/lint/interpolation_check.rb +53 -0
  235. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +44 -0
  236. data/lib/rubocop/cop/lint/{literal_in_condition.rb → literal_as_condition.rb} +48 -28
  237. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +71 -20
  238. data/lib/rubocop/cop/lint/loop.rb +31 -9
  239. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +81 -0
  240. data/lib/rubocop/cop/lint/missing_super.rb +101 -0
  241. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +36 -0
  242. data/lib/rubocop/cop/lint/multiple_comparison.rb +48 -0
  243. data/lib/rubocop/cop/lint/nested_method_definition.rb +23 -28
  244. data/lib/rubocop/cop/lint/nested_percent_literal.rb +63 -0
  245. data/lib/rubocop/cop/lint/next_without_accumulator.rb +5 -4
  246. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +58 -0
  247. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +169 -0
  248. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +20 -19
  249. data/lib/rubocop/cop/lint/number_conversion.rb +155 -0
  250. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +47 -0
  251. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +39 -0
  252. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +83 -0
  253. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +96 -0
  254. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +40 -17
  255. data/lib/rubocop/cop/lint/percent_string_array.rb +18 -34
  256. data/lib/rubocop/cop/lint/percent_symbol_array.rb +19 -17
  257. data/lib/rubocop/cop/lint/raise_exception.rb +87 -0
  258. data/lib/rubocop/cop/lint/rand_one.rb +13 -6
  259. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +262 -0
  260. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +128 -0
  261. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +50 -0
  262. data/lib/rubocop/cop/lint/redundant_require_statement.rb +49 -0
  263. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +77 -0
  264. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +209 -0
  265. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +52 -0
  266. data/lib/rubocop/cop/lint/redundant_with_index.rb +77 -0
  267. data/lib/rubocop/cop/lint/redundant_with_object.rb +78 -0
  268. data/lib/rubocop/cop/lint/regexp_as_condition.rb +31 -0
  269. data/lib/rubocop/cop/lint/require_parentheses.rb +11 -8
  270. data/lib/rubocop/cop/lint/rescue_exception.rb +5 -5
  271. data/lib/rubocop/cop/lint/rescue_type.rb +88 -0
  272. data/lib/rubocop/cop/lint/return_in_void_context.rb +71 -0
  273. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +22 -30
  274. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +92 -0
  275. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +46 -0
  276. data/lib/rubocop/cop/lint/script_permission.rb +73 -0
  277. data/lib/rubocop/cop/lint/self_assignment.rb +78 -0
  278. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +83 -0
  279. data/lib/rubocop/cop/lint/shadowed_argument.rb +176 -0
  280. data/lib/rubocop/cop/lint/shadowed_exception.rb +77 -43
  281. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +24 -10
  282. data/lib/rubocop/cop/lint/struct_new_override.rb +59 -0
  283. data/lib/rubocop/cop/lint/suppressed_exception.rb +132 -0
  284. data/lib/rubocop/cop/lint/symbol_conversion.rb +178 -0
  285. data/lib/rubocop/cop/lint/syntax.rb +17 -32
  286. data/lib/rubocop/cop/lint/to_enum_arguments.rb +89 -0
  287. data/lib/rubocop/cop/lint/to_json.rb +49 -0
  288. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +34 -0
  289. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +55 -0
  290. data/lib/rubocop/cop/lint/triple_quotes.rb +71 -0
  291. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +31 -13
  292. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +85 -0
  293. data/lib/rubocop/cop/lint/unified_integer.rb +10 -10
  294. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +204 -0
  295. data/lib/rubocop/cop/lint/unreachable_code.rb +57 -12
  296. data/lib/rubocop/cop/lint/unreachable_loop.rb +196 -0
  297. data/lib/rubocop/cop/lint/unused_block_argument.rb +41 -14
  298. data/lib/rubocop/cop/lint/unused_method_argument.rb +70 -14
  299. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +79 -0
  300. data/lib/rubocop/cop/lint/uri_regexp.rb +38 -0
  301. data/lib/rubocop/cop/lint/useless_access_modifier.rb +120 -59
  302. data/lib/rubocop/cop/lint/useless_assignment.rb +13 -20
  303. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +10 -11
  304. data/lib/rubocop/cop/lint/useless_method_definition.rb +68 -0
  305. data/lib/rubocop/cop/lint/useless_setter_call.rb +30 -22
  306. data/lib/rubocop/cop/lint/useless_times.rb +109 -0
  307. data/lib/rubocop/cop/lint/void.rb +82 -50
  308. data/lib/rubocop/cop/message_annotator.rb +48 -24
  309. data/lib/rubocop/cop/metrics/abc_size.rb +29 -20
  310. data/lib/rubocop/cop/metrics/block_length.rb +54 -6
  311. data/lib/rubocop/cop/metrics/block_nesting.rb +7 -11
  312. data/lib/rubocop/cop/metrics/class_length.rb +44 -3
  313. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +38 -5
  314. data/lib/rubocop/cop/metrics/method_length.rb +43 -6
  315. data/lib/rubocop/cop/metrics/module_length.rb +35 -3
  316. data/lib/rubocop/cop/metrics/parameter_lists.rb +80 -8
  317. data/lib/rubocop/cop/metrics/perceived_complexity.rb +8 -10
  318. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +145 -0
  319. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +160 -0
  320. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  321. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +143 -0
  322. data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +42 -0
  323. data/lib/rubocop/cop/migration/department_name.rb +79 -0
  324. data/lib/rubocop/cop/mixin/alignment.rb +81 -0
  325. data/lib/rubocop/cop/mixin/allowed_identifiers.rb +18 -0
  326. data/lib/rubocop/cop/mixin/allowed_methods.rb +21 -0
  327. data/lib/rubocop/cop/mixin/annotation_comment.rb +6 -0
  328. data/lib/rubocop/cop/mixin/array_min_size.rb +57 -0
  329. data/lib/rubocop/cop/mixin/array_syntax.rb +3 -1
  330. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  331. data/lib/rubocop/cop/mixin/check_assignment.rb +13 -9
  332. data/lib/rubocop/cop/mixin/check_line_breakable.rb +214 -0
  333. data/lib/rubocop/cop/mixin/code_length.rb +33 -6
  334. data/lib/rubocop/cop/mixin/comments_help.rb +42 -0
  335. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +20 -18
  336. data/lib/rubocop/cop/mixin/configurable_formatting.rb +5 -13
  337. data/lib/rubocop/cop/mixin/configurable_max.rb +7 -2
  338. data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
  339. data/lib/rubocop/cop/mixin/configurable_numbering.rb +4 -3
  340. data/lib/rubocop/cop/mixin/def_node.rb +12 -8
  341. data/lib/rubocop/cop/mixin/documentation_comment.rb +13 -10
  342. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +45 -34
  343. data/lib/rubocop/cop/mixin/empty_parameter.rb +25 -0
  344. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +29 -33
  345. data/lib/rubocop/cop/mixin/enforce_superclass.rb +38 -0
  346. data/lib/rubocop/cop/mixin/first_element_line_break.rb +17 -12
  347. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +35 -10
  348. data/lib/rubocop/cop/mixin/gem_declaration.rb +13 -0
  349. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +55 -16
  350. data/lib/rubocop/cop/mixin/hash_transform_method.rb +183 -0
  351. data/lib/rubocop/cop/mixin/heredoc.rb +32 -0
  352. data/lib/rubocop/cop/mixin/ignored_methods.rb +52 -0
  353. data/lib/rubocop/cop/mixin/ignored_pattern.rb +3 -1
  354. data/lib/rubocop/cop/mixin/integer_node.rb +3 -1
  355. data/lib/rubocop/cop/mixin/interpolation.rb +25 -0
  356. data/lib/rubocop/cop/mixin/line_length_help.rb +90 -0
  357. data/lib/rubocop/cop/mixin/match_range.rb +6 -5
  358. data/lib/rubocop/cop/mixin/method_complexity.rb +58 -11
  359. data/lib/rubocop/cop/mixin/method_preference.rb +1 -1
  360. data/lib/rubocop/cop/mixin/min_body_length.rb +3 -1
  361. data/lib/rubocop/cop/mixin/{array_hash_indentation.rb → multiline_element_indentation.rb} +11 -6
  362. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +33 -0
  363. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +108 -61
  364. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +31 -42
  365. data/lib/rubocop/cop/mixin/negative_conditional.rb +9 -18
  366. data/lib/rubocop/cop/mixin/nil_methods.rb +23 -0
  367. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +58 -0
  368. data/lib/rubocop/cop/mixin/parentheses.rb +3 -9
  369. data/lib/rubocop/cop/mixin/percent_array.rb +57 -0
  370. data/lib/rubocop/cop/mixin/percent_literal.rb +3 -71
  371. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +95 -9
  372. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +50 -0
  373. data/lib/rubocop/cop/mixin/range_help.rb +128 -0
  374. data/lib/rubocop/cop/mixin/rational_literal.rb +19 -0
  375. data/lib/rubocop/cop/mixin/rescue_node.rb +15 -8
  376. data/lib/rubocop/cop/mixin/safe_assignment.rb +9 -2
  377. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +15 -16
  378. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +19 -18
  379. data/lib/rubocop/cop/mixin/statement_modifier.rb +50 -25
  380. data/lib/rubocop/cop/mixin/string_help.rb +6 -1
  381. data/lib/rubocop/cop/mixin/string_literals_help.rb +5 -17
  382. data/lib/rubocop/cop/mixin/surrounding_space.rb +113 -23
  383. data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
  384. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  385. data/lib/rubocop/cop/mixin/trailing_body.rb +25 -0
  386. data/lib/rubocop/cop/mixin/trailing_comma.rb +100 -52
  387. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +104 -0
  388. data/lib/rubocop/cop/mixin/unused_argument.rb +6 -19
  389. data/lib/rubocop/cop/mixin/visibility_help.rb +37 -0
  390. data/lib/rubocop/cop/naming/accessor_method_name.rb +71 -0
  391. data/lib/rubocop/cop/naming/ascii_identifiers.rb +93 -0
  392. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +53 -0
  393. data/lib/rubocop/cop/naming/block_parameter_name.rb +49 -0
  394. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +43 -0
  395. data/lib/rubocop/cop/naming/constant_name.rb +84 -0
  396. data/lib/rubocop/cop/{style → naming}/file_name.rb +79 -48
  397. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +68 -0
  398. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +55 -0
  399. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +279 -0
  400. data/lib/rubocop/cop/naming/method_name.rb +81 -0
  401. data/lib/rubocop/cop/naming/method_parameter_name.rb +58 -0
  402. data/lib/rubocop/cop/naming/predicate_name.rb +105 -0
  403. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +156 -0
  404. data/lib/rubocop/cop/naming/variable_name.rb +54 -0
  405. data/lib/rubocop/cop/naming/variable_number.rb +146 -0
  406. data/lib/rubocop/cop/offense.rb +74 -23
  407. data/lib/rubocop/cop/registry.rb +140 -23
  408. data/lib/rubocop/cop/security/eval.rb +14 -5
  409. data/lib/rubocop/cop/security/json_load.rb +14 -12
  410. data/lib/rubocop/cop/security/marshal_load.rb +9 -7
  411. data/lib/rubocop/cop/security/open.rb +75 -0
  412. data/lib/rubocop/cop/security/yaml_load.rb +12 -10
  413. data/lib/rubocop/cop/severity.rb +5 -14
  414. data/lib/rubocop/cop/style/access_modifier_declarations.rb +136 -0
  415. data/lib/rubocop/cop/style/accessor_grouping.rb +150 -0
  416. data/lib/rubocop/cop/style/alias.rb +86 -57
  417. data/lib/rubocop/cop/style/and_or.rb +81 -53
  418. data/lib/rubocop/cop/style/arguments_forwarding.rb +143 -0
  419. data/lib/rubocop/cop/style/array_coercion.rb +69 -0
  420. data/lib/rubocop/cop/style/array_join.rb +19 -10
  421. data/lib/rubocop/cop/style/ascii_comments.rb +31 -9
  422. data/lib/rubocop/cop/style/attr.rb +33 -13
  423. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +19 -13
  424. data/lib/rubocop/cop/style/bare_percent_literals.rb +31 -12
  425. data/lib/rubocop/cop/style/begin_block.rb +9 -3
  426. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +125 -0
  427. data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +60 -0
  428. data/lib/rubocop/cop/style/block_comments.rb +40 -20
  429. data/lib/rubocop/cop/style/block_delimiters.rb +213 -59
  430. data/lib/rubocop/cop/style/case_equality.rb +67 -4
  431. data/lib/rubocop/cop/style/case_like_if.rb +258 -0
  432. data/lib/rubocop/cop/style/character_literal.rb +22 -15
  433. data/lib/rubocop/cop/style/class_and_module_children.rb +118 -17
  434. data/lib/rubocop/cop/style/class_check.rb +31 -17
  435. data/lib/rubocop/cop/style/class_equality_comparison.rb +67 -0
  436. data/lib/rubocop/cop/style/class_methods.rb +18 -31
  437. data/lib/rubocop/cop/style/class_methods_definitions.rb +157 -0
  438. data/lib/rubocop/cop/style/class_vars.rb +48 -7
  439. data/lib/rubocop/cop/style/collection_compact.rb +91 -0
  440. data/lib/rubocop/cop/style/collection_methods.rb +52 -17
  441. data/lib/rubocop/cop/style/colon_method_call.rb +26 -13
  442. data/lib/rubocop/cop/style/colon_method_definition.rb +37 -0
  443. data/lib/rubocop/cop/style/combinable_loops.rb +92 -0
  444. data/lib/rubocop/cop/style/command_literal.rb +104 -42
  445. data/lib/rubocop/cop/style/comment_annotation.rb +62 -24
  446. data/lib/rubocop/cop/style/commented_keyword.rb +86 -0
  447. data/lib/rubocop/cop/style/conditional_assignment.rb +143 -182
  448. data/lib/rubocop/cop/style/constant_visibility.rb +106 -0
  449. data/lib/rubocop/cop/style/copyright.rb +42 -35
  450. data/lib/rubocop/cop/style/date_time.rb +88 -0
  451. data/lib/rubocop/cop/style/def_with_parentheses.rb +36 -13
  452. data/lib/rubocop/cop/style/dir.rb +47 -0
  453. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +87 -0
  454. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +169 -0
  455. data/lib/rubocop/cop/style/documentation.rb +114 -22
  456. data/lib/rubocop/cop/style/documentation_method.rb +56 -10
  457. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +52 -0
  458. data/lib/rubocop/cop/style/double_negation.rb +52 -8
  459. data/lib/rubocop/cop/style/each_for_simple_loop.rb +16 -18
  460. data/lib/rubocop/cop/style/each_with_object.rb +34 -17
  461. data/lib/rubocop/cop/style/empty_block_parameter.rb +47 -0
  462. data/lib/rubocop/cop/style/empty_case_condition.rb +32 -13
  463. data/lib/rubocop/cop/style/empty_else.rb +56 -27
  464. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +44 -0
  465. data/lib/rubocop/cop/style/empty_literal.rb +63 -33
  466. data/lib/rubocop/cop/style/empty_method.rb +37 -35
  467. data/lib/rubocop/cop/style/encoding.rb +20 -60
  468. data/lib/rubocop/cop/style/end_block.rb +15 -4
  469. data/lib/rubocop/cop/style/endless_method.rb +101 -0
  470. data/lib/rubocop/cop/style/eval_with_location.rb +237 -0
  471. data/lib/rubocop/cop/style/even_odd.rb +16 -16
  472. data/lib/rubocop/cop/style/expand_path_arguments.rb +196 -0
  473. data/lib/rubocop/cop/style/explicit_block_argument.rb +114 -0
  474. data/lib/rubocop/cop/style/exponential_notation.rb +116 -0
  475. data/lib/rubocop/cop/style/float_division.rb +143 -0
  476. data/lib/rubocop/cop/style/for.rb +49 -17
  477. data/lib/rubocop/cop/style/format_string.rb +97 -10
  478. data/lib/rubocop/cop/style/format_string_token.rb +177 -0
  479. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +155 -47
  480. data/lib/rubocop/cop/style/global_std_stream.rb +66 -0
  481. data/lib/rubocop/cop/style/global_vars.rb +16 -6
  482. data/lib/rubocop/cop/style/guard_clause.rb +69 -18
  483. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +88 -0
  484. data/lib/rubocop/cop/style/hash_conversion.rb +133 -0
  485. data/lib/rubocop/cop/style/hash_each_methods.rb +103 -0
  486. data/lib/rubocop/cop/style/hash_except.rb +96 -0
  487. data/lib/rubocop/cop/style/hash_like_case.rb +77 -0
  488. data/lib/rubocop/cop/style/hash_syntax.rb +99 -94
  489. data/lib/rubocop/cop/style/hash_transform_keys.rb +95 -0
  490. data/lib/rubocop/cop/style/hash_transform_values.rb +92 -0
  491. data/lib/rubocop/cop/style/identical_conditional_branches.rb +53 -29
  492. data/lib/rubocop/cop/style/if_inside_else.rb +101 -11
  493. data/lib/rubocop/cop/style/if_unless_modifier.rb +162 -44
  494. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +13 -4
  495. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +122 -0
  496. data/lib/rubocop/cop/style/if_with_semicolon.rb +62 -4
  497. data/lib/rubocop/cop/style/implicit_runtime_error.rb +10 -7
  498. data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
  499. data/lib/rubocop/cop/style/infinite_loop.rb +65 -27
  500. data/lib/rubocop/cop/style/inline_comment.rb +7 -5
  501. data/lib/rubocop/cop/style/inverse_methods.rb +99 -44
  502. data/lib/rubocop/cop/style/ip_addresses.rb +75 -0
  503. data/lib/rubocop/cop/style/keyword_parameters_order.rb +75 -0
  504. data/lib/rubocop/cop/style/lambda.rb +26 -110
  505. data/lib/rubocop/cop/style/lambda_call.rb +29 -19
  506. data/lib/rubocop/cop/style/line_end_concatenation.rb +40 -34
  507. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +185 -52
  508. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +189 -0
  509. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +44 -0
  510. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +27 -18
  511. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +19 -10
  512. data/lib/rubocop/cop/style/method_def_parentheses.rb +122 -45
  513. data/lib/rubocop/cop/style/min_max.rb +64 -0
  514. data/lib/rubocop/cop/style/missing_else.rb +88 -20
  515. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +52 -0
  516. data/lib/rubocop/cop/style/mixin_grouping.rb +66 -28
  517. data/lib/rubocop/cop/style/mixin_usage.rb +72 -0
  518. data/lib/rubocop/cop/style/module_function.rb +111 -26
  519. data/lib/rubocop/cop/style/multiline_block_chain.rb +21 -15
  520. data/lib/rubocop/cop/style/multiline_if_modifier.rb +8 -11
  521. data/lib/rubocop/cop/style/multiline_if_then.rb +14 -17
  522. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
  523. data/lib/rubocop/cop/style/multiline_memoization.rb +44 -25
  524. data/lib/rubocop/cop/style/multiline_method_signature.rb +91 -0
  525. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +45 -5
  526. data/lib/rubocop/cop/style/multiline_when_then.rb +75 -0
  527. data/lib/rubocop/cop/style/multiple_comparison.rb +157 -0
  528. data/lib/rubocop/cop/style/mutable_constant.rb +132 -18
  529. data/lib/rubocop/cop/style/negated_if.rb +33 -38
  530. data/lib/rubocop/cop/style/negated_if_else_condition.rb +128 -0
  531. data/lib/rubocop/cop/style/negated_unless.rb +88 -0
  532. data/lib/rubocop/cop/style/negated_while.rb +25 -17
  533. data/lib/rubocop/cop/style/nested_modifier.rb +36 -23
  534. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +38 -29
  535. data/lib/rubocop/cop/style/nested_ternary_operator.rb +41 -4
  536. data/lib/rubocop/cop/style/next.rb +77 -67
  537. data/lib/rubocop/cop/style/nil_comparison.rb +62 -14
  538. data/lib/rubocop/cop/style/nil_lambda.rb +70 -0
  539. data/lib/rubocop/cop/style/non_nil_check.rb +100 -63
  540. data/lib/rubocop/cop/style/not.rb +38 -31
  541. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +47 -25
  542. data/lib/rubocop/cop/style/numeric_literals.rb +40 -35
  543. data/lib/rubocop/cop/style/numeric_predicate.rb +33 -43
  544. data/lib/rubocop/cop/style/one_line_conditional.rb +100 -28
  545. data/lib/rubocop/cop/style/option_hash.rb +21 -25
  546. data/lib/rubocop/cop/style/optional_arguments.rb +4 -11
  547. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +53 -0
  548. data/lib/rubocop/cop/style/or_assignment.rb +97 -0
  549. data/lib/rubocop/cop/style/parallel_assignment.rb +42 -48
  550. data/lib/rubocop/cop/style/parentheses_around_condition.rb +76 -14
  551. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +42 -23
  552. data/lib/rubocop/cop/style/percent_q_literals.rb +31 -13
  553. data/lib/rubocop/cop/style/perl_backrefs.rb +91 -16
  554. data/lib/rubocop/cop/style/preferred_hash_methods.rb +15 -24
  555. data/lib/rubocop/cop/style/proc.rb +18 -10
  556. data/lib/rubocop/cop/style/quoted_symbols.rb +105 -0
  557. data/lib/rubocop/cop/style/raise_args.rb +53 -46
  558. data/lib/rubocop/cop/style/random_with_offset.rb +153 -0
  559. data/lib/rubocop/cop/style/redundant_argument.rb +85 -0
  560. data/lib/rubocop/cop/style/redundant_assignment.rb +106 -0
  561. data/lib/rubocop/cop/style/redundant_begin.rb +119 -9
  562. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +17 -11
  563. data/lib/rubocop/cop/style/redundant_condition.rb +137 -0
  564. data/lib/rubocop/cop/style/redundant_conditional.rb +96 -0
  565. data/lib/rubocop/cop/style/redundant_exception.rb +28 -18
  566. data/lib/rubocop/cop/style/redundant_fetch_block.rb +115 -0
  567. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +52 -0
  568. data/lib/rubocop/cop/style/redundant_freeze.rb +37 -13
  569. data/lib/rubocop/cop/style/redundant_interpolation.rb +103 -0
  570. data/lib/rubocop/cop/style/redundant_parentheses.rb +99 -54
  571. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +39 -26
  572. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +104 -0
  573. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +118 -0
  574. data/lib/rubocop/cop/style/redundant_return.rb +109 -59
  575. data/lib/rubocop/cop/style/redundant_self.rb +75 -50
  576. data/lib/rubocop/cop/style/redundant_self_assignment.rb +118 -0
  577. data/lib/rubocop/cop/style/redundant_sort.rb +160 -0
  578. data/lib/rubocop/cop/{performance → style}/redundant_sort_by.rb +15 -13
  579. data/lib/rubocop/cop/style/regexp_literal.rb +142 -43
  580. data/lib/rubocop/cop/style/rescue_modifier.rb +77 -14
  581. data/lib/rubocop/cop/style/rescue_standard_error.rb +126 -0
  582. data/lib/rubocop/cop/style/return_nil.rb +94 -0
  583. data/lib/rubocop/cop/style/safe_navigation.rb +193 -58
  584. data/lib/rubocop/cop/{performance → style}/sample.rb +29 -26
  585. data/lib/rubocop/cop/style/self_assignment.rb +24 -16
  586. data/lib/rubocop/cop/style/semicolon.rb +48 -17
  587. data/lib/rubocop/cop/style/send.rb +15 -7
  588. data/lib/rubocop/cop/style/signal_exception.rb +134 -27
  589. data/lib/rubocop/cop/style/single_argument_dig.rb +55 -0
  590. data/lib/rubocop/cop/style/single_line_block_params.rb +72 -23
  591. data/lib/rubocop/cop/style/single_line_methods.rb +95 -37
  592. data/lib/rubocop/cop/style/slicing_with_range.rb +38 -0
  593. data/lib/rubocop/cop/style/sole_nested_conditional.rb +176 -0
  594. data/lib/rubocop/cop/style/special_global_vars.rb +80 -58
  595. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +35 -69
  596. data/lib/rubocop/cop/style/static_class.rb +97 -0
  597. data/lib/rubocop/cop/style/stderr_puts.rb +57 -0
  598. data/lib/rubocop/cop/style/string_chars.rb +39 -0
  599. data/lib/rubocop/cop/style/string_concatenation.rb +142 -0
  600. data/lib/rubocop/cop/style/string_hash_keys.rb +51 -0
  601. data/lib/rubocop/cop/style/string_literals.rb +44 -13
  602. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +24 -3
  603. data/lib/rubocop/cop/style/string_methods.rb +17 -15
  604. data/lib/rubocop/cop/{performance/lstrip_rstrip.rb → style/strip.rb} +18 -17
  605. data/lib/rubocop/cop/style/struct_inheritance.rb +45 -9
  606. data/lib/rubocop/cop/style/swap_values.rb +108 -0
  607. data/lib/rubocop/cop/style/symbol_array.rb +56 -46
  608. data/lib/rubocop/cop/style/symbol_literal.rb +6 -10
  609. data/lib/rubocop/cop/style/symbol_proc.rb +63 -78
  610. data/lib/rubocop/cop/style/ternary_parentheses.rb +95 -77
  611. data/lib/rubocop/cop/style/top_level_method_definition.rb +83 -0
  612. data/lib/rubocop/cop/style/trailing_body_on_class.rb +40 -0
  613. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +55 -0
  614. data/lib/rubocop/cop/style/trailing_body_on_module.rb +40 -0
  615. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +69 -27
  616. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +96 -0
  617. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +86 -0
  618. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +97 -0
  619. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +65 -0
  620. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +79 -40
  621. data/lib/rubocop/cop/style/trivial_accessors.rb +158 -82
  622. data/lib/rubocop/cop/style/unless_else.rb +25 -13
  623. data/lib/rubocop/cop/style/unless_logical_operators.rb +105 -0
  624. data/lib/rubocop/cop/style/unpack_first.rb +59 -0
  625. data/lib/rubocop/cop/style/variable_interpolation.rb +26 -25
  626. data/lib/rubocop/cop/style/when_then.rb +20 -7
  627. data/lib/rubocop/cop/style/while_until_do.rb +31 -18
  628. data/lib/rubocop/cop/style/while_until_modifier.rb +36 -24
  629. data/lib/rubocop/cop/style/word_array.rb +40 -91
  630. data/lib/rubocop/cop/style/yoda_condition.rb +155 -0
  631. data/lib/rubocop/cop/style/zero_length_predicate.rb +60 -31
  632. data/lib/rubocop/cop/team.rb +171 -105
  633. data/lib/rubocop/cop/util.rb +44 -194
  634. data/lib/rubocop/cop/utils/format_string.rb +133 -0
  635. data/lib/rubocop/cop/variable_force.rb +47 -51
  636. data/lib/rubocop/cop/variable_force/assignment.rb +10 -4
  637. data/lib/rubocop/cop/variable_force/branch.rb +22 -9
  638. data/lib/rubocop/cop/variable_force/branchable.rb +2 -0
  639. data/lib/rubocop/cop/variable_force/reference.rb +1 -3
  640. data/lib/rubocop/cop/variable_force/scope.rb +13 -14
  641. data/lib/rubocop/cop/variable_force/variable.rb +25 -14
  642. data/lib/rubocop/cop/variable_force/variable_table.rb +4 -3
  643. data/lib/rubocop/cops_documentation_generator.rb +270 -0
  644. data/lib/rubocop/core_ext/string.rb +23 -0
  645. data/lib/rubocop/directive_comment.rb +96 -0
  646. data/lib/rubocop/error.rb +24 -0
  647. data/lib/rubocop/ext/processed_source.rb +18 -0
  648. data/lib/rubocop/ext/regexp_node.rb +87 -0
  649. data/lib/rubocop/ext/regexp_parser.rb +92 -0
  650. data/lib/rubocop/file_finder.rb +41 -0
  651. data/lib/rubocop/formatter/auto_gen_config_formatter.rb +17 -0
  652. data/lib/rubocop/formatter/base_formatter.rb +3 -7
  653. data/lib/rubocop/formatter/clang_style_formatter.rb +13 -8
  654. data/lib/rubocop/formatter/disabled_config_formatter.rb +110 -58
  655. data/lib/rubocop/formatter/emacs_style_formatter.rb +24 -9
  656. data/lib/rubocop/formatter/file_list_formatter.rb +2 -1
  657. data/lib/rubocop/formatter/formatter_set.rb +20 -16
  658. data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -2
  659. data/lib/rubocop/formatter/git_hub_actions_formatter.rb +44 -0
  660. data/lib/rubocop/formatter/html_formatter.rb +18 -15
  661. data/lib/rubocop/formatter/json_formatter.rb +17 -14
  662. data/lib/rubocop/formatter/junit_formatter.rb +93 -0
  663. data/lib/rubocop/formatter/offense_count_formatter.rb +21 -2
  664. data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
  665. data/lib/rubocop/formatter/progress_formatter.rb +4 -5
  666. data/lib/rubocop/formatter/quiet_formatter.rb +13 -0
  667. data/lib/rubocop/formatter/simple_text_formatter.rb +61 -26
  668. data/lib/rubocop/formatter/tap_formatter.rb +86 -0
  669. data/lib/rubocop/formatter/worst_offenders_formatter.rb +4 -2
  670. data/lib/rubocop/lockfile.rb +40 -0
  671. data/lib/rubocop/magic_comment.rb +45 -12
  672. data/lib/rubocop/name_similarity.rb +18 -10
  673. data/lib/rubocop/options.rb +311 -140
  674. data/lib/rubocop/path_util.rb +57 -5
  675. data/lib/rubocop/platform.rb +1 -1
  676. data/lib/rubocop/rake_task.rb +27 -32
  677. data/lib/rubocop/remote_config.rb +32 -8
  678. data/lib/rubocop/result_cache.rb +89 -39
  679. data/lib/rubocop/rspec/cop_helper.rb +18 -46
  680. data/lib/rubocop/rspec/expect_offense.rb +329 -0
  681. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +1 -5
  682. data/lib/rubocop/rspec/shared_contexts.rb +92 -53
  683. data/lib/rubocop/rspec/support.rb +9 -4
  684. data/lib/rubocop/runner.rb +174 -86
  685. data/lib/rubocop/string_interpreter.rb +11 -8
  686. data/lib/rubocop/target_finder.rb +102 -93
  687. data/lib/rubocop/target_ruby.rb +264 -0
  688. data/lib/rubocop/util.rb +16 -0
  689. data/lib/rubocop/version.rb +71 -5
  690. data/lib/rubocop/yaml_duplication_checker.rb +40 -0
  691. metadata +495 -233
  692. data/bin/rubocop +0 -17
  693. data/config/disabled.yml +0 -119
  694. data/config/enabled.yml +0 -1713
  695. data/lib/rubocop/ast/builder.rb +0 -64
  696. data/lib/rubocop/ast/node.rb +0 -610
  697. data/lib/rubocop/ast/node/and_node.rb +0 -37
  698. data/lib/rubocop/ast/node/array_node.rb +0 -48
  699. data/lib/rubocop/ast/node/case_node.rb +0 -64
  700. data/lib/rubocop/ast/node/ensure_node.rb +0 -25
  701. data/lib/rubocop/ast/node/for_node.rb +0 -53
  702. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  703. data/lib/rubocop/ast/node/if_node.rb +0 -138
  704. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  705. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -23
  706. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  707. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  708. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  709. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  710. data/lib/rubocop/ast/node/or_node.rb +0 -37
  711. data/lib/rubocop/ast/node/pair_node.rb +0 -64
  712. data/lib/rubocop/ast/node/resbody_node.rb +0 -25
  713. data/lib/rubocop/ast/node/send_node.rb +0 -195
  714. data/lib/rubocop/ast/node/until_node.rb +0 -43
  715. data/lib/rubocop/ast/node/when_node.rb +0 -61
  716. data/lib/rubocop/ast/node/while_node.rb +0 -43
  717. data/lib/rubocop/ast/sexp.rb +0 -16
  718. data/lib/rubocop/ast/traversal.rb +0 -171
  719. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  720. data/lib/rubocop/cop/lint/handle_exceptions.rb +0 -56
  721. data/lib/rubocop/cop/lint/invalid_character_literal.rb +0 -41
  722. data/lib/rubocop/cop/lint/multiple_compare.rb +0 -48
  723. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +0 -58
  724. data/lib/rubocop/cop/lint/unneeded_disable.rb +0 -231
  725. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +0 -141
  726. data/lib/rubocop/cop/lint/useless_comparison.rb +0 -28
  727. data/lib/rubocop/cop/metrics/line_length.rb +0 -168
  728. data/lib/rubocop/cop/mixin/access_modifier_node.rb +0 -41
  729. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
  730. data/lib/rubocop/cop/mixin/classish_length.rb +0 -36
  731. data/lib/rubocop/cop/mixin/on_method_def.rb +0 -44
  732. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +0 -34
  733. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -22
  734. data/lib/rubocop/cop/mixin/space_inside.rb +0 -76
  735. data/lib/rubocop/cop/mixin/target_rails_version.rb +0 -16
  736. data/lib/rubocop/cop/mixin/too_many_lines.rb +0 -39
  737. data/lib/rubocop/cop/performance/case_when_splat.rb +0 -176
  738. data/lib/rubocop/cop/performance/casecmp.rb +0 -107
  739. data/lib/rubocop/cop/performance/compare_with_block.rb +0 -61
  740. data/lib/rubocop/cop/performance/count.rb +0 -98
  741. data/lib/rubocop/cop/performance/detect.rb +0 -107
  742. data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -102
  743. data/lib/rubocop/cop/performance/end_with.rb +0 -55
  744. data/lib/rubocop/cop/performance/fixed_size.rb +0 -56
  745. data/lib/rubocop/cop/performance/flat_map.rb +0 -73
  746. data/lib/rubocop/cop/performance/hash_each_methods.rb +0 -84
  747. data/lib/rubocop/cop/performance/range_include.rb +0 -41
  748. data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -93
  749. data/lib/rubocop/cop/performance/redundant_match.rb +0 -55
  750. data/lib/rubocop/cop/performance/redundant_merge.rb +0 -149
  751. data/lib/rubocop/cop/performance/regexp_match.rb +0 -215
  752. data/lib/rubocop/cop/performance/reverse_each.rb +0 -40
  753. data/lib/rubocop/cop/performance/size.rb +0 -71
  754. data/lib/rubocop/cop/performance/start_with.rb +0 -58
  755. data/lib/rubocop/cop/performance/string_replacement.rb +0 -170
  756. data/lib/rubocop/cop/performance/times_map.rb +0 -61
  757. data/lib/rubocop/cop/rails/action_filter.rb +0 -96
  758. data/lib/rubocop/cop/rails/active_support_aliases.rb +0 -68
  759. data/lib/rubocop/cop/rails/blank.rb +0 -132
  760. data/lib/rubocop/cop/rails/date.rb +0 -127
  761. data/lib/rubocop/cop/rails/delegate.rb +0 -106
  762. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +0 -51
  763. data/lib/rubocop/cop/rails/dynamic_find_by.rb +0 -81
  764. data/lib/rubocop/cop/rails/enum_uniqueness.rb +0 -43
  765. data/lib/rubocop/cop/rails/exit.rb +0 -61
  766. data/lib/rubocop/cop/rails/file_path.rb +0 -75
  767. data/lib/rubocop/cop/rails/find_by.rb +0 -51
  768. data/lib/rubocop/cop/rails/find_each.rb +0 -47
  769. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +0 -18
  770. data/lib/rubocop/cop/rails/http_positional_arguments.rb +0 -106
  771. data/lib/rubocop/cop/rails/not_null_column.rb +0 -67
  772. data/lib/rubocop/cop/rails/output.rb +0 -23
  773. data/lib/rubocop/cop/rails/output_safety.rb +0 -54
  774. data/lib/rubocop/cop/rails/pluralization_grammar.rb +0 -106
  775. data/lib/rubocop/cop/rails/present.rb +0 -137
  776. data/lib/rubocop/cop/rails/read_write_attribute.rb +0 -65
  777. data/lib/rubocop/cop/rails/relative_date_constant.rb +0 -57
  778. data/lib/rubocop/cop/rails/request_referer.rb +0 -56
  779. data/lib/rubocop/cop/rails/reversible_migration.rb +0 -216
  780. data/lib/rubocop/cop/rails/safe_navigation.rb +0 -91
  781. data/lib/rubocop/cop/rails/save_bang.rb +0 -155
  782. data/lib/rubocop/cop/rails/scope_args.rb +0 -29
  783. data/lib/rubocop/cop/rails/skips_model_validations.rb +0 -63
  784. data/lib/rubocop/cop/rails/time_zone.rb +0 -197
  785. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +0 -93
  786. data/lib/rubocop/cop/rails/validation.rb +0 -64
  787. data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -80
  788. data/lib/rubocop/cop/style/accessor_method_name.rb +0 -45
  789. data/lib/rubocop/cop/style/align_array.rb +0 -20
  790. data/lib/rubocop/cop/style/align_hash.rb +0 -235
  791. data/lib/rubocop/cop/style/align_parameters.rb +0 -69
  792. data/lib/rubocop/cop/style/ascii_identifiers.rb +0 -36
  793. data/lib/rubocop/cop/style/block_end_newline.rb +0 -56
  794. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -138
  795. data/lib/rubocop/cop/style/case_indentation.rb +0 -100
  796. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +0 -29
  797. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +0 -88
  798. data/lib/rubocop/cop/style/comment_indentation.rb +0 -71
  799. data/lib/rubocop/cop/style/constant_name.rb +0 -29
  800. data/lib/rubocop/cop/style/else_alignment.rb +0 -105
  801. data/lib/rubocop/cop/style/empty_line_between_defs.rb +0 -143
  802. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +0 -95
  803. data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +0 -41
  804. data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +0 -39
  805. data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +0 -44
  806. data/lib/rubocop/cop/style/end_of_line.rb +0 -52
  807. data/lib/rubocop/cop/style/extra_spacing.rb +0 -237
  808. data/lib/rubocop/cop/style/first_parameter_indentation.rb +0 -109
  809. data/lib/rubocop/cop/style/flip_flop.rb +0 -20
  810. data/lib/rubocop/cop/style/indent_array.rb +0 -114
  811. data/lib/rubocop/cop/style/indent_hash.rb +0 -134
  812. data/lib/rubocop/cop/style/indent_heredoc.rb +0 -173
  813. data/lib/rubocop/cop/style/indentation_consistency.rb +0 -51
  814. data/lib/rubocop/cop/style/initial_indentation.rb +0 -42
  815. data/lib/rubocop/cop/style/leading_comment_space.rb +0 -43
  816. data/lib/rubocop/cop/style/method_missing.rb +0 -81
  817. data/lib/rubocop/cop/style/method_name.rb +0 -28
  818. data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +0 -81
  819. data/lib/rubocop/cop/style/multiline_assignment_layout.rb +0 -88
  820. data/lib/rubocop/cop/style/multiline_block_layout.rb +0 -134
  821. data/lib/rubocop/cop/style/op_method.rb +0 -41
  822. data/lib/rubocop/cop/style/predicate_name.rb +0 -67
  823. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +0 -86
  824. data/lib/rubocop/cop/style/space_after_comma.rb +0 -21
  825. data/lib/rubocop/cop/style/space_after_method_name.rb +0 -37
  826. data/lib/rubocop/cop/style/space_around_block_parameters.rb +0 -109
  827. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +0 -68
  828. data/lib/rubocop/cop/style/space_around_operators.rb +0 -142
  829. data/lib/rubocop/cop/style/space_before_block_braces.rb +0 -54
  830. data/lib/rubocop/cop/style/space_before_comma.rb +0 -16
  831. data/lib/rubocop/cop/style/space_before_comment.rb +0 -27
  832. data/lib/rubocop/cop/style/space_before_semicolon.rb +0 -16
  833. data/lib/rubocop/cop/style/space_in_lambda_literal.rb +0 -87
  834. data/lib/rubocop/cop/style/space_inside_block_braces.rb +0 -158
  835. data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -20
  836. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +0 -150
  837. data/lib/rubocop/cop/style/space_inside_parens.rb +0 -16
  838. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +0 -65
  839. data/lib/rubocop/cop/style/tab.rb +0 -57
  840. data/lib/rubocop/cop/style/trailing_blank_lines.rb +0 -78
  841. data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +0 -56
  842. data/lib/rubocop/cop/style/trailing_whitespace.rb +0 -28
  843. data/lib/rubocop/cop/style/unneeded_interpolation.rb +0 -98
  844. data/lib/rubocop/cop/style/variable_name.rb +0 -39
  845. data/lib/rubocop/cop/style/variable_number.rb +0 -78
  846. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
  847. data/lib/rubocop/node_pattern.rb +0 -543
  848. data/lib/rubocop/processed_source.rb +0 -151
  849. data/lib/rubocop/rspec/shared_examples.rb +0 -100
  850. data/lib/rubocop/string_util.rb +0 -156
  851. data/lib/rubocop/token.rb +0 -25
@@ -6,33 +6,23 @@ require 'tempfile'
6
6
  module CopHelper
7
7
  extend RSpec::SharedContext
8
8
 
9
- let(:ruby_version) { 2.2 }
10
- let(:enabled_rails) { false }
9
+ let(:ruby_version) { 2.5 }
11
10
  let(:rails_version) { false }
12
11
 
13
- def inspect_source_file(cop, source)
14
- Tempfile.open('tmp') { |f| inspect_source(cop, source, f) }
15
- end
16
-
17
- def inspect_gemfile(cop, source)
18
- inspect_source(cop, source, 'Gemfile')
19
- end
20
-
21
- def inspect_source(cop, source, file = nil)
22
- if source.is_a?(Array) && source.size == 1
23
- raise "Don't use an array for a single line of code: #{source}"
24
- end
12
+ def inspect_source(source, file = nil)
25
13
  RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
26
14
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
27
15
  processed_source = parse_source(source, file)
28
- raise 'Error parsing example code' unless processed_source.valid_syntax?
16
+ unless processed_source.valid_syntax?
17
+ raise 'Error parsing example code: ' \
18
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
19
+ end
20
+
29
21
  _investigate(cop, processed_source)
30
22
  end
31
23
 
32
24
  def parse_source(source, file = nil)
33
- source = source.join($RS) if source.is_a?(Array)
34
-
35
- if file && file.respond_to?(:write)
25
+ if file.respond_to?(:write)
36
26
  file.write(source)
37
27
  file.rewind
38
28
  file = file.path
@@ -41,39 +31,25 @@ module CopHelper
41
31
  RuboCop::ProcessedSource.new(source, ruby_version, file)
42
32
  end
43
33
 
44
- def autocorrect_source_file(cop, source)
45
- Tempfile.open('tmp') { |f| autocorrect_source(cop, source, f) }
34
+ def autocorrect_source_file(source)
35
+ Tempfile.open('tmp') { |f| autocorrect_source(source, f) }
46
36
  end
47
37
 
48
- def autocorrect_source(cop, source, file = nil)
38
+ def autocorrect_source(source, file = nil)
39
+ RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
40
+ RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
49
41
  cop.instance_variable_get(:@options)[:auto_correct] = true
50
42
  processed_source = parse_source(source, file)
51
43
  _investigate(cop, processed_source)
52
44
 
53
- corrector =
54
- RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
55
- corrector.rewrite
56
- end
57
-
58
- def autocorrect_source_with_loop(cop, source, file = nil)
59
- loop do
60
- cop.instance_variable_set(:@corrections, [])
61
- new_source = autocorrect_source(cop, source, file)
62
- return new_source if new_source == source
63
- source = new_source
64
- end
45
+ @last_corrector.rewrite
65
46
  end
66
47
 
67
48
  def _investigate(cop, processed_source)
68
- forces = RuboCop::Cop::Force.all.each_with_object([]) do |klass, instances|
69
- next unless cop.join_force?(klass)
70
- instances << klass.new([cop])
71
- end
72
-
73
- commissioner =
74
- RuboCop::Cop::Commissioner.new([cop], forces, raise_error: true)
75
- commissioner.investigate(processed_source)
76
- commissioner
49
+ team = RuboCop::Cop::Team.new([cop], nil, raise_error: true)
50
+ report = team.investigate(processed_source)
51
+ @last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source)
52
+ report.offenses
77
53
  end
78
54
  end
79
55
 
@@ -92,7 +68,3 @@ module RuboCop
92
68
  end
93
69
  end
94
70
  end
95
-
96
- RSpec.configure do |config|
97
- config.include CopHelper
98
- end
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module RSpec
5
+ # Mixin for `expect_offense` and `expect_no_offenses`
6
+ #
7
+ # This mixin makes it easier to specify strict offense expectations
8
+ # in a declarative and visual fashion. Just type out the code that
9
+ # should generate a offense, annotate code by writing '^'s
10
+ # underneath each character that should be highlighted, and follow
11
+ # the carets with a string (separated by a space) that is the
12
+ # message of the offense. You can include multiple offenses in
13
+ # one code snippet.
14
+ #
15
+ # @example Usage
16
+ #
17
+ # expect_offense(<<~RUBY)
18
+ # a do
19
+ # b
20
+ # end.c
21
+ # ^^^^^ Avoid chaining a method call on a do...end block.
22
+ # RUBY
23
+ #
24
+ # @example Equivalent assertion without `expect_offense`
25
+ #
26
+ # inspect_source(<<~RUBY)
27
+ # a do
28
+ # b
29
+ # end.c
30
+ # RUBY
31
+ #
32
+ # expect(cop.offenses.size).to be(1)
33
+ #
34
+ # offense = cop.offenses.first
35
+ # expect(offense.line).to be(3)
36
+ # expect(offense.column_range).to be(0...5)
37
+ # expect(offense.message).to eql(
38
+ # 'Avoid chaining a method call on a do...end block.'
39
+ # )
40
+ #
41
+ # Auto-correction can be tested using `expect_correction` after
42
+ # `expect_offense`.
43
+ #
44
+ # @example `expect_offense` and `expect_correction`
45
+ #
46
+ # expect_offense(<<~RUBY)
47
+ # x % 2 == 0
48
+ # ^^^^^^^^^^ Replace with `Integer#even?`.
49
+ # RUBY
50
+ #
51
+ # expect_correction(<<~RUBY)
52
+ # x.even?
53
+ # RUBY
54
+ #
55
+ # If you do not want to specify an offense then use the
56
+ # companion method `expect_no_offenses`. This method is a much
57
+ # simpler assertion since it just inspects the source and checks
58
+ # that there were no offenses. The `expect_offense` method has
59
+ # to do more work by parsing out lines that contain carets.
60
+ #
61
+ # If the code produces an offense that could not be auto-corrected, you can
62
+ # use `expect_no_corrections` after `expect_offense`.
63
+ #
64
+ # @example `expect_offense` and `expect_no_corrections`
65
+ #
66
+ # expect_offense(<<~RUBY)
67
+ # a do
68
+ # b
69
+ # end.c
70
+ # ^^^^^ Avoid chaining a method call on a do...end block.
71
+ # RUBY
72
+ #
73
+ # expect_no_corrections
74
+ #
75
+ # If your code has variables of different lengths, you can use `%{foo}`,
76
+ # `^{foo}`, and `_{foo}` to format your template; you can also abbreviate
77
+ # offense messages with `[...]`:
78
+ #
79
+ # %w[raise fail].each do |keyword|
80
+ # expect_offense(<<~RUBY, keyword: keyword)
81
+ # %{keyword}(RuntimeError, msg)
82
+ # ^{keyword}^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument [...]
83
+ # RUBY
84
+ #
85
+ # %w[has_one has_many].each do |type|
86
+ # expect_offense(<<~RUBY, type: type)
87
+ # class Book
88
+ # %{type} :chapter, foreign_key: 'book_id'
89
+ # _{type} ^^^^^^^^^^^^^^^^^^^^^^ Specifying the default [...]
90
+ # end
91
+ # RUBY
92
+ # end
93
+ #
94
+ # If you need to specify an offense on a blank line, use the empty `^{}` marker:
95
+ #
96
+ # @example `^{}` empty line offense
97
+ #
98
+ # expect_offense(<<~RUBY)
99
+ #
100
+ # ^{} Missing frozen string literal comment.
101
+ # puts 1
102
+ # RUBY
103
+ module ExpectOffense
104
+ def format_offense(source, **replacements)
105
+ replacements.each do |keyword, value|
106
+ value = value.to_s
107
+ source = source.gsub("%{#{keyword}}", value)
108
+ .gsub("^{#{keyword}}", '^' * value.size)
109
+ .gsub("_{#{keyword}}", ' ' * value.size)
110
+ end
111
+ source
112
+ end
113
+
114
+ def expect_offense(source, file = nil, severity: nil, chomp: false, **replacements)
115
+ expected_annotations = parse_annotations(source, **replacements)
116
+ source = expected_annotations.plain_source
117
+ source = source.chomp if chomp
118
+
119
+ @processed_source = parse_processed_source(source, file)
120
+ @offenses = _investigate(cop, @processed_source)
121
+ actual_annotations = expected_annotations.with_offense_annotations(@offenses)
122
+
123
+ expect(actual_annotations).to eq(expected_annotations), ''
124
+ expect(@offenses.map(&:severity).uniq).to eq([severity]) if severity
125
+
126
+ @offenses
127
+ end
128
+
129
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
130
+ def expect_correction(correction, loop: true, source: nil)
131
+ if source
132
+ expected_annotations = parse_annotations(source, raise_error: false)
133
+ @processed_source = parse_processed_source(expected_annotations.plain_source)
134
+ _investigate(cop, @processed_source)
135
+ end
136
+
137
+ raise '`expect_correction` must follow `expect_offense`' unless @processed_source
138
+
139
+ iteration = 0
140
+ new_source = loop do
141
+ iteration += 1
142
+
143
+ corrected_source = @last_corrector.rewrite
144
+
145
+ break corrected_source unless loop
146
+ break corrected_source if @last_corrector.empty?
147
+ break corrected_source if corrected_source == @processed_source.buffer.source
148
+
149
+ if iteration > RuboCop::Runner::MAX_ITERATIONS
150
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
151
+ end
152
+
153
+ # Prepare for next loop
154
+ @processed_source = parse_source(corrected_source, @processed_source.path)
155
+ _investigate(cop, @processed_source)
156
+ end
157
+
158
+ expect(new_source).to eq(correction)
159
+ end
160
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
161
+
162
+ def expect_no_corrections
163
+ raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
164
+
165
+ return if @last_corrector.empty?
166
+
167
+ # In order to print a nice diff, e.g. what source got corrected to,
168
+ # we need to run the actual corrections
169
+
170
+ new_source = @last_corrector.rewrite
171
+
172
+ expect(new_source).to eq(@processed_source.buffer.source)
173
+ end
174
+
175
+ def expect_no_offenses(source, file = nil)
176
+ offenses = inspect_source(source, file)
177
+
178
+ expected_annotations = AnnotatedSource.parse(source)
179
+ actual_annotations = expected_annotations.with_offense_annotations(offenses)
180
+ expect(actual_annotations.to_s).to eq(source)
181
+ end
182
+
183
+ def parse_annotations(source, raise_error: true, **replacements)
184
+ set_formatter_options
185
+
186
+ source = format_offense(source, **replacements)
187
+ annotations = AnnotatedSource.parse(source)
188
+ return annotations unless raise_error && annotations.plain_source == source
189
+
190
+ raise 'Use `expect_no_offenses` to assert that no offenses are found'
191
+ end
192
+
193
+ def parse_processed_source(source, file = nil)
194
+ processed_source = parse_source(source, file)
195
+ return processed_source if processed_source.valid_syntax?
196
+
197
+ raise 'Error parsing example code: ' \
198
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
199
+ end
200
+
201
+ def set_formatter_options
202
+ RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
203
+ RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
204
+ cop.instance_variable_get(:@options)[:auto_correct] = true
205
+ end
206
+
207
+ # Parsed representation of code annotated with the `^^^ Message` style
208
+ class AnnotatedSource
209
+ ANNOTATION_PATTERN = /\A\s*(\^+|\^{}) /.freeze
210
+ ABBREV = "[...]\n"
211
+
212
+ # @param annotated_source [String] string passed to the matchers
213
+ #
214
+ # Separates annotation lines from source lines. Tracks the real
215
+ # source line number that each annotation corresponds to.
216
+ #
217
+ # @return [AnnotatedSource]
218
+ def self.parse(annotated_source)
219
+ source = []
220
+ annotations = []
221
+
222
+ annotated_source.each_line do |source_line|
223
+ if ANNOTATION_PATTERN.match?(source_line)
224
+ annotations << [source.size, source_line]
225
+ else
226
+ source << source_line
227
+ end
228
+ end
229
+ annotations.each { |a| a[0] = 1 } if source.empty?
230
+
231
+ new(source, annotations)
232
+ end
233
+
234
+ # @param lines [Array<String>]
235
+ # @param annotations [Array<(Integer, String)>]
236
+ # each entry is the annotated line number and the annotation text
237
+ #
238
+ # @note annotations are sorted so that reconstructing the annotation
239
+ # text via {#to_s} is deterministic
240
+ def initialize(lines, annotations)
241
+ @lines = lines.freeze
242
+ @annotations = annotations.sort.freeze
243
+ end
244
+
245
+ def ==(other)
246
+ other.is_a?(self.class) && other.lines == lines && match_annotations?(other)
247
+ end
248
+
249
+ # Dirty hack: expectations with [...] are rewritten when they match
250
+ # This way the diff is clean.
251
+ def match_annotations?(other)
252
+ annotations.zip(other.annotations) do |(_actual_line, actual_annotation),
253
+ (_expected_line, expected_annotation)|
254
+ if expected_annotation&.end_with?(ABBREV) &&
255
+ actual_annotation.start_with?(expected_annotation[0...-ABBREV.length])
256
+
257
+ expected_annotation.replace(actual_annotation)
258
+ end
259
+ end
260
+
261
+ annotations == other.annotations
262
+ end
263
+
264
+ # Construct annotated source string (like what we parse)
265
+ #
266
+ # Reconstruct a deterministic annotated source string. This is
267
+ # useful for eliminating semantically irrelevant annotation
268
+ # ordering differences.
269
+ #
270
+ # @example standardization
271
+ #
272
+ # source1 = AnnotatedSource.parse(<<-RUBY)
273
+ # line1
274
+ # ^ Annotation 1
275
+ # ^^ Annotation 2
276
+ # RUBY
277
+ #
278
+ # source2 = AnnotatedSource.parse(<<-RUBY)
279
+ # line1
280
+ # ^^ Annotation 2
281
+ # ^ Annotation 1
282
+ # RUBY
283
+ #
284
+ # source1.to_s == source2.to_s # => true
285
+ #
286
+ # @return [String]
287
+ def to_s
288
+ reconstructed = lines.dup
289
+
290
+ annotations.reverse_each do |line_number, annotation|
291
+ reconstructed.insert(line_number, annotation)
292
+ end
293
+
294
+ reconstructed.join
295
+ end
296
+ alias inspect to_s
297
+
298
+ # Return the plain source code without annotations
299
+ #
300
+ # @return [String]
301
+ def plain_source
302
+ lines.join
303
+ end
304
+
305
+ # Annotate the source code with the RuboCop offenses provided
306
+ #
307
+ # @param offenses [Array<RuboCop::Cop::Offense>]
308
+ #
309
+ # @return [self]
310
+ def with_offense_annotations(offenses)
311
+ offense_annotations =
312
+ offenses.map do |offense|
313
+ indent = ' ' * offense.column
314
+ carets = '^' * offense.column_length
315
+ carets = '^{}' if offense.column_length.zero?
316
+
317
+ [offense.line, "#{indent}#{carets} #{offense.message}\n"]
318
+ end
319
+
320
+ self.class.new(lines, offense_annotations)
321
+ end
322
+
323
+ protected
324
+
325
+ attr_reader :lines, :annotations
326
+ end
327
+ end
328
+ end
329
+ end
@@ -10,7 +10,7 @@ module HostEnvironmentSimulatorHelper
10
10
  pid = ::Process.fork do
11
11
  # Need to write coverage result under different name
12
12
  if defined?(SimpleCov)
13
- SimpleCov.coverage_dir "coverage/ignored_results_#{Process.pid}"
13
+ SimpleCov.command_name "rspec-fork-#{Process.pid}"
14
14
  SimpleCov.pid = Process.pid
15
15
  end
16
16
 
@@ -26,7 +26,3 @@ module HostEnvironmentSimulatorHelper
26
26
  end
27
27
  end
28
28
  end
29
-
30
- RSpec.configure do |config|
31
- config.include HostEnvironmentSimulatorHelper
32
- end
@@ -1,98 +1,137 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tmpdir'
4
- require 'fileutils'
5
4
 
6
- shared_context 'isolated environment', :isolated_environment do
5
+ RSpec.shared_context 'isolated environment', :isolated_environment do
7
6
  around do |example|
8
7
  Dir.mktmpdir do |tmpdir|
9
8
  original_home = ENV['HOME']
9
+ original_xdg_config_home = ENV['XDG_CONFIG_HOME']
10
10
 
11
11
  # Make sure to expand all symlinks in the path first. Otherwise we may
12
12
  # get mismatched pathnames when loading config files later on.
13
13
  tmpdir = File.realpath(tmpdir)
14
14
 
15
+ virtual_home = File.expand_path(File.join(tmpdir, 'home'))
16
+ Dir.mkdir(virtual_home)
17
+ ENV['HOME'] = virtual_home
18
+ ENV.delete('XDG_CONFIG_HOME')
19
+
20
+ base_dir = example.metadata[:project_inside_home] ? virtual_home : tmpdir
21
+ root = example.metadata[:root]
22
+ working_dir = root ? File.join(base_dir, 'work', root) : File.join(base_dir, 'work')
23
+
15
24
  # Make upwards search for .rubocop.yml files stop at this directory.
16
- RuboCop::ConfigLoader.root_level = tmpdir
25
+ RuboCop::FileFinder.root_level = working_dir
17
26
 
18
27
  begin
19
- virtual_home = File.expand_path(File.join(tmpdir, 'home'))
20
- Dir.mkdir(virtual_home)
21
- ENV['HOME'] = virtual_home
28
+ FileUtils.mkdir_p(working_dir)
22
29
 
23
- working_dir = File.join(tmpdir, 'work')
24
- Dir.mkdir(working_dir)
25
-
26
- Dir.chdir(working_dir) do
27
- example.run
28
- end
30
+ Dir.chdir(working_dir) { example.run }
29
31
  ensure
30
32
  ENV['HOME'] = original_home
33
+ ENV['XDG_CONFIG_HOME'] = original_xdg_config_home
34
+
35
+ RuboCop::FileFinder.root_level = nil
31
36
  end
32
37
  end
33
38
  end
34
39
  end
35
40
 
36
- # `cop_config` must be declared with #let.
37
- shared_context 'config', :config do
38
- let(:config) do
39
- # Module#<
40
- unless described_class < RuboCop::Cop::Cop
41
- raise '`config` must be used in `describe SomeCopClass do .. end`'
42
- end
41
+ RSpec.shared_context 'maintain registry', :restore_registry do
42
+ around(:each) { |example| RuboCop::Cop::Registry.with_temporary_global { example.run } }
43
+
44
+ def stub_cop_class(name, inherit: RuboCop::Cop::Base, &block)
45
+ klass = Class.new(inherit, &block)
46
+ stub_const(name, klass)
47
+ klass
48
+ end
49
+ end
50
+
51
+ # This context assumes nothing and defines `cop`, among others.
52
+ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
53
+ ### Meant to be overridden at will
43
54
 
44
- hash = { 'AllCops' => { 'TargetRubyVersion' => ruby_version } }
45
- hash['Rails'] = { 'Enabled' => true } if enabled_rails
46
- hash['AllCops']['TargetRailsVersion'] = rails_version if rails_version
47
- if respond_to?(:cop_config)
48
- cop_name = described_class.cop_name
49
- hash[cop_name] = RuboCop::ConfigLoader
50
- .default_configuration[cop_name]
51
- .merge(cop_config)
55
+ let(:cop_class) do
56
+ unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
57
+ raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
58
+ 'or RuboCop::Cop::Cop for legacy)'
52
59
  end
60
+ described_class
61
+ end
53
62
 
54
- hash = other_cops.merge hash if respond_to?(:other_cops)
63
+ let(:cop_config) { {} }
55
64
 
56
- RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
65
+ let(:other_cops) { {} }
66
+
67
+ let(:cop_options) { {} }
68
+
69
+ ### Utilities
70
+
71
+ def source_range(range, buffer: source_buffer)
72
+ Parser::Source::Range.new(buffer, range.begin,
73
+ range.exclude_end? ? range.end : range.end + 1)
57
74
  end
58
- end
59
75
 
60
- shared_context 'ruby 1.9', :ruby19 do
61
- let(:ruby_version) { 1.9 }
62
- end
76
+ ### Useful intermediary steps (less likely to be overridden)
63
77
 
64
- shared_context 'ruby 2.0', :ruby20 do
65
- let(:ruby_version) { 2.0 }
66
- end
78
+ let(:processed_source) { parse_source(source, 'test') }
67
79
 
68
- shared_context 'ruby 2.1', :ruby21 do
69
- let(:ruby_version) { 2.1 }
70
- end
80
+ let(:source_buffer) { processed_source.buffer }
81
+
82
+ let(:all_cops_config) do
83
+ rails = { 'TargetRubyVersion' => ruby_version }
84
+ rails['TargetRailsVersion'] = rails_version if rails_version
85
+ rails
86
+ end
87
+
88
+ let(:cur_cop_config) do
89
+ RuboCop::ConfigLoader
90
+ .default_configuration.for_cop(cop_class)
91
+ .merge({
92
+ 'Enabled' => true, # in case it is 'pending'
93
+ 'AutoCorrect' => true # in case defaults set it to false
94
+ })
95
+ .merge(cop_config)
96
+ end
71
97
 
72
- shared_context 'ruby 2.2', :ruby22 do
73
- let(:ruby_version) { 2.2 }
98
+ let(:config) do
99
+ hash = { 'AllCops' => all_cops_config, cop_class.cop_name => cur_cop_config }.merge!(other_cops)
100
+
101
+ RuboCop::Config.new(hash, "#{Dir.pwd}/.rubocop.yml")
102
+ end
103
+
104
+ let(:cop) { cop_class.new(config, cop_options) }
74
105
  end
75
106
 
76
- shared_context 'ruby 2.3', :ruby23 do
77
- let(:ruby_version) { 2.3 }
107
+ RSpec.shared_context 'mock console output' do
108
+ before do
109
+ $stdout = StringIO.new
110
+ $stderr = StringIO.new
111
+ end
112
+
113
+ after do
114
+ $stdout = STDOUT
115
+ $stderr = STDERR
116
+ end
78
117
  end
79
118
 
80
- shared_context 'ruby 2.4', :ruby24 do
81
- let(:ruby_version) { 2.4 }
119
+ RSpec.shared_context 'ruby 2.5', :ruby25 do
120
+ let(:ruby_version) { 2.5 }
82
121
  end
83
122
 
84
- shared_context 'with Rails', :enabled_rails do
85
- let(:enabled_rails) { true }
123
+ RSpec.shared_context 'ruby 2.6', :ruby26 do
124
+ let(:ruby_version) { 2.6 }
86
125
  end
87
126
 
88
- shared_context 'with Rails 3', :rails3 do
89
- let(:rails_version) { 3.0 }
127
+ RSpec.shared_context 'ruby 2.7', :ruby27 do
128
+ let(:ruby_version) { 2.7 }
90
129
  end
91
130
 
92
- shared_context 'with Rails 4', :rails4 do
93
- let(:rails_version) { 4.0 }
131
+ RSpec.shared_context 'ruby 3.0', :ruby30 do
132
+ let(:ruby_version) { 3.0 }
94
133
  end
95
134
 
96
- shared_context 'with Rails 5', :rails5 do
97
- let(:rails_version) { 5.0 }
135
+ RSpec.shared_context 'ruby 3.1', :ruby31 do
136
+ let(:ruby_version) { 3.1 }
98
137
  end