rubocop 0.50.0 → 0.51.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (318) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -6
  3. data/config/default.yml +20 -11
  4. data/config/enabled.yml +44 -7
  5. data/lib/rubocop.rb +526 -514
  6. data/lib/rubocop/ast/node.rb +9 -9
  7. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +2 -2
  8. data/lib/rubocop/ast/node/send_node.rb +4 -0
  9. data/lib/rubocop/cached_data.rb +1 -6
  10. data/lib/rubocop/cli.rb +7 -6
  11. data/lib/rubocop/config.rb +58 -22
  12. data/lib/rubocop/config_loader.rb +37 -21
  13. data/lib/rubocop/config_loader_resolver.rb +3 -2
  14. data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -3
  15. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +4 -2
  16. data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -53
  17. data/lib/rubocop/cop/commissioner.rb +1 -4
  18. data/lib/rubocop/cop/cop.rb +50 -17
  19. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +96 -0
  20. data/lib/rubocop/cop/generator.rb +8 -3
  21. data/lib/rubocop/cop/internal_affairs.rb +6 -5
  22. data/lib/rubocop/cop/internal_affairs/deprecated_positional_arguments.rb +81 -0
  23. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  24. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +21 -11
  25. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +27 -14
  26. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +38 -16
  27. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
  28. data/lib/rubocop/cop/layout/block_end_newline.rb +1 -1
  29. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  30. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  31. data/lib/rubocop/cop/layout/comment_indentation.rb +4 -2
  32. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  33. data/lib/rubocop/cop/layout/else_alignment.rb +5 -2
  34. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +1 -1
  35. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
  36. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  37. data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
  38. data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
  39. data/lib/rubocop/cop/layout/indent_array.rb +1 -1
  40. data/lib/rubocop/cop/layout/indent_hash.rb +1 -1
  41. data/lib/rubocop/cop/layout/indent_heredoc.rb +2 -2
  42. data/lib/rubocop/cop/layout/indentation_width.rb +7 -5
  43. data/lib/rubocop/cop/layout/initial_indentation.rb +3 -2
  44. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
  45. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  46. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
  47. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  48. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  49. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -2
  50. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +1 -1
  51. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  52. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  53. data/lib/rubocop/cop/layout/space_before_block_braces.rb +4 -4
  54. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
  55. data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
  56. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +6 -2
  57. data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
  58. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  59. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +5 -2
  60. data/lib/rubocop/cop/layout/space_inside_parens.rb +9 -0
  61. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
  62. data/lib/rubocop/cop/layout/tab.rb +5 -2
  63. data/lib/rubocop/cop/layout/trailing_blank_lines.rb +4 -2
  64. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  65. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
  66. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  67. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  68. data/lib/rubocop/cop/lint/circular_argument_reference.rb +3 -14
  69. data/lib/rubocop/cop/lint/debugger.rb +7 -7
  70. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  71. data/lib/rubocop/cop/lint/duplicate_methods.rb +5 -3
  72. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
  73. data/lib/rubocop/cop/lint/empty_expression.rb +1 -1
  74. data/lib/rubocop/cop/lint/empty_when.rb +1 -1
  75. data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
  76. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  77. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  78. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +4 -3
  79. data/lib/rubocop/cop/lint/interpolation_check.rb +2 -1
  80. data/lib/rubocop/cop/lint/{literal_in_condition.rb → literal_as_condition.rb} +19 -5
  81. data/lib/rubocop/cop/lint/loop.rb +1 -1
  82. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  83. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  84. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -2
  85. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  86. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  87. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  88. data/lib/rubocop/cop/lint/redundant_with_object.rb +81 -0
  89. data/lib/rubocop/cop/lint/regexp_as_condition.rb +29 -0
  90. data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
  91. data/lib/rubocop/cop/lint/rescue_type.rb +5 -3
  92. data/lib/rubocop/cop/lint/rescue_without_error_class.rb +6 -3
  93. data/lib/rubocop/cop/lint/return_in_void_context.rb +24 -13
  94. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  95. data/lib/rubocop/cop/lint/script_permission.rb +1 -1
  96. data/lib/rubocop/cop/lint/shadowed_exception.rb +37 -10
  97. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
  98. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
  99. data/lib/rubocop/cop/lint/syntax.rb +8 -2
  100. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +1 -1
  101. data/lib/rubocop/cop/lint/unified_integer.rb +2 -2
  102. data/lib/rubocop/cop/lint/unneeded_disable.rb +11 -4
  103. data/lib/rubocop/cop/lint/unneeded_require_statement.rb +50 -0
  104. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +2 -2
  105. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  106. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
  107. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -2
  108. data/lib/rubocop/cop/lint/uri_regexp.rb +3 -3
  109. data/lib/rubocop/cop/lint/useless_access_modifier.rb +9 -9
  110. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
  111. data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
  112. data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
  113. data/lib/rubocop/cop/lint/void.rb +10 -5
  114. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  115. data/lib/rubocop/cop/metrics/line_length.rb +4 -1
  116. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -2
  117. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +3 -2
  118. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
  119. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  120. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  121. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  122. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +7 -2
  123. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  124. data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
  125. data/lib/rubocop/cop/mixin/heredoc.rb +1 -1
  126. data/lib/rubocop/cop/mixin/method_complexity.rb +3 -4
  127. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  128. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +10 -4
  129. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +63 -0
  130. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +4 -1
  131. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -1
  132. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +2 -1
  133. data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
  134. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  135. data/lib/rubocop/cop/mixin/trailing_comma.rb +5 -5
  136. data/lib/rubocop/cop/mixin/unused_argument.rb +43 -2
  137. data/lib/rubocop/cop/naming/accessor_method_name.rb +8 -7
  138. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  139. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  140. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  141. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  142. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  143. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
  144. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -2
  145. data/lib/rubocop/cop/naming/predicate_name.rb +36 -5
  146. data/lib/rubocop/cop/performance/caller.rb +2 -2
  147. data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
  148. data/lib/rubocop/cop/performance/casecmp.rb +1 -1
  149. data/lib/rubocop/cop/performance/compare_with_block.rb +6 -2
  150. data/lib/rubocop/cop/performance/count.rb +3 -1
  151. data/lib/rubocop/cop/performance/detect.rb +4 -4
  152. data/lib/rubocop/cop/performance/double_start_end_with.rb +6 -9
  153. data/lib/rubocop/cop/performance/end_with.rb +1 -1
  154. data/lib/rubocop/cop/performance/flat_map.rb +3 -1
  155. data/lib/rubocop/cop/performance/hash_each_methods.rb +13 -10
  156. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +3 -1
  157. data/lib/rubocop/cop/performance/range_include.rb +1 -1
  158. data/lib/rubocop/cop/performance/redundant_block_call.rb +1 -1
  159. data/lib/rubocop/cop/performance/redundant_match.rb +6 -5
  160. data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
  161. data/lib/rubocop/cop/performance/redundant_sort_by.rb +4 -1
  162. data/lib/rubocop/cop/performance/regexp_match.rb +4 -4
  163. data/lib/rubocop/cop/performance/reverse_each.rb +1 -1
  164. data/lib/rubocop/cop/performance/sample.rb +1 -1
  165. data/lib/rubocop/cop/performance/size.rb +1 -1
  166. data/lib/rubocop/cop/performance/start_with.rb +1 -1
  167. data/lib/rubocop/cop/performance/string_replacement.rb +2 -2
  168. data/lib/rubocop/cop/performance/times_map.rb +3 -3
  169. data/lib/rubocop/cop/performance/unfreeze_string.rb +2 -2
  170. data/lib/rubocop/cop/performance/uri_default_parser.rb +2 -2
  171. data/lib/rubocop/cop/rails/action_filter.rb +1 -1
  172. data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -2
  173. data/lib/rubocop/cop/rails/application_job.rb +1 -1
  174. data/lib/rubocop/cop/rails/application_record.rb +1 -1
  175. data/lib/rubocop/cop/rails/blank.rb +20 -17
  176. data/lib/rubocop/cop/rails/date.rb +7 -6
  177. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  178. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
  179. data/lib/rubocop/cop/rails/dynamic_find_by.rb +2 -2
  180. data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -2
  181. data/lib/rubocop/cop/rails/exit.rb +1 -1
  182. data/lib/rubocop/cop/rails/file_path.rb +6 -8
  183. data/lib/rubocop/cop/rails/find_by.rb +2 -1
  184. data/lib/rubocop/cop/rails/find_each.rb +1 -1
  185. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  186. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +35 -11
  187. data/lib/rubocop/cop/rails/http_positional_arguments.rb +3 -2
  188. data/lib/rubocop/cop/rails/not_null_column.rb +5 -5
  189. data/lib/rubocop/cop/rails/output.rb +2 -2
  190. data/lib/rubocop/cop/rails/output_safety.rb +2 -1
  191. data/lib/rubocop/cop/rails/present.rb +14 -17
  192. data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -3
  193. data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
  194. data/lib/rubocop/cop/rails/request_referer.rb +2 -2
  195. data/lib/rubocop/cop/rails/reversible_migration.rb +21 -19
  196. data/lib/rubocop/cop/rails/safe_navigation.rb +2 -2
  197. data/lib/rubocop/cop/rails/save_bang.rb +12 -12
  198. data/lib/rubocop/cop/rails/scope_args.rb +1 -1
  199. data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
  200. data/lib/rubocop/cop/rails/time_zone.rb +3 -2
  201. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -1
  202. data/lib/rubocop/cop/rails/unknown_env.rb +63 -0
  203. data/lib/rubocop/cop/rails/validation.rb +1 -1
  204. data/lib/rubocop/cop/registry.rb +2 -1
  205. data/lib/rubocop/cop/security/eval.rb +2 -2
  206. data/lib/rubocop/cop/security/json_load.rb +2 -2
  207. data/lib/rubocop/cop/security/marshal_load.rb +3 -3
  208. data/lib/rubocop/cop/security/yaml_load.rb +2 -2
  209. data/lib/rubocop/cop/style/alias.rb +3 -3
  210. data/lib/rubocop/cop/style/and_or.rb +1 -1
  211. data/lib/rubocop/cop/style/array_join.rb +1 -1
  212. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  213. data/lib/rubocop/cop/style/attr.rb +1 -1
  214. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -2
  215. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  216. data/lib/rubocop/cop/style/begin_block.rb +1 -1
  217. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  218. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +22 -19
  219. data/lib/rubocop/cop/style/case_equality.rb +1 -1
  220. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  221. data/lib/rubocop/cop/style/class_check.rb +1 -1
  222. data/lib/rubocop/cop/style/class_methods.rb +2 -1
  223. data/lib/rubocop/cop/style/class_vars.rb +1 -1
  224. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  225. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  226. data/lib/rubocop/cop/style/comment_annotation.rb +5 -2
  227. data/lib/rubocop/cop/style/commented_keyword.rb +81 -0
  228. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  229. data/lib/rubocop/cop/style/copyright.rb +1 -1
  230. data/lib/rubocop/cop/style/date_time.rb +44 -0
  231. data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
  232. data/lib/rubocop/cop/style/dir.rb +2 -6
  233. data/lib/rubocop/cop/style/documentation.rb +1 -1
  234. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  235. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  236. data/lib/rubocop/cop/style/each_with_object.rb +2 -1
  237. data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
  238. data/lib/rubocop/cop/style/empty_else.rb +2 -2
  239. data/lib/rubocop/cop/style/empty_literal.rb +9 -9
  240. data/lib/rubocop/cop/style/encoding.rb +7 -51
  241. data/lib/rubocop/cop/style/end_block.rb +1 -1
  242. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  243. data/lib/rubocop/cop/style/for.rb +6 -2
  244. data/lib/rubocop/cop/style/format_string.rb +4 -3
  245. data/lib/rubocop/cop/style/format_string_token.rb +2 -1
  246. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -3
  247. data/lib/rubocop/cop/style/global_vars.rb +1 -1
  248. data/lib/rubocop/cop/style/guard_clause.rb +2 -2
  249. data/lib/rubocop/cop/style/hash_syntax.rb +2 -3
  250. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  251. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -1
  252. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +2 -1
  253. data/lib/rubocop/cop/style/implicit_runtime_error.rb +2 -2
  254. data/lib/rubocop/cop/style/infinite_loop.rb +2 -2
  255. data/lib/rubocop/cop/style/inverse_methods.rb +4 -6
  256. data/lib/rubocop/cop/style/lambda.rb +3 -3
  257. data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
  258. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -1
  259. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
  260. data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -2
  261. data/lib/rubocop/cop/style/min_max.rb +2 -1
  262. data/lib/rubocop/cop/style/mixin_usage.rb +73 -0
  263. data/lib/rubocop/cop/style/module_function.rb +2 -2
  264. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  265. data/lib/rubocop/cop/style/multiline_if_then.rb +2 -1
  266. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  267. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  268. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +3 -1
  269. data/lib/rubocop/cop/style/next.rb +2 -1
  270. data/lib/rubocop/cop/style/nil_comparison.rb +2 -2
  271. data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
  272. data/lib/rubocop/cop/style/not.rb +1 -1
  273. data/lib/rubocop/cop/style/numeric_predicate.rb +2 -2
  274. data/lib/rubocop/cop/style/option_hash.rb +0 -11
  275. data/lib/rubocop/cop/style/or_assignment.rb +1 -1
  276. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  277. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  278. data/lib/rubocop/cop/style/preferred_hash_methods.rb +1 -1
  279. data/lib/rubocop/cop/style/proc.rb +1 -1
  280. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  281. data/lib/rubocop/cop/style/redundant_exception.rb +4 -4
  282. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  283. data/lib/rubocop/cop/style/redundant_return.rb +1 -1
  284. data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
  285. data/lib/rubocop/cop/style/return_nil.rb +2 -7
  286. data/lib/rubocop/cop/style/safe_navigation.rb +27 -30
  287. data/lib/rubocop/cop/style/self_assignment.rb +2 -2
  288. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  289. data/lib/rubocop/cop/style/send.rb +1 -1
  290. data/lib/rubocop/cop/style/signal_exception.rb +4 -3
  291. data/lib/rubocop/cop/style/stderr_puts.rb +52 -0
  292. data/lib/rubocop/cop/style/string_literals.rb +4 -3
  293. data/lib/rubocop/cop/style/string_methods.rb +1 -1
  294. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
  295. data/lib/rubocop/cop/style/symbol_array.rb +1 -5
  296. data/lib/rubocop/cop/style/symbol_proc.rb +5 -5
  297. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -2
  298. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +46 -23
  299. data/lib/rubocop/cop/style/trivial_accessors.rb +3 -1
  300. data/lib/rubocop/cop/style/variable_interpolation.rb +0 -2
  301. data/lib/rubocop/cop/style/when_then.rb +1 -1
  302. data/lib/rubocop/cop/style/while_until_do.rb +2 -1
  303. data/lib/rubocop/cop/style/while_until_modifier.rb +2 -1
  304. data/lib/rubocop/cop/style/word_array.rb +2 -2
  305. data/lib/rubocop/cop/style/zero_length_predicate.rb +4 -4
  306. data/lib/rubocop/cop/util.rb +1 -12
  307. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  308. data/lib/rubocop/formatter/simple_text_formatter.rb +2 -2
  309. data/lib/rubocop/node_pattern.rb +1 -1
  310. data/lib/rubocop/options.rb +4 -0
  311. data/lib/rubocop/processed_source.rb +2 -8
  312. data/lib/rubocop/rake_task.rb +16 -23
  313. data/lib/rubocop/remote_config.rb +8 -0
  314. data/lib/rubocop/rspec/shared_contexts.rb +0 -8
  315. data/lib/rubocop/rspec/support.rb +5 -5
  316. data/lib/rubocop/version.rb +1 -1
  317. metadata +40 -30
  318. data/lib/rubocop/cop/lint/invalid_character_literal.rb +0 -41
@@ -58,7 +58,8 @@ module RuboCop
58
58
 
59
59
  return if safe_chain?(node) || safe_to_time?(node)
60
60
 
61
- add_offense(node, :selector, format(MSG_SEND, node.method_name))
61
+ add_offense(node, location: :selector,
62
+ message: format(MSG_SEND, node.method_name))
62
63
  end
63
64
 
64
65
  private
@@ -70,10 +71,10 @@ module RuboCop
70
71
 
71
72
  method_name = (chain & bad_days).join('.')
72
73
 
73
- add_offense(node, :selector,
74
- format(MSG,
75
- "Date.#{method_name}",
76
- "Time.zone.#{method_name}"))
74
+ add_offense(node, location: :selector,
75
+ message: format(MSG,
76
+ "Date.#{method_name}",
77
+ "Time.zone.#{method_name}"))
77
78
  end
78
79
 
79
80
  def extract_method_chain(node)
@@ -98,7 +99,7 @@ module RuboCop
98
99
  return unless node.method?(:to_time)
99
100
 
100
101
  if node.receiver.str_type?
101
- zone_regexp = /[+-][\d:]+\z/
102
+ zone_regexp = /([+-][\d:]+|\dZ)\z/
102
103
 
103
104
  node.receiver.str_content.match(zone_regexp)
104
105
  else
@@ -59,7 +59,7 @@ module RuboCop
59
59
  method_name, args, body = *node
60
60
  return unless trivial_delegate?(method_name, args, body)
61
61
  return if private_or_protected_delegation(node)
62
- add_offense(node, :keyword)
62
+ add_offense(node, location: :keyword)
63
63
  end
64
64
 
65
65
  private
@@ -17,7 +17,7 @@ module RuboCop
17
17
  MSG = '`allow_blank` is not a valid option, use `allow_nil`.'.freeze
18
18
 
19
19
  def_node_matcher :delegate_options, <<-PATTERN
20
- (send nil :delegate _ $hash)
20
+ (send nil? :delegate _ $hash)
21
21
  PATTERN
22
22
 
23
23
  def_node_matcher :allow_blank_option?, <<-PATTERN
@@ -38,8 +38,8 @@ module RuboCop
38
38
 
39
39
  return unless static_name
40
40
 
41
- add_offense(node, :expression,
42
- format(MSG, static_name, node.method_name))
41
+ add_offense(node,
42
+ message: format(MSG, static_name, node.method_name))
43
43
  end
44
44
 
45
45
  def autocorrect(node)
@@ -23,7 +23,7 @@ module RuboCop
23
23
  MSG = 'Duplicate value `%s` found in `%s` enum declaration.'.freeze
24
24
 
25
25
  def_node_matcher :enum_declaration, <<-PATTERN
26
- (send nil :enum (hash (pair (_ $_) ${array hash})))
26
+ (send nil? :enum (hash (pair (_ $_) ${array hash})))
27
27
  PATTERN
28
28
 
29
29
  def on_send(node)
@@ -33,7 +33,7 @@ module RuboCop
33
33
  return unless duplicates?(items)
34
34
 
35
35
  consecutive_duplicates(items).each do |item|
36
- add_offense(item, :expression, format(MSG, item.source, name))
36
+ add_offense(item, message: format(MSG, item.source, name))
37
37
  end
38
38
  end
39
39
  end
@@ -24,7 +24,7 @@ module RuboCop
24
24
  EXPLICIT_RECEIVERS = %i[Kernel Process].freeze
25
25
 
26
26
  def on_send(node)
27
- add_offense(node, :selector) if offending_node?(node)
27
+ add_offense(node, location: :selector) if offending_node?(node)
28
28
  end
29
29
 
30
30
  private
@@ -18,15 +18,15 @@ module RuboCop
18
18
  MSG = 'Please use `Rails.root.join(\'path\', \'to\')` instead.'.freeze
19
19
 
20
20
  def_node_matcher :file_join_nodes?, <<-PATTERN
21
- (send (const nil :File) :join ...)
21
+ (send (const nil? :File) :join ...)
22
22
  PATTERN
23
23
 
24
24
  def_node_search :rails_root_nodes?, <<-PATTERN
25
- (send (const nil :Rails) :root)
25
+ (send (const nil? :Rails) :root)
26
26
  PATTERN
27
27
 
28
28
  def_node_matcher :rails_root_join_nodes?, <<-PATTERN
29
- (send (send (const nil :Rails) :root) :join ...)
29
+ (send (send (const nil? :Rails) :root) :join ...)
30
30
  PATTERN
31
31
 
32
32
  def on_dstr(node)
@@ -62,11 +62,9 @@ module RuboCop
62
62
 
63
63
  def register_offense(node)
64
64
  line_range = node.loc.column...node.loc.last_column
65
-
66
- add_offense(
67
- node,
68
- source_range(processed_source.buffer, node.loc.line, line_range)
69
- )
65
+ source_range = source_range(processed_source.buffer, node.loc.line,
66
+ line_range)
67
+ add_offense(node, location: source_range)
70
68
  end
71
69
  end
72
70
  end
@@ -27,7 +27,8 @@ module RuboCop
27
27
  range = range_between(node.receiver.loc.selector.begin_pos,
28
28
  node.loc.selector.end_pos)
29
29
 
30
- add_offense(node, range, format(MSG, node.method_name))
30
+ add_offense(node, location: range,
31
+ message: format(MSG, node.method_name))
31
32
  end
32
33
 
33
34
  def autocorrect(node)
@@ -24,7 +24,7 @@ module RuboCop
24
24
  return unless SCOPE_METHODS.include?(node.receiver.method_name)
25
25
  return if method_chain(node).any? { |m| ignored_by_find_each?(m) }
26
26
 
27
- add_offense(node, :selector)
27
+ add_offense(node, location: :selector)
28
28
  end
29
29
 
30
30
  def autocorrect(node)
@@ -10,7 +10,7 @@ module RuboCop
10
10
  def on_send(node)
11
11
  return unless node.command?(:has_and_belongs_to_many)
12
12
 
13
- add_offense(node, :selector)
13
+ add_offense(node, location: :selector)
14
14
  end
15
15
  end
16
16
  end
@@ -5,6 +5,7 @@ module RuboCop
5
5
  module Rails
6
6
  # This cop looks for `has_many` or `has_one` associations that don't
7
7
  # specify a `:dependent` option.
8
+ # It doesn't register an offense if `:through` option was specified.
8
9
  #
9
10
  # @example
10
11
  # # bad
@@ -17,30 +18,53 @@ module RuboCop
17
18
  # class User < ActiveRecord::Base
18
19
  # has_many :comments, dependent: :restrict_with_exception
19
20
  # has_one :avatar, dependent: :destroy
21
+ # has_many :patients, through: :appointments
20
22
  # end
21
23
  class HasManyOrHasOneDependent < Cop
22
24
  MSG = 'Specify a `:dependent` option.'.freeze
23
25
 
24
- def_node_matcher :is_has_many_or_has_one_without_options?, <<-PATTERN
25
- (send nil {:has_many :has_one} _)
26
+ def_node_matcher :association_without_options?, <<-PATTERN
27
+ (send nil? {:has_many :has_one} _)
26
28
  PATTERN
27
29
 
28
- def_node_matcher :is_has_many_or_has_one_with_options?, <<-PATTERN
29
- (send nil {:has_many :has_one} _ (hash $...))
30
+ def_node_matcher :association_with_options?, <<-PATTERN
31
+ (send nil? {:has_many :has_one} _ (hash $...))
30
32
  PATTERN
31
33
 
32
- def_node_matcher :has_dependent?, <<-PATTERN
33
- (pair (sym :dependent) !(:nil))
34
+ def_node_matcher :dependent_option?, <<-PATTERN
35
+ (pair (sym :dependent) !nil)
36
+ PATTERN
37
+
38
+ def_node_matcher :present_option?, <<-PATTERN
39
+ (pair (sym :through) !nil)
40
+ PATTERN
41
+
42
+ def_node_matcher :with_options_block, <<-PATTERN
43
+ (block
44
+ (send nil? :with_options
45
+ (hash $...))
46
+ (args) ...)
34
47
  PATTERN
35
48
 
36
49
  def on_send(node)
37
- unless is_has_many_or_has_one_without_options?(node)
38
- pairs = is_has_many_or_has_one_with_options?(node)
39
- return unless pairs
40
- return if pairs.any? { |pair| has_dependent?(pair) }
50
+ if !association_without_options?(node)
51
+ return if valid_options?(association_with_options?(node))
52
+ elsif with_options_block(node.parent)
53
+ return if valid_options?(with_options_block(node.parent))
54
+ end
55
+
56
+ add_offense(node, location: :selector)
57
+ end
58
+
59
+ private
60
+
61
+ def valid_options?(options)
62
+ return true unless options
63
+ return true if options.any? do |o|
64
+ dependent_option?(o) || present_option?(o)
41
65
  end
42
66
 
43
- add_offense(node, :selector)
67
+ false
44
68
  end
45
69
  end
46
70
  end
@@ -29,7 +29,7 @@ module RuboCop
29
29
  minimum_target_rails_version 5.0
30
30
 
31
31
  def_node_matcher :http_request?, <<-PATTERN
32
- (send nil {#{HTTP_METHODS.map(&:inspect).join(' ')}} !nil $_data ...)
32
+ (send nil? {#{HTTP_METHODS.map(&:inspect).join(' ')}} !nil? $_data ...)
33
33
  PATTERN
34
34
 
35
35
  def on_send(node)
@@ -39,7 +39,8 @@ module RuboCop
39
39
  return if data.nil?
40
40
  return unless needs_conversion?(data)
41
41
 
42
- add_offense(node, :selector, format(MSG, node.method_name))
42
+ add_offense(node, location: :selector,
43
+ message: format(MSG, node.method_name))
43
44
  end
44
45
 
45
46
  # @return [Boolean] true if the line needs to be converted
@@ -20,19 +20,19 @@ module RuboCop
20
20
  MSG = 'Do not add a NOT NULL column without a default value.'.freeze
21
21
 
22
22
  def_node_matcher :add_not_null_column?, <<-PATTERN
23
- (send nil :add_column _ _ _ (hash $...))
23
+ (send nil? :add_column _ _ _ (hash $...))
24
24
  PATTERN
25
25
 
26
26
  def_node_matcher :add_not_null_reference?, <<-PATTERN
27
- (send nil :add_reference _ _ (hash $...))
27
+ (send nil? :add_reference _ _ (hash $...))
28
28
  PATTERN
29
29
 
30
30
  def_node_matcher :null_false?, <<-PATTERN
31
31
  (pair (sym :null) (false))
32
32
  PATTERN
33
33
 
34
- def_node_matcher :has_default?, <<-PATTERN
35
- (pair (sym :default) !(:nil))
34
+ def_node_matcher :default_option?, <<-PATTERN
35
+ (pair (sym :default) !nil)
36
36
  PATTERN
37
37
 
38
38
  def on_send(node)
@@ -54,7 +54,7 @@ module RuboCop
54
54
 
55
55
  def check_pairs(pairs)
56
56
  return unless pairs
57
- return if pairs.any? { |pair| has_default?(pair) }
57
+ return if pairs.any? { |pair| default_option?(pair) }
58
58
 
59
59
  null_false = pairs.find { |pair| null_false?(pair) }
60
60
  return unless null_false
@@ -9,13 +9,13 @@ module RuboCop
9
9
  "Use Rails's logger if you want to log.".freeze
10
10
 
11
11
  def_node_matcher :output?, <<-PATTERN
12
- (send nil {:ap :p :pp :pretty_print :print :puts} ...)
12
+ (send nil? {:ap :p :pp :pretty_print :print :puts} ...)
13
13
  PATTERN
14
14
 
15
15
  def on_send(node)
16
16
  return unless output?(node) && node.arguments?
17
17
 
18
- add_offense(node, :selector)
18
+ add_offense(node, location: :selector)
19
19
  end
20
20
  end
21
21
  end
@@ -76,8 +76,9 @@ module RuboCop
76
76
  looks_like_rails_raw?(node) ||
77
77
  looks_like_rails_safe_concat?(node)
78
78
 
79
- add_offense(node, :selector)
79
+ add_offense(node, location: :selector)
80
80
  end
81
+ alias on_csend on_send
81
82
 
82
83
  private
83
84
 
@@ -36,15 +36,15 @@ module RuboCop
36
36
  # something if foo.present?
37
37
  class Present < Cop
38
38
  MSG_NOT_BLANK = 'Use `%s` instead of `%s`.'.freeze
39
- MSG_EXISTS_AND_NOT_EMPTY = 'Use `%s.present?` instead of `%s`.'.freeze
40
- MSG_UNLESS_BLANK = 'Use `if %s.present?` instead of `%s`.'.freeze
39
+ MSG_EXISTS_AND_NOT_EMPTY = 'Use `%s` instead of `%s`.'.freeze
40
+ MSG_UNLESS_BLANK = 'Use `if %s` instead of `%s`.'.freeze
41
41
 
42
42
  def_node_matcher :exists_and_not_empty?, <<-PATTERN
43
43
  (and
44
44
  {
45
45
  (send (send $_ :nil?) :!)
46
46
  (send (send $_ :!) :!)
47
- (send $_ :!= (:nil))
47
+ (send $_ :!= nil)
48
48
  $_
49
49
  }
50
50
  {
@@ -56,7 +56,7 @@ module RuboCop
56
56
  def_node_matcher :not_blank?, '(send (send $_ :blank?) :!)'
57
57
 
58
58
  def_node_matcher :unless_blank?, <<-PATTERN
59
- (:if $(send $_ :blank?) {nil (...)} ...)
59
+ (:if $(send $_ :blank?) {nil? (...)} ...)
60
60
  PATTERN
61
61
 
62
62
  def on_send(node)
@@ -64,10 +64,9 @@ module RuboCop
64
64
 
65
65
  not_blank?(node) do |receiver|
66
66
  add_offense(node,
67
- :expression,
68
- format(MSG_NOT_BLANK,
69
- replacement(receiver),
70
- node.source))
67
+ message: format(MSG_NOT_BLANK,
68
+ replacement(receiver),
69
+ node.source))
71
70
  end
72
71
  end
73
72
 
@@ -78,10 +77,9 @@ module RuboCop
78
77
  return unless variable1 == variable2
79
78
 
80
79
  add_offense(node,
81
- :expression,
82
- format(MSG_EXISTS_AND_NOT_EMPTY,
83
- variable1.source,
84
- node.source))
80
+ message: format(MSG_EXISTS_AND_NOT_EMPTY,
81
+ replacement(variable1),
82
+ node.source))
85
83
  end
86
84
  end
87
85
 
@@ -91,7 +89,7 @@ module RuboCop
91
89
  exists_and_not_empty?(node) do |variable1, variable2|
92
90
  return unless variable1 == variable2
93
91
 
94
- add_offense(node, :expression, MSG_EXISTS_AND_NOT_EMPTY)
92
+ add_offense(node, message: MSG_EXISTS_AND_NOT_EMPTY)
95
93
  end
96
94
  end
97
95
 
@@ -101,9 +99,8 @@ module RuboCop
101
99
 
102
100
  unless_blank?(node) do |method_call, receiver|
103
101
  range = unless_condition(node, method_call)
104
- add_offense(node,
105
- range,
106
- format(MSG_UNLESS_BLANK, receiver.source, range.source))
102
+ msg = format(MSG_UNLESS_BLANK, replacement(receiver), range.source)
103
+ add_offense(node, location: range, message: msg)
107
104
  end
108
105
  end
109
106
 
@@ -111,7 +108,7 @@ module RuboCop
111
108
  lambda do |corrector|
112
109
  method_call, variable1 = unless_blank?(node)
113
110
 
114
- if method_call && variable1
111
+ if method_call
115
112
  corrector.replace(node.loc.keyword, 'if')
116
113
  range = method_call.loc.expression
117
114
  else
@@ -20,15 +20,15 @@ module RuboCop
20
20
 
21
21
  def_node_matcher :read_write_attribute?, <<-PATTERN
22
22
  {
23
- (send nil :read_attribute _)
24
- (send nil :write_attribute _ _)
23
+ (send nil? :read_attribute _)
24
+ (send nil? :write_attribute _ _)
25
25
  }
26
26
  PATTERN
27
27
 
28
28
  def on_send(node)
29
29
  return unless read_write_attribute?(node)
30
30
 
31
- add_offense(node, :selector)
31
+ add_offense(node, location: :selector)
32
32
  end
33
33
 
34
34
  private
@@ -63,7 +63,7 @@ module RuboCop
63
63
 
64
64
  nodes.each do |n|
65
65
  if relative_date_method?(n)
66
- add_offense(node.parent, :expression, format(MSG, n.method_name))
66
+ add_offense(node.parent, message: format(MSG, n.method_name))
67
67
  end
68
68
  end
69
69
  end
@@ -26,14 +26,14 @@ module RuboCop
26
26
  MSG = 'Use `request.%s` instead of `request.%s`.'.freeze
27
27
 
28
28
  def_node_matcher :referer?, <<-PATTERN
29
- (send (send nil :request) {:referer :referrer})
29
+ (send (send nil? :request) {:referer :referrer})
30
30
  PATTERN
31
31
 
32
32
  def on_send(node)
33
33
  referer?(node) do
34
34
  return unless node.method?(wrong_method_name)
35
35
 
36
- add_offense(node.source_range, node.source_range)
36
+ add_offense(node.source_range, location: node.source_range)
37
37
  end
38
38
  end
39
39
 
@@ -132,27 +132,27 @@ module RuboCop
132
132
  ].freeze
133
133
 
134
134
  def_node_matcher :irreversible_schema_statement_call, <<-PATTERN
135
- (send nil ${:change_table_comment :execute :remove_belongs_to} ...)
135
+ (send nil? ${:change_table_comment :execute :remove_belongs_to} ...)
136
136
  PATTERN
137
137
 
138
138
  def_node_matcher :drop_table_call, <<-PATTERN
139
- (send nil :drop_table ...)
139
+ (send nil? :drop_table ...)
140
140
  PATTERN
141
141
 
142
142
  def_node_matcher :change_column_default_call, <<-PATTERN
143
- (send nil :change_column_default _ _ $...)
143
+ (send nil? :change_column_default _ _ $...)
144
144
  PATTERN
145
145
 
146
146
  def_node_matcher :remove_column_call, <<-PATTERN
147
- (send nil :remove_column $...)
147
+ (send nil? :remove_column $...)
148
148
  PATTERN
149
149
 
150
150
  def_node_matcher :remove_foreign_key_call, <<-PATTERN
151
- (send nil :remove_foreign_key _ $_)
151
+ (send nil? :remove_foreign_key _ $_)
152
152
  PATTERN
153
153
 
154
154
  def_node_matcher :change_table_call, <<-PATTERN
155
- (send nil :change_table $_ ...)
155
+ (send nil? :change_table $_ ...)
156
156
  PATTERN
157
157
 
158
158
  def on_send(node)
@@ -177,7 +177,7 @@ module RuboCop
177
177
 
178
178
  def check_irreversible_schema_statement_node(node)
179
179
  irreversible_schema_statement_call(node) do |method_name|
180
- add_offense(node, :expression, format(MSG, method_name))
180
+ add_offense(node, message: format(MSG, method_name))
181
181
  end
182
182
  end
183
183
 
@@ -185,8 +185,8 @@ module RuboCop
185
185
  drop_table_call(node) do
186
186
  unless node.parent.block_type?
187
187
  add_offense(
188
- node, :expression,
189
- format(MSG, 'drop_table(without block)')
188
+ node,
189
+ message: format(MSG, 'drop_table(without block)')
190
190
  )
191
191
  end
192
192
  end
@@ -196,8 +196,10 @@ module RuboCop
196
196
  change_column_default_call(node) do |args|
197
197
  unless all_hash_key?(args.first, :from, :to)
198
198
  add_offense(
199
- node, :expression,
200
- format(MSG, 'change_column_default(without :from and :to)')
199
+ node,
200
+ message: format(
201
+ MSG, 'change_column_default(without :from and :to)'
202
+ )
201
203
  )
202
204
  end
203
205
  end
@@ -207,8 +209,8 @@ module RuboCop
207
209
  remove_column_call(node) do |args|
208
210
  if args.to_a.size < 3
209
211
  add_offense(
210
- node, :expression,
211
- format(MSG, 'remove_column(without type)')
212
+ node,
213
+ message: format(MSG, 'remove_column(without type)')
212
214
  )
213
215
  end
214
216
  end
@@ -218,8 +220,8 @@ module RuboCop
218
220
  remove_foreign_key_call(node) do |arg|
219
221
  if arg.hash_type?
220
222
  add_offense(
221
- node, :expression,
222
- format(MSG, 'remove_foreign_key(without table)')
223
+ node,
224
+ message: format(MSG, 'remove_foreign_key(without table)')
223
225
  )
224
226
  end
225
227
  end
@@ -229,8 +231,8 @@ module RuboCop
229
231
  change_table_call(node) do |arg|
230
232
  if target_rails_version < 4.0
231
233
  add_offense(
232
- node, :expression,
233
- format(MSG, 'change_table')
234
+ node,
235
+ message: format(MSG, 'change_table')
234
236
  )
235
237
  elsif block.send_type?
236
238
  check_change_table_offense(arg, block)
@@ -247,8 +249,8 @@ module RuboCop
247
249
  return if receiver != node.receiver &&
248
250
  !IRREVERSIBLE_CHANGE_TABLE_CALLS.include?(method_name)
249
251
  add_offense(
250
- node, :expression,
251
- format(MSG, "change_table(with #{method_name})")
252
+ node,
253
+ message: format(MSG, "change_table(with #{method_name})")
252
254
  )
253
255
  end
254
256