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
@@ -285,8 +285,8 @@ module RuboCop
285
285
  def_node_matcher :defined_module0, <<-PATTERN
286
286
  {(class (const $_ $_) ...)
287
287
  (module (const $_ $_) ...)
288
- (casgn $_ $_ (send (const nil {:Class :Module}) :new ...))
289
- (casgn $_ $_ (block (send (const nil {:Class :Module}) :new ...) ...))}
288
+ (casgn $_ $_ (send (const nil? {:Class :Module}) :new ...))
289
+ (casgn $_ $_ (block (send (const nil? {:Class :Module}) :new ...) ...))}
290
290
  PATTERN
291
291
  private :defined_module0
292
292
 
@@ -439,21 +439,21 @@ module RuboCop
439
439
  end
440
440
 
441
441
  def_node_matcher :guard_clause?, <<-PATTERN
442
- [{(send nil {:raise :fail} ...) return break next} single_line?]
442
+ [{(send nil? {:raise :fail} ...) return break next} single_line?]
443
443
  PATTERN
444
444
 
445
445
  def_node_matcher :proc?, <<-PATTERN
446
- {(block (send nil :proc) ...)
447
- (block (send (const nil :Proc) :new) ...)
448
- (send (const nil :Proc) :new)}
446
+ {(block (send nil? :proc) ...)
447
+ (block (send (const nil? :Proc) :new) ...)
448
+ (send (const nil? :Proc) :new)}
449
449
  PATTERN
450
450
 
451
- def_node_matcher :lambda?, '(block (send nil :lambda) ...)'
451
+ def_node_matcher :lambda?, '(block (send nil? :lambda) ...)'
452
452
  def_node_matcher :lambda_or_proc?, '{lambda? proc?}'
453
453
 
454
454
  def_node_matcher :class_constructor?, <<-PATTERN
455
- { (send (const nil {:Class :Module}) :new ...)
456
- (block (send (const nil {:Class :Module}) :new ...) ...)}
455
+ { (send (const nil? {:Class :Module}) :new ...)
456
+ (block (send (const nil? {:Class :Module}) :new ...) ...)}
457
457
  PATTERN
458
458
 
459
459
  def_node_matcher :module_definition?, <<-PATTERN
@@ -163,11 +163,11 @@ module RuboCop
163
163
  end
164
164
 
165
165
  def_node_matcher :adjacent_def_modifier?, <<-PATTERN
166
- (send nil _ ({def defs} ...))
166
+ (send nil? _ ({def defs} ...))
167
167
  PATTERN
168
168
 
169
169
  def_node_matcher :bare_access_modifier?, <<-PATTERN
170
- (send nil {:public :protected :private :module_function})
170
+ (send nil? {:public :protected :private :module_function})
171
171
  PATTERN
172
172
  end
173
173
  end
@@ -16,6 +16,10 @@ module RuboCop
16
16
  def node_parts
17
17
  to_a
18
18
  end
19
+
20
+ def negation_method?
21
+ keyword_bang? || keyword_not?
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -38,12 +38,7 @@ module RuboCop
38
38
  def message(offense)
39
39
  # JSON.dump will fail if the offense message contains text which is not
40
40
  # valid UTF-8
41
- message = offense.message
42
- if message.respond_to?(:scrub)
43
- message.scrub
44
- else
45
- message.chars.select(&:valid_encoding?).join
46
- end
41
+ offense.message.scrub
47
42
  end
48
43
 
49
44
  # Restore an offense object loaded from a JSON file.
@@ -31,13 +31,13 @@ module RuboCop
31
31
 
32
32
  execute_runner(paths)
33
33
  rescue RuboCop::Error => e
34
- $stderr.puts Rainbow("Error: #{e.message}").red
34
+ warn Rainbow("Error: #{e.message}").red
35
35
  return 2
36
36
  rescue Finished
37
37
  return 0
38
- rescue StandardError, SyntaxError => e
39
- $stderr.puts e.message
40
- $stderr.puts e.backtrace
38
+ rescue StandardError, SyntaxError, LoadError => e
39
+ warn e.message
40
+ warn e.backtrace
41
41
  return 2
42
42
  end
43
43
 
@@ -45,8 +45,8 @@ module RuboCop
45
45
  Signal.trap('INT') do
46
46
  exit!(1) if runner.aborting?
47
47
  runner.abort
48
- $stderr.puts
49
- $stderr.puts 'Exiting... Interrupt again to exit immediately.'
48
+ warn
49
+ warn 'Exiting... Interrupt again to exit immediately.'
50
50
  end
51
51
  end
52
52
 
@@ -66,6 +66,7 @@ module RuboCop
66
66
 
67
67
  ConfigLoader.debug = @options[:debug]
68
68
  ConfigLoader.auto_gen_config = @options[:auto_gen_config]
69
+ ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
69
70
 
70
71
  @config_store.options_config = @options[:config] if @options[:config]
71
72
  @config_store.force_default_config! if @options[:force_default_config]
@@ -17,7 +17,8 @@ module RuboCop
17
17
  AutoCorrect StyleGuide Details].freeze
18
18
  # 2.1 is the oldest officially supported Ruby version.
19
19
  DEFAULT_RUBY_VERSION = 2.1
20
- KNOWN_RUBIES = [1.9, 2.0, 2.1, 2.2, 2.3, 2.4].freeze
20
+ KNOWN_RUBIES = [2.1, 2.2, 2.3, 2.4].freeze
21
+ OBSOLETE_RUBIES = { 1.9 => '0.50', 2.0 => '0.50' }.freeze
21
22
  DEFAULT_RAILS_VERSION = 5.0
22
23
  OBSOLETE_COPS = {
23
24
  'Style/TrailingComma' =>
@@ -26,6 +27,9 @@ module RuboCop
26
27
  '`Style/TrailingCommaInArguments` instead.',
27
28
  'Rails/DefaultScope' =>
28
29
  'The `Rails/DefaultScope` cop no longer exists.',
30
+ 'Lint/InvalidCharacterLiteral' =>
31
+ 'The `Lint/InvalidCharacterLiteral` cop has been removed since it ' \
32
+ 'was never being actually triggered.',
29
33
  'Style/SingleSpaceBeforeFirstArg' =>
30
34
  'The `Style/SingleSpaceBeforeFirstArg` cop has been renamed to ' \
31
35
  '`Layout/SpaceBeforeFirstArg`.',
@@ -60,8 +64,8 @@ module RuboCop
60
64
  'The `Style/AsciiIdentifiers` cop has been moved to ' \
61
65
  '`Naming/AccessorMethodName`.',
62
66
  'Style/OpMethod' =>
63
- 'The `Style/OpMethods` cop has been renamed and moved to ' \
64
- '`Naming/BinaryOperatorParameter`.',
67
+ 'The `Style/OpMethod` cop has been renamed and moved to ' \
68
+ '`Naming/BinaryOperatorParameterName`.',
65
69
  'Style/ClassAndModuleCamelCase' =>
66
70
  'The `Style/ClassAndModuleCamelCase` cop has been renamed to ' \
67
71
  '`Naming/ClassAndModuleCamelCase`.',
@@ -92,6 +96,24 @@ module RuboCop
92
96
  'for alignment, please use AllowForAlignment: ' \
93
97
  'true instead.'
94
98
  },
99
+ {
100
+ cop: 'Style/Encoding',
101
+ parameter: 'EnforcedStyle',
102
+ alternative: 'Style/Encoding no longer supports styles. ' \
103
+ 'The "never" behavior is always assumed.'
104
+ },
105
+ {
106
+ cop: 'Style/Encoding',
107
+ parameter: 'SupportedStyles',
108
+ alternative: 'Style/Encoding no longer supports styles. ' \
109
+ 'The "never" behavior is always assumed.'
110
+ },
111
+ {
112
+ cop: 'Style/Encoding',
113
+ parameter: 'AutoCorrectEncodingComment',
114
+ alternative: 'Style/Encoding no longer supports styles. ' \
115
+ 'The "never" behavior is always assumed.'
116
+ },
95
117
  {
96
118
  cop: 'Style/SpaceAroundOperators',
97
119
  parameter: 'MultiSpaceAllowedForOperators',
@@ -355,7 +377,7 @@ module RuboCop
355
377
  next if Cop::Cop.registry.contains_cop_matching?([name])
356
378
 
357
379
  warn Rainbow("Warning: unrecognized cop #{name} found in " \
358
- "#{loaded_path}").yellow
380
+ "#{smart_loaded_path}").yellow
359
381
  end
360
382
  end
361
383
 
@@ -364,13 +386,14 @@ module RuboCop
364
386
  valid_cop_names.include?('Syntax')
365
387
 
366
388
  raise ValidationError,
367
- "configuration for Syntax cop found in #{loaded_path}\n" \
389
+ "configuration for Syntax cop found in #{smart_loaded_path}\n" \
368
390
  'This cop cannot be configured.'
369
391
  end
370
392
 
371
393
  def validate_section_presence(name)
372
394
  return unless key?(name) && self[name].nil?
373
- raise ValidationError, "empty section #{name} found in #{loaded_path}"
395
+ raise ValidationError,
396
+ "empty section #{name} found in #{smart_loaded_path}"
374
397
  end
375
398
 
376
399
  def validate_parameter_names(valid_cop_names)
@@ -381,7 +404,7 @@ module RuboCop
381
404
  ConfigLoader.default_configuration[name].key?(param)
382
405
 
383
406
  warn Rainbow("Warning: unrecognized parameter #{name}:#{param} " \
384
- "found in #{loaded_path}").yellow
407
+ "found in #{smart_loaded_path}").yellow
385
408
  end
386
409
  end
387
410
  end
@@ -397,7 +420,7 @@ module RuboCop
397
420
  next if valid.include?(style)
398
421
 
399
422
  msg = "invalid #{style_name} '#{style}' for #{name} found in " \
400
- "#{loaded_path}\n" \
423
+ "#{smart_loaded_path}\n" \
401
424
  "Valid choices are: #{valid.join(', ')}"
402
425
  raise ValidationError, msg
403
426
  end
@@ -425,36 +448,45 @@ module RuboCop
425
448
  return unless self[cop] && self[cop].key?(parameter)
426
449
 
427
450
  "obsolete parameter #{parameter} (for #{cop}) " \
428
- "found in #{loaded_path}" \
451
+ "found in #{smart_loaded_path}" \
429
452
  "\n#{alternative}"
430
453
  end
431
454
 
432
455
  def obsolete_cops
433
456
  OBSOLETE_COPS.map do |cop_name, message|
434
457
  next unless key?(cop_name) || key?(Cop::Badge.parse(cop_name).cop_name)
435
- message + "\n(obsolete configuration found in #{loaded_path}, please" \
436
- ' update it)'
458
+ message + "\n(obsolete configuration found in #{smart_loaded_path}," \
459
+ ' please update it)'
437
460
  end
438
461
  end
439
462
 
440
463
  def check_target_ruby
441
464
  return if KNOWN_RUBIES.include?(target_ruby_version)
442
465
 
443
- msg = "Unknown Ruby version #{target_ruby_version.inspect} found "
466
+ msg = if OBSOLETE_RUBIES.include?(target_ruby_version)
467
+ "Unsupported Ruby version #{target_ruby_version} found in " \
468
+ "#{target_ruby_source}. #{target_ruby_version}-compatible " \
469
+ 'analysis was dropped after version ' \
470
+ "#{OBSOLETE_RUBIES[target_ruby_version]}."
471
+ else
472
+ "Unknown Ruby version #{target_ruby_version.inspect} found in " \
473
+ "#{target_ruby_source}."
474
+ end
444
475
 
445
- msg +=
446
- case @target_ruby_version_source
447
- when :dot_ruby_version
448
- 'in `.ruby-version`.'
449
- when :rubocop_yml
450
- "in `TargetRubyVersion` parameter (in #{loaded_path})." \
451
- end
452
-
453
- msg += "\nKnown versions: #{KNOWN_RUBIES.join(', ')}"
476
+ msg += "\nSupported versions: #{KNOWN_RUBIES.join(', ')}"
454
477
 
455
478
  raise ValidationError, msg
456
479
  end
457
480
 
481
+ def target_ruby_source
482
+ case @target_ruby_version_source
483
+ when :dot_ruby_version
484
+ '`.ruby-version`'
485
+ when :rubocop_yml
486
+ "`TargetRubyVersion` parameter (in #{smart_loaded_path})"
487
+ end
488
+ end
489
+
458
490
  def reject_mutually_exclusive_defaults
459
491
  disabled_by_default = for_all_cops['DisabledByDefault']
460
492
  enabled_by_default = for_all_cops['EnabledByDefault']
@@ -470,12 +502,16 @@ module RuboCop
470
502
 
471
503
  unless department
472
504
  department_options = self[cop_department]
473
- if department_options && department_options.fetch('Enabled') == false
505
+ if department_options && department_options['Enabled'] == false
474
506
  return false
475
507
  end
476
508
  end
477
509
 
478
510
  cop_options.fetch('Enabled', true)
479
511
  end
512
+
513
+ def smart_loaded_path
514
+ PathUtil.smart_path(@loaded_path)
515
+ end
480
516
  end
481
517
  end
@@ -18,19 +18,24 @@ module RuboCop
18
18
  class << self
19
19
  include ConfigLoaderResolver
20
20
 
21
- attr_accessor :debug, :auto_gen_config
21
+ attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion
22
22
  attr_writer :root_level # The upwards search is stopped at this level.
23
23
  attr_writer :default_configuration
24
24
 
25
25
  alias debug? debug
26
26
  alias auto_gen_config? auto_gen_config
27
+ alias ignore_parent_exclusion? ignore_parent_exclusion
27
28
 
28
29
  def clear_options
29
30
  @debug = @auto_gen_config = @root_level = nil
30
31
  end
31
32
 
32
- def load_file(path)
33
- path = File.absolute_path(path)
33
+ def load_file(file)
34
+ return if file.nil?
35
+ path = File.absolute_path(
36
+ file.is_a?(RemoteConfig) ? file.file : file
37
+ )
38
+
34
39
  hash = load_yaml_configuration(path)
35
40
 
36
41
  # Resolve requires first in case they define additional cops
@@ -40,7 +45,7 @@ module RuboCop
40
45
  target_ruby_version_to_f!(hash)
41
46
 
42
47
  resolve_inheritance_from_gems(hash, hash.delete('inherit_gem'))
43
- resolve_inheritance(path, hash)
48
+ resolve_inheritance(path, hash, file)
44
49
 
45
50
  hash.delete('inherit_from')
46
51
 
@@ -83,25 +88,29 @@ module RuboCop
83
88
  result
84
89
  end
85
90
 
86
- def base_configs(path, inherit_from)
91
+ def base_configs(path, inherit_from, file)
87
92
  configs = Array(inherit_from).compact.map do |f|
88
- if f =~ /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/
89
- f = RemoteConfig.new(f, File.dirname(path)).file
90
- else
91
- f = File.expand_path(f, File.dirname(path))
92
-
93
- if auto_gen_config?
94
- next if f.include?(AUTO_GENERATED_FILE)
95
- end
96
-
97
- print 'Inheriting ' if debug?
98
- end
99
- load_file(f)
93
+ load_file(inherited_file(path, f, file))
100
94
  end
101
95
 
102
96
  configs.compact
103
97
  end
104
98
 
99
+ def inherited_file(path, inherit_from, file)
100
+ regex = URI::DEFAULT_PARSER.make_regexp(%w[http https])
101
+ if inherit_from =~ /\A#{regex}\z/
102
+ f = RemoteConfig.new(inherit_from, File.dirname(path))
103
+ elsif file.is_a?(RemoteConfig)
104
+ f = file.inherit_from_remote(inherit_from, path)
105
+ else
106
+ f = File.expand_path(inherit_from, File.dirname(path))
107
+
108
+ return if auto_gen_config? && f.include?(AUTO_GENERATED_FILE)
109
+ print 'Inheriting ' if debug?
110
+ end
111
+ f
112
+ end
113
+
105
114
  # Returns the path of .rubocop.yml searching upwards in the
106
115
  # directory structure starting at the given directory where the
107
116
  # inspected file is. If no .rubocop.yml is found there, the
@@ -115,14 +124,21 @@ module RuboCop
115
124
  config = load_file(config_file)
116
125
  return config if config_file == DEFAULT_FILE
117
126
 
118
- found_files = config_files_in_path(config_file)
119
- if found_files.any? && found_files.last != config_file
120
- print 'AllCops/Exclude ' if debug?
121
- config.add_excludes_from_higher_level(load_file(found_files.last))
127
+ if ignore_parent_exclusion?
128
+ print 'Ignoring AllCops/Exclude from parent folders' if debug?
129
+ else
130
+ add_excludes_from_files(config, config_file)
122
131
  end
123
132
  merge_with_default(config, config_file)
124
133
  end
125
134
 
135
+ def add_excludes_from_files(config, config_file)
136
+ found_files = config_files_in_path(config_file)
137
+ return unless found_files.any? && found_files.last != config_file
138
+ print 'AllCops/Exclude ' if debug?
139
+ config.add_excludes_from_higher_level(load_file(found_files.last))
140
+ end
141
+
126
142
  def default_configuration
127
143
  @default_configuration ||= begin
128
144
  print 'Default ' if debug?
@@ -17,8 +17,9 @@ module RuboCop
17
17
  end
18
18
  end
19
19
 
20
- def resolve_inheritance(path, hash)
21
- base_configs(path, hash['inherit_from']).reverse_each do |base_config|
20
+ def resolve_inheritance(path, hash, file)
21
+ base_configs(path, hash['inherit_from'], file)
22
+ .reverse_each do |base_config|
22
23
  base_config.each do |k, v|
23
24
  hash[k] = hash.key?(k) ? merge(v, hash[k]) : v if v.is_a?(Hash)
24
25
  end
@@ -45,7 +45,7 @@ module RuboCop
45
45
 
46
46
  private
47
47
 
48
- def_node_search :gem_declarations, '(send nil :gem str ...)'
48
+ def_node_search :gem_declarations, '(send nil? :gem str ...)'
49
49
 
50
50
  def duplicated_gem_nodes
51
51
  gem_declarations(processed_source.ast)
@@ -56,11 +56,13 @@ module RuboCop
56
56
 
57
57
  def register_offense(node, gem_name, line_of_first_occurrence)
58
58
  line_range = node.loc.column...node.loc.last_column
59
+ offense_location =
60
+ source_range(processed_source.buffer, node.loc.line, line_range)
59
61
 
60
62
  add_offense(
61
63
  node,
62
- source_range(processed_source.buffer, node.loc.line, line_range),
63
- format(MSG, gem_name, line_of_first_occurrence)
64
+ location: offense_location,
65
+ message: format(MSG, gem_name, line_of_first_occurrence)
64
66
  )
65
67
  end
66
68
  end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  "if possible, or 'http://rubygems.org' if not.".freeze
32
32
 
33
33
  def_node_matcher :insecure_protocol_source?, <<-PATTERN
34
- (send nil :source
34
+ (send nil? :source
35
35
  (sym ${:gemcutter :rubygems :rubyforge}))
36
36
  PATTERN
37
37
 
@@ -40,7 +40,9 @@ module RuboCop
40
40
  message = format(MSG, source)
41
41
 
42
42
  add_offense(
43
- node, source_range(node.first_argument.loc.expression), message
43
+ node,
44
+ location: source_range(node.first_argument.loc.expression),
45
+ message: message
44
46
  )
45
47
  end
46
48
  end