rubocop 0.80.1 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/config/default.yml +202 -49
  4. data/lib/rubocop.rb +20 -61
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli.rb +13 -7
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
  8. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  9. data/lib/rubocop/comment_config.rb +1 -1
  10. data/lib/rubocop/config.rb +14 -2
  11. data/lib/rubocop/config_loader.rb +37 -33
  12. data/lib/rubocop/config_loader_resolver.rb +45 -6
  13. data/lib/rubocop/config_obsoletion.rb +2 -0
  14. data/lib/rubocop/config_store.rb +12 -2
  15. data/lib/rubocop/config_validator.rb +18 -1
  16. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  17. data/lib/rubocop/cop/badge.rb +5 -5
  18. data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
  19. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  20. data/lib/rubocop/cop/commissioner.rb +0 -21
  21. data/lib/rubocop/cop/cop.rb +14 -6
  22. data/lib/rubocop/cop/corrector.rb +48 -24
  23. data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
  24. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
  25. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
  26. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +4 -4
  27. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  28. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  29. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  30. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
  31. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  32. data/lib/rubocop/cop/generator.rb +4 -3
  33. data/lib/rubocop/cop/ignored_node.rb +1 -3
  34. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
  35. data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
  36. data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
  37. data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
  38. data/lib/rubocop/cop/layout/class_structure.rb +19 -16
  39. data/lib/rubocop/cop/layout/condition_position.rb +12 -2
  40. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  41. data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
  42. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  43. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
  44. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  45. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -3
  46. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
  47. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  48. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  49. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  50. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  51. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
  52. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -9
  53. data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
  54. data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
  55. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  56. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  57. data/lib/rubocop/cop/layout/line_length.rb +23 -20
  58. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  60. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  61. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
  62. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
  63. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  64. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +131 -0
  65. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
  66. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  67. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  68. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
  69. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  70. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
  71. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
  72. data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
  73. data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
  74. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
  75. data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
  76. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  77. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
  78. data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
  79. data/lib/rubocop/cop/lint/empty_when.rb +29 -6
  80. data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
  81. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -4
  82. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  83. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  84. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
  85. data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
  86. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  87. data/lib/rubocop/cop/lint/loop.rb +7 -5
  88. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +62 -0
  89. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
  90. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  91. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  92. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  93. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  94. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  95. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
  96. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
  97. data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
  98. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
  99. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  100. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  101. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  102. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  103. data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
  104. data/lib/rubocop/cop/lint/suppressed_exception.rb +23 -26
  105. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  106. data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
  107. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  108. data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
  109. data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
  110. data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
  111. data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
  112. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
  113. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  114. data/lib/rubocop/cop/migration/department_name.rb +22 -9
  115. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  116. data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
  117. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
  118. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  119. data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
  120. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
  121. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
  122. data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -2
  123. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  124. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
  125. data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
  126. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
  127. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
  128. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
  129. data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
  130. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  131. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
  132. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  133. data/lib/rubocop/cop/naming/constant_name.rb +2 -1
  134. data/lib/rubocop/cop/naming/file_name.rb +27 -14
  135. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  136. data/lib/rubocop/cop/naming/method_name.rb +26 -0
  137. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  138. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  139. data/lib/rubocop/cop/registry.rb +12 -7
  140. data/lib/rubocop/cop/severity.rb +1 -3
  141. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
  142. data/lib/rubocop/cop/style/alias.rb +4 -4
  143. data/lib/rubocop/cop/style/and_or.rb +7 -8
  144. data/lib/rubocop/cop/style/array_join.rb +2 -2
  145. data/lib/rubocop/cop/style/attr.rb +1 -3
  146. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  147. data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
  148. data/lib/rubocop/cop/style/case_equality.rb +24 -1
  149. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  150. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  151. data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
  152. data/lib/rubocop/cop/style/copyright.rb +3 -3
  153. data/lib/rubocop/cop/style/dir.rb +1 -1
  154. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
  155. data/lib/rubocop/cop/style/documentation.rb +43 -5
  156. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
  157. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  158. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  159. data/lib/rubocop/cop/style/each_with_object.rb +3 -3
  160. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  161. data/lib/rubocop/cop/style/empty_method.rb +2 -6
  162. data/lib/rubocop/cop/style/end_block.rb +6 -0
  163. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  164. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  165. data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
  166. data/lib/rubocop/cop/style/format_string.rb +2 -2
  167. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  168. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
  169. data/lib/rubocop/cop/style/guard_clause.rb +25 -2
  170. data/lib/rubocop/cop/style/hash_each_methods.rb +6 -4
  171. data/lib/rubocop/cop/style/hash_syntax.rb +19 -12
  172. data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
  173. data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
  174. data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
  175. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
  176. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  177. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  178. data/lib/rubocop/cop/style/lambda.rb +3 -2
  179. data/lib/rubocop/cop/style/lambda_call.rb +1 -21
  180. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  181. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  182. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  183. data/lib/rubocop/cop/style/module_function.rb +58 -12
  184. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  185. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  186. data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
  187. data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
  188. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  189. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  190. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
  191. data/lib/rubocop/cop/style/next.rb +2 -2
  192. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  193. data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
  194. data/lib/rubocop/cop/style/not.rb +1 -1
  195. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  196. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  197. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  198. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
  199. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  200. data/lib/rubocop/cop/style/or_assignment.rb +1 -1
  201. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  202. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  203. data/lib/rubocop/cop/style/proc.rb +1 -1
  204. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  205. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  206. data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
  207. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  208. data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
  209. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  210. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
  211. data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
  212. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
  213. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
  214. data/lib/rubocop/cop/style/redundant_return.rb +5 -7
  215. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  216. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  217. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  218. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  219. data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
  220. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  221. data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
  222. data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
  223. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
  224. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
  225. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  226. data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
  227. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
  228. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
  229. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
  230. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
  231. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
  232. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
  233. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  234. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  235. data/lib/rubocop/cop/style/unpack_first.rb +0 -4
  236. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  237. data/lib/rubocop/cop/style/when_then.rb +1 -1
  238. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  239. data/lib/rubocop/cop/style/word_array.rb +1 -1
  240. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
  241. data/lib/rubocop/cop/team.rb +61 -25
  242. data/lib/rubocop/cop/util.rb +25 -1
  243. data/lib/rubocop/cop/variable_force.rb +3 -9
  244. data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
  245. data/lib/rubocop/cop/variable_force/branch.rb +1 -3
  246. data/lib/rubocop/cop/variable_force/scope.rb +1 -0
  247. data/lib/rubocop/cop/variable_force/variable.rb +3 -6
  248. data/lib/rubocop/ext/processed_source.rb +18 -0
  249. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  250. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  251. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
  252. data/lib/rubocop/formatter/formatter_set.rb +1 -4
  253. data/lib/rubocop/formatter/junit_formatter.rb +27 -6
  254. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  255. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  256. data/lib/rubocop/magic_comment.rb +1 -1
  257. data/lib/rubocop/name_similarity.rb +12 -9
  258. data/lib/rubocop/options.rb +33 -12
  259. data/lib/rubocop/remote_config.rb +1 -3
  260. data/lib/rubocop/result_cache.rb +5 -7
  261. data/lib/rubocop/rspec/cop_helper.rb +3 -26
  262. data/lib/rubocop/rspec/expect_offense.rb +46 -16
  263. data/lib/rubocop/rspec/shared_contexts.rb +54 -20
  264. data/lib/rubocop/runner.rb +21 -14
  265. data/lib/rubocop/target_finder.rb +7 -7
  266. data/lib/rubocop/target_ruby.rb +5 -2
  267. data/lib/rubocop/version.rb +5 -3
  268. metadata +50 -77
  269. data/lib/rubocop/ast/builder.rb +0 -83
  270. data/lib/rubocop/ast/node.rb +0 -632
  271. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  272. data/lib/rubocop/ast/node/and_node.rb +0 -29
  273. data/lib/rubocop/ast/node/args_node.rb +0 -29
  274. data/lib/rubocop/ast/node/array_node.rb +0 -57
  275. data/lib/rubocop/ast/node/block_node.rb +0 -117
  276. data/lib/rubocop/ast/node/break_node.rb +0 -17
  277. data/lib/rubocop/ast/node/case_node.rb +0 -56
  278. data/lib/rubocop/ast/node/class_node.rb +0 -31
  279. data/lib/rubocop/ast/node/def_node.rb +0 -82
  280. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  281. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  282. data/lib/rubocop/ast/node/float_node.rb +0 -12
  283. data/lib/rubocop/ast/node/for_node.rb +0 -53
  284. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  285. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  286. data/lib/rubocop/ast/node/if_node.rb +0 -175
  287. data/lib/rubocop/ast/node/int_node.rb +0 -12
  288. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  289. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  290. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  291. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  292. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  293. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  294. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
  295. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  296. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  297. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  298. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  299. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  300. data/lib/rubocop/ast/node/module_node.rb +0 -24
  301. data/lib/rubocop/ast/node/or_node.rb +0 -29
  302. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  303. data/lib/rubocop/ast/node/range_node.rb +0 -18
  304. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  305. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  306. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  307. data/lib/rubocop/ast/node/return_node.rb +0 -24
  308. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  309. data/lib/rubocop/ast/node/send_node.rb +0 -13
  310. data/lib/rubocop/ast/node/str_node.rb +0 -16
  311. data/lib/rubocop/ast/node/super_node.rb +0 -21
  312. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  313. data/lib/rubocop/ast/node/until_node.rb +0 -35
  314. data/lib/rubocop/ast/node/when_node.rb +0 -53
  315. data/lib/rubocop/ast/node/while_node.rb +0 -35
  316. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  317. data/lib/rubocop/ast/sexp.rb +0 -16
  318. data/lib/rubocop/ast/traversal.rb +0 -200
  319. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  320. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
  321. data/lib/rubocop/node_pattern.rb +0 -887
  322. data/lib/rubocop/processed_source.rb +0 -216
  323. data/lib/rubocop/string_util.rb +0 -14
  324. data/lib/rubocop/token.rb +0 -114
@@ -104,7 +104,7 @@ module RuboCop
104
104
 
105
105
  corrected = "#{style}(#{node.receiver.source}, #{args})"
106
106
 
107
- corrector.replace(node.loc.expression, corrected)
107
+ corrector.replace(node, corrected)
108
108
  end
109
109
 
110
110
  def autocorrect_to_percent(corrector, node)
@@ -119,7 +119,7 @@ module RuboCop
119
119
  "[#{param_args.map(&:source).join(', ')}]"
120
120
  end
121
121
 
122
- corrector.replace(node.loc.expression, "#{format} % #{args}")
122
+ corrector.replace(node, "#{format} % #{args}")
123
123
  end
124
124
  end
125
125
  end
@@ -5,11 +5,10 @@ module RuboCop
5
5
  module Style
6
6
  # Use a consistent style for named format string tokens.
7
7
  #
8
- # **Note:**
9
- # `unannotated` style cop only works for strings
8
+ # NOTE: `unannotated` style cop only works for strings
10
9
  # which are passed as arguments to those methods:
11
10
  # `printf`, `sprintf`, `format`, `%`.
12
- # The reason is that *unannotated* format is very similar
11
+ # The reason is that _unannotated_ format is very similar
13
12
  # to encoded URLs or Date/Time formatting strings.
14
13
  #
15
14
  # @example EnforcedStyle: annotated (default)
@@ -8,8 +8,7 @@ module RuboCop
8
8
  # It will add the comment `# frozen_string_literal: true` to the top of
9
9
  # files to enable frozen string literals. Frozen string literals may be
10
10
  # default in future Ruby. The comment will be added below a shebang and
11
- # encoding comment. The frozen string literal comment is only valid in
12
- # Ruby 2.3+.
11
+ # encoding comment.
13
12
  #
14
13
  # Note that the cop will ignore files where the comment exists but is set
15
14
  # to `false` instead of `true`.
@@ -149,9 +148,7 @@ module RuboCop
149
148
  end
150
149
 
151
150
  next_token = processed_source.tokens[token_number]
152
- if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
153
- token = next_token
154
- end
151
+ token = next_token if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
155
152
 
156
153
  token
157
154
  end
@@ -216,7 +213,7 @@ module RuboCop
216
213
  if comment
217
214
  corrector.insert_after(line_range(comment.line), following_comment)
218
215
  else
219
- corrector.insert_before(line_range(1), preceding_comment)
216
+ corrector.insert_before(processed_source.buffer.source_range, preceding_comment)
220
217
  end
221
218
  end
222
219
 
@@ -35,6 +35,17 @@ module RuboCop
35
35
  # # good
36
36
  # raise 'exception' if something
37
37
  # ok
38
+ #
39
+ # # bad
40
+ # if something
41
+ # foo || raise('exception')
42
+ # else
43
+ # ok
44
+ # end
45
+ #
46
+ # # good
47
+ # foo || raise('exception') if something
48
+ # ok
38
49
  class GuardClause < Cop
39
50
  include MinBodyLength
40
51
  include StatementModifier
@@ -69,7 +80,8 @@ module RuboCop
69
80
  else
70
81
  opposite_keyword(node)
71
82
  end
72
- register_offense(node, guard_clause.source, kw)
83
+
84
+ register_offense(node, guard_clause_source(guard_clause), kw)
73
85
  end
74
86
 
75
87
  private
@@ -98,13 +110,24 @@ module RuboCop
98
110
  message: format(MSG, example: example))
99
111
  end
100
112
 
113
+ def guard_clause_source(guard_clause)
114
+ parent = guard_clause.parent
115
+
116
+ if parent.and_type? || parent.or_type?
117
+ guard_clause.parent.source
118
+ else
119
+ guard_clause.source
120
+ end
121
+ end
122
+
101
123
  def too_long_for_single_line?(node, example)
102
124
  max = max_line_length
103
125
  max && node.source_range.column + example.length > max
104
126
  end
105
127
 
106
128
  def accepted_form?(node, ending = false)
107
- accepted_if?(node, ending) || node.condition.multiline?
129
+ accepted_if?(node, ending) || node.condition.multiline? ||
130
+ node.parent&.assignment?
108
131
  end
109
132
 
110
133
  def accepted_if?(node, ending)
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Style
6
6
  # This cop checks for uses of `each_key` and `each_value` Hash methods.
7
7
  #
8
- # Note: If you have an array of two-element arrays, you can put
8
+ # NOTE: If you have an array of two-element arrays, you can put
9
9
  # parentheses around the block arguments to indicate that you're not
10
10
  # working with a hash, and suppress RuboCop offenses.
11
11
  #
@@ -40,6 +40,8 @@ module RuboCop
40
40
 
41
41
  def register_kv_offense(node)
42
42
  kv_each(node) do |target, method|
43
+ return unless target.receiver.receiver
44
+
43
45
  msg = format(message, prefer: "each_#{method[0..-2]}",
44
46
  current: "#{method}.each")
45
47
 
@@ -58,7 +60,7 @@ module RuboCop
58
60
  end
59
61
 
60
62
  def correct_implicit(node, corrector, method_name)
61
- corrector.replace(node.loc.expression, method_name)
63
+ corrector.replace(node, method_name)
62
64
  correct_args(node, corrector)
63
65
  end
64
66
 
@@ -68,14 +70,14 @@ module RuboCop
68
70
  return correct_implicit(node, corrector, name) unless receiver
69
71
 
70
72
  new_source = receiver.source + ".#{name}"
71
- corrector.replace(node.loc.expression, new_source)
73
+ corrector.replace(node, new_source)
72
74
  end
73
75
 
74
76
  def correct_args(node, corrector)
75
77
  args = node.parent.arguments
76
78
  name, = *args.children.find { |arg| used?(arg) }
77
79
 
78
- corrector.replace(args.source_range, "|#{name}|")
80
+ corrector.replace(args, "|#{name}|")
79
81
  end
80
82
 
81
83
  def kv_range(outer_node)
@@ -13,11 +13,11 @@ module RuboCop
13
13
  # The supported styles are:
14
14
  #
15
15
  # * ruby19 - forces use of the 1.9 syntax (e.g. `{a: 1}`) when hashes have
16
- # all symbols for keys
16
+ # all symbols for keys
17
17
  # * hash_rockets - forces use of hash rockets for all hashes
18
18
  # * no_mixed_keys - simply checks for hashes with mixed syntaxes
19
19
  # * ruby19_no_mixed_keys - forces use of ruby 1.9 syntax and forbids mixed
20
- # syntax hashes
20
+ # syntax hashes
21
21
  #
22
22
  # @example EnforcedStyle: ruby19 (default)
23
23
  # # bad
@@ -144,11 +144,11 @@ module RuboCop
144
144
  # Prefer { :production? => false } over { production?: false } and
145
145
  # similarly for other non-alnum final characters (except quotes,
146
146
  # to prefer { "x y": 1 } over { :"x y" => 1 }).
147
- return false unless sym_name =~ /[\p{Alnum}"']\z/
147
+ return false unless /[\p{Alnum}"']\z/.match?(sym_name)
148
148
  end
149
149
 
150
150
  # Most hash keys can be matched against a simple regex.
151
- return true if sym_name =~ /\A[_a-z]\w*[?!]?\z/i
151
+ return true if /\A[_a-z]\w*[?!]?\z/i.match?(sym_name)
152
152
 
153
153
  # For more complicated hash keys, let the parser validate the syntax.
154
154
  parse("{ #{sym_name}: :foo }").valid_syntax?
@@ -168,11 +168,7 @@ module RuboCop
168
168
  end
169
169
 
170
170
  def autocorrect_ruby19(corrector, pair_node)
171
- key = pair_node.key.source_range
172
- op = pair_node.loc.operator
173
-
174
- range = key.join(op)
175
- range = range_with_surrounding_space(range: range, side: :right)
171
+ range = range_for_autocorrect_ruby19(pair_node)
176
172
 
177
173
  space = argument_without_space?(pair_node.parent) ? ' ' : ''
178
174
 
@@ -180,6 +176,19 @@ module RuboCop
180
176
  range,
181
177
  range.source.sub(/^:(.*\S)\s*=>\s*$/, space.to_s + '\1: ')
182
178
  )
179
+
180
+ hash_node = pair_node.parent
181
+ return unless hash_node.parent&.return_type? && !hash_node.braces?
182
+
183
+ corrector.wrap(hash_node, '{', '}')
184
+ end
185
+
186
+ def range_for_autocorrect_ruby19(pair_node)
187
+ key = pair_node.key.source_range
188
+ operator = pair_node.loc.operator
189
+
190
+ range = key.join(operator)
191
+ range_with_surrounding_space(range: range, side: :right)
183
192
  end
184
193
 
185
194
  def argument_without_space?(node)
@@ -188,11 +197,9 @@ module RuboCop
188
197
  end
189
198
 
190
199
  def autocorrect_hash_rockets(corrector, pair_node)
191
- key = pair_node.key.source_range
192
200
  op = pair_node.loc.operator
193
201
 
194
- corrector.insert_after(key, pair_node.inverse_delimiter(true))
195
- corrector.insert_before(key, ':')
202
+ corrector.wrap(pair_node.key, ':', pair_node.inverse_delimiter(true))
196
203
  corrector.remove(range_with_surrounding_space(range: op))
197
204
  end
198
205
 
@@ -31,7 +31,9 @@ module RuboCop
31
31
 
32
32
  def_node_matcher :on_bad_each_with_object, <<~PATTERN
33
33
  (block
34
- ({send csend} !(send _ :each_with_index) :each_with_object (hash))
34
+ ({send csend}
35
+ !{(send _ :each_with_index) (array ...)}
36
+ :each_with_object (hash))
35
37
  (args
36
38
  (mlhs
37
39
  (arg $_)
@@ -55,7 +57,9 @@ module RuboCop
55
57
  def_node_matcher :on_bad_map_to_h, <<~PATTERN
56
58
  ({send csend}
57
59
  (block
58
- ({send csend} !(send _ :each_with_index) {:map :collect})
60
+ ({send csend}
61
+ !{(send _ :each_with_index) (array ...)}
62
+ {:map :collect})
59
63
  (args
60
64
  (arg $_)
61
65
  (arg _val))
@@ -24,14 +24,13 @@ module RuboCop
24
24
  # {a: 1, b: 2}.transform_values { |v| foo(v) }
25
25
  # {a: 1, b: 2}.transform_values { |v| v * v }
26
26
  class HashTransformValues < Cop
27
- extend TargetRubyVersion
28
27
  include HashTransformMethod
29
28
 
30
- minimum_target_ruby_version 2.4
31
-
32
29
  def_node_matcher :on_bad_each_with_object, <<~PATTERN
33
30
  (block
34
- ({send csend} !(send _ :each_with_index) :each_with_object (hash))
31
+ ({send csend}
32
+ !{(send _ :each_with_index) (array ...)}
33
+ :each_with_object (hash))
35
34
  (args
36
35
  (mlhs
37
36
  (arg _key)
@@ -55,7 +54,9 @@ module RuboCop
55
54
  def_node_matcher :on_bad_map_to_h, <<~PATTERN
56
55
  ({send csend}
57
56
  (block
58
- ({send csend} !(send _ :each_with_index) {:map :collect})
57
+ ({send csend}
58
+ !{(send _ :each_with_index) (array ...)}
59
+ {:map :collect})
59
60
  (args
60
61
  (arg _key)
61
62
  (arg $_))
@@ -9,7 +9,7 @@ module RuboCop
9
9
  #
10
10
  # The maximum line length is configured in the `Layout/LineLength`
11
11
  # cop. The tab size is configured in the `IndentationWidth` of the
12
- # `Layout/Tab` cop.
12
+ # `Layout/IndentationStyle` cop.
13
13
  #
14
14
  # @example
15
15
  # # bad
@@ -47,7 +47,7 @@ module RuboCop
47
47
  def on_if(node)
48
48
  msg = if eligible_node?(node)
49
49
  MSG_USE_MODIFIER unless named_capture_in_condition?(node)
50
- elsif node.modifier_form? && too_long_single_line?(node)
50
+ elsif too_long_due_to_modifier?(node)
51
51
  MSG_USE_NORMAL
52
52
  end
53
53
  return unless msg
@@ -63,11 +63,16 @@ module RuboCop
63
63
  else
64
64
  to_modifier_form(node)
65
65
  end
66
- ->(corrector) { corrector.replace(node.source_range, replacement) }
66
+ ->(corrector) { corrector.replace(node, replacement) }
67
67
  end
68
68
 
69
69
  private
70
70
 
71
+ def too_long_due_to_modifier?(node)
72
+ node.modifier_form? && too_long_single_line?(node) &&
73
+ !another_statement_on_same_line?(node)
74
+ end
75
+
71
76
  def ignored_patterns
72
77
  config.for_cop('Layout/LineLength')['IgnoredPatterns'] || []
73
78
  end
@@ -129,6 +134,21 @@ module RuboCop
129
134
  node.ternary? || node.modifier_form? || node.elsif? || node.else?
130
135
  end
131
136
 
137
+ def another_statement_on_same_line?(node)
138
+ line_no = node.source_range.last_line
139
+
140
+ # traverse the AST upwards until we find a 'begin' node
141
+ # we want to look at the following child and see if it is on the
142
+ # same line as this 'if' node
143
+ while node && !node.begin_type?
144
+ index = node.sibling_index
145
+ node = node.parent
146
+ end
147
+
148
+ node && (sibling = node.children[index + 1]) &&
149
+ sibling.source_range.first_line == line_no
150
+ end
151
+
132
152
  def parenthesize?(node)
133
153
  # Parenthesize corrected expression if changing to modifier-if form
134
154
  # would change the meaning of the parent expression
@@ -19,11 +19,27 @@ module RuboCop
19
19
  MSG = 'Do not use if x; Use the ternary operator instead.'
20
20
 
21
21
  def on_normal_if_unless(node)
22
+ return unless node.else_branch
23
+
22
24
  beginning = node.loc.begin
23
25
  return unless beginning&.is?(';')
24
26
 
25
27
  add_offense(node)
26
28
  end
29
+
30
+ def autocorrect(node)
31
+ lambda do |corrector|
32
+ corrector.replace(node, correct_to_ternary(node))
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def correct_to_ternary(node)
39
+ else_code = node.else_branch ? node.else_branch.source : 'nil'
40
+
41
+ "#{node.condition.source} ? #{node.if_branch.source} : #{else_code}"
42
+ end
27
43
  end
28
44
  end
29
45
  end
@@ -23,7 +23,7 @@ module RuboCop
23
23
  def investigate(processed_source)
24
24
  processed_source.each_comment do |comment|
25
25
  next if comment_line?(processed_source[comment.loc.line - 1]) ||
26
- comment.text.match(/\A# rubocop:(enable|disable)/)
26
+ comment.text.match?(/\A# rubocop:(enable|disable)/)
27
27
 
28
28
  add_offense(comment)
29
29
  end
@@ -44,7 +44,7 @@ module RuboCop
44
44
  CAMEL_CASE = /[A-Z]+[a-z]+/.freeze
45
45
 
46
46
  def self.autocorrect_incompatible_with
47
- [Style::Not]
47
+ [Style::Not, Style::SymbolProc]
48
48
  end
49
49
 
50
50
  def_node_matcher :inverse_candidate?, <<~PATTERN
@@ -73,6 +73,7 @@ module RuboCop
73
73
  location: node.send_node.source_range,
74
74
  message: message(node, selector))
75
75
  end
76
+ alias on_numblock on_block
76
77
 
77
78
  def autocorrect(node)
78
79
  if node.send_node.source == 'lambda'
@@ -108,13 +109,13 @@ module RuboCop
108
109
  end
109
110
 
110
111
  def autocorrect_method_to_literal(corrector, node)
111
- corrector.replace(node.send_node.source_range, '->')
112
+ corrector.replace(node.send_node, '->')
112
113
 
113
114
  return unless node.arguments?
114
115
 
115
116
  arg_str = "(#{lambda_arg_string(node.arguments)})"
116
117
 
117
- corrector.insert_after(node.send_node.source_range, arg_str)
118
+ corrector.insert_after(node.send_node, arg_str)
118
119
  corrector.remove(arguments_with_whitespace(node))
119
120
  end
120
121
 
@@ -37,7 +37,7 @@ module RuboCop
37
37
  receiver = node.receiver.source
38
38
  replacement = node.source.sub("#{receiver}.", "#{receiver}.call")
39
39
 
40
- corrector.replace(node.source_range, replacement)
40
+ corrector.replace(node, replacement)
41
41
  else
42
42
  add_parentheses(node, corrector) unless node.parenthesized?
43
43
  corrector.remove(node.loc.selector)
@@ -52,26 +52,6 @@ module RuboCop
52
52
  implicit_style? && !node.implicit_call?
53
53
  end
54
54
 
55
- def add_parentheses(node, corrector)
56
- if node.arguments.empty?
57
- corrector.insert_after(node.source_range, '()')
58
- else
59
- corrector.replace(args_begin(node), '(')
60
- corrector.insert_after(args_end(node), ')')
61
- end
62
- end
63
-
64
- def args_begin(node)
65
- loc = node.loc
66
- selector =
67
- node.super_type? || node.yield_type? ? loc.keyword : loc.selector
68
- selector.end.resize(1)
69
- end
70
-
71
- def args_end(node)
72
- node.loc.expression.end
73
- end
74
-
75
55
  def message(_node)
76
56
  if explicit_style?
77
57
  'Prefer the use of `lambda.call(...)` over `lambda.(...)`.'