rubocop 0.35.1 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (385) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +164 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +72 -21
  5. data/bin/rubocop +1 -0
  6. data/config/default.yml +167 -18
  7. data/config/disabled.yml +19 -6
  8. data/config/enabled.yml +159 -14
  9. data/lib/rubocop.rb +67 -26
  10. data/lib/rubocop/ast_node.rb +488 -14
  11. data/lib/rubocop/ast_node/builder.rb +24 -0
  12. data/lib/rubocop/ast_node/sexp.rb +13 -0
  13. data/lib/rubocop/cached_data.rb +58 -0
  14. data/lib/rubocop/cli.rb +47 -10
  15. data/lib/rubocop/comment_config.rb +9 -2
  16. data/lib/rubocop/config.rb +99 -31
  17. data/lib/rubocop/config_loader.rb +23 -14
  18. data/lib/rubocop/config_store.rb +1 -0
  19. data/lib/rubocop/cop/autocorrect_logic.rb +2 -1
  20. data/lib/rubocop/cop/commissioner.rb +3 -5
  21. data/lib/rubocop/cop/cop.rb +23 -17
  22. data/lib/rubocop/cop/corrector.rb +25 -0
  23. data/lib/rubocop/cop/force.rb +1 -0
  24. data/lib/rubocop/cop/ignored_node.rb +3 -2
  25. data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -1
  26. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
  27. data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -3
  28. data/lib/rubocop/cop/lint/block_alignment.rb +29 -91
  29. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -1
  30. data/lib/rubocop/cop/lint/condition_position.rb +2 -1
  31. data/lib/rubocop/cop/lint/debugger.rb +29 -12
  32. data/lib/rubocop/cop/lint/def_end_alignment.rb +16 -18
  33. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +6 -6
  34. data/lib/rubocop/cop/lint/duplicate_methods.rb +98 -74
  35. data/lib/rubocop/cop/lint/duplicated_key.rb +3 -2
  36. data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -2
  37. data/lib/rubocop/cop/lint/else_layout.rb +2 -1
  38. data/lib/rubocop/cop/lint/empty_ensure.rb +2 -1
  39. data/lib/rubocop/cop/lint/empty_interpolation.rb +2 -1
  40. data/lib/rubocop/cop/lint/end_alignment.rb +77 -39
  41. data/lib/rubocop/cop/lint/end_in_method.rb +2 -1
  42. data/lib/rubocop/cop/lint/ensure_return.rb +2 -1
  43. data/lib/rubocop/cop/lint/eval.rb +2 -1
  44. data/lib/rubocop/cop/lint/float_out_of_range.rb +31 -0
  45. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -30
  46. data/lib/rubocop/cop/lint/handle_exceptions.rb +2 -1
  47. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +85 -0
  48. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +120 -0
  49. data/lib/rubocop/cop/lint/invalid_character_literal.rb +3 -1
  50. data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -9
  51. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +6 -9
  52. data/lib/rubocop/cop/lint/loop.rb +2 -1
  53. data/lib/rubocop/cop/lint/nested_method_definition.rb +19 -3
  54. data/lib/rubocop/cop/lint/next_without_accumulator.rb +38 -0
  55. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +5 -8
  56. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -6
  57. data/lib/rubocop/cop/lint/rand_one.rb +36 -0
  58. data/lib/rubocop/cop/lint/require_parentheses.rb +6 -5
  59. data/lib/rubocop/cop/lint/rescue_exception.rb +3 -2
  60. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -1
  61. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -4
  62. data/lib/rubocop/cop/lint/syntax.rb +9 -5
  63. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +3 -2
  64. data/lib/rubocop/cop/lint/unneeded_disable.rb +121 -18
  65. data/lib/rubocop/cop/lint/unreachable_code.rb +5 -4
  66. data/lib/rubocop/cop/lint/unused_block_argument.rb +9 -7
  67. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
  68. data/lib/rubocop/cop/lint/useless_access_modifier.rb +56 -29
  69. data/lib/rubocop/cop/lint/useless_assignment.rb +4 -16
  70. data/lib/rubocop/cop/lint/useless_comparison.rb +3 -2
  71. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +2 -1
  72. data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -20
  73. data/lib/rubocop/cop/lint/void.rb +10 -11
  74. data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
  75. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -1
  76. data/lib/rubocop/cop/metrics/class_length.rb +1 -0
  77. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -2
  78. data/lib/rubocop/cop/metrics/line_length.rb +35 -13
  79. data/lib/rubocop/cop/metrics/method_length.rb +2 -1
  80. data/lib/rubocop/cop/metrics/module_length.rb +1 -0
  81. data/lib/rubocop/cop/metrics/parameter_lists.rb +2 -1
  82. data/lib/rubocop/cop/metrics/perceived_complexity.rb +4 -2
  83. data/lib/rubocop/cop/mixin/access_modifier_node.rb +3 -10
  84. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
  85. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +80 -0
  86. data/lib/rubocop/cop/mixin/array_syntax.rb +2 -1
  87. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +14 -20
  88. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +5 -4
  89. data/lib/rubocop/cop/mixin/check_assignment.rb +20 -15
  90. data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
  91. data/lib/rubocop/cop/mixin/code_length.rb +1 -0
  92. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +17 -15
  93. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
  94. data/lib/rubocop/cop/mixin/configurable_naming.rb +4 -0
  95. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +9 -4
  96. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +24 -16
  97. data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -2
  98. data/lib/rubocop/cop/mixin/hash_node.rb +15 -0
  99. data/lib/rubocop/cop/mixin/if_node.rb +1 -0
  100. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
  101. data/lib/rubocop/cop/mixin/method_preference.rb +1 -0
  102. data/lib/rubocop/cop/mixin/min_body_length.rb +1 -0
  103. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +177 -0
  104. data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -0
  105. data/lib/rubocop/cop/mixin/on_method_def.rb +6 -5
  106. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +1 -0
  107. data/lib/rubocop/cop/mixin/parentheses.rb +22 -0
  108. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -0
  109. data/lib/rubocop/cop/mixin/percent_literal.rb +1 -0
  110. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +79 -0
  111. data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -0
  112. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -1
  113. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +2 -1
  114. data/lib/rubocop/cop/mixin/space_inside.rb +2 -1
  115. data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -5
  116. data/lib/rubocop/cop/mixin/string_help.rb +2 -9
  117. data/lib/rubocop/cop/mixin/string_literals_help.rb +13 -7
  118. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -2
  119. data/lib/rubocop/cop/mixin/trailing_comma.rb +134 -0
  120. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -0
  121. data/lib/rubocop/cop/offense.rb +19 -14
  122. data/lib/rubocop/cop/performance/case_when_splat.rb +8 -8
  123. data/lib/rubocop/cop/performance/casecmp.rb +54 -0
  124. data/lib/rubocop/cop/performance/count.rb +10 -9
  125. data/lib/rubocop/cop/performance/detect.rb +6 -5
  126. data/lib/rubocop/cop/performance/double_start_end_with.rb +65 -0
  127. data/lib/rubocop/cop/performance/end_with.rb +55 -0
  128. data/lib/rubocop/cop/performance/fixed_size.rb +1 -0
  129. data/lib/rubocop/cop/performance/flat_map.rb +9 -8
  130. data/lib/rubocop/cop/performance/hash_each.rb +86 -0
  131. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +44 -0
  132. data/lib/rubocop/cop/performance/range_include.rb +40 -0
  133. data/lib/rubocop/cop/performance/redundant_block_call.rb +57 -0
  134. data/lib/rubocop/cop/performance/redundant_match.rb +51 -0
  135. data/lib/rubocop/cop/performance/redundant_merge.rb +85 -0
  136. data/lib/rubocop/cop/performance/redundant_sort_by.rb +45 -0
  137. data/lib/rubocop/cop/performance/reverse_each.rb +3 -2
  138. data/lib/rubocop/cop/performance/sample.rb +6 -5
  139. data/lib/rubocop/cop/performance/size.rb +2 -1
  140. data/lib/rubocop/cop/performance/start_with.rb +58 -0
  141. data/lib/rubocop/cop/performance/string_replacement.rb +18 -23
  142. data/lib/rubocop/cop/performance/times_map.rb +49 -0
  143. data/lib/rubocop/cop/rails/action_filter.rb +4 -3
  144. data/lib/rubocop/cop/rails/date.rb +5 -4
  145. data/lib/rubocop/cop/rails/delegate.rb +3 -2
  146. data/lib/rubocop/cop/rails/find_by.rb +20 -14
  147. data/lib/rubocop/cop/rails/find_each.rb +23 -2
  148. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +3 -2
  149. data/lib/rubocop/cop/rails/output.rb +4 -2
  150. data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
  151. data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -7
  152. data/lib/rubocop/cop/rails/scope_args.rb +3 -2
  153. data/lib/rubocop/cop/rails/time_zone.rb +14 -10
  154. data/lib/rubocop/cop/rails/validation.rb +4 -3
  155. data/lib/rubocop/cop/severity.rb +8 -7
  156. data/lib/rubocop/cop/style/access_modifier_indentation.rb +5 -4
  157. data/lib/rubocop/cop/style/accessor_method_name.rb +1 -0
  158. data/lib/rubocop/cop/style/alias.rb +84 -24
  159. data/lib/rubocop/cop/style/align_array.rb +2 -1
  160. data/lib/rubocop/cop/style/align_hash.rb +13 -14
  161. data/lib/rubocop/cop/style/align_parameters.rb +3 -2
  162. data/lib/rubocop/cop/style/and_or.rb +9 -7
  163. data/lib/rubocop/cop/style/array_join.rb +5 -5
  164. data/lib/rubocop/cop/style/ascii_comments.rb +2 -1
  165. data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -1
  166. data/lib/rubocop/cop/style/attr.rb +30 -5
  167. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -3
  168. data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -1
  169. data/lib/rubocop/cop/style/begin_block.rb +2 -1
  170. data/lib/rubocop/cop/style/block_comments.rb +2 -1
  171. data/lib/rubocop/cop/style/block_delimiters.rb +10 -9
  172. data/lib/rubocop/cop/style/block_end_newline.rb +3 -2
  173. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +9 -8
  174. data/lib/rubocop/cop/style/case_equality.rb +2 -1
  175. data/lib/rubocop/cop/style/case_indentation.rb +2 -1
  176. data/lib/rubocop/cop/style/character_literal.rb +11 -7
  177. data/lib/rubocop/cop/style/class_and_module_camel_case.rb +2 -1
  178. data/lib/rubocop/cop/style/class_and_module_children.rb +3 -2
  179. data/lib/rubocop/cop/style/class_check.rb +2 -1
  180. data/lib/rubocop/cop/style/class_methods.rb +2 -1
  181. data/lib/rubocop/cop/style/class_vars.rb +2 -1
  182. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +3 -2
  183. data/lib/rubocop/cop/style/collection_methods.rb +2 -1
  184. data/lib/rubocop/cop/style/colon_method_call.rb +3 -2
  185. data/lib/rubocop/cop/style/command_literal.rb +8 -7
  186. data/lib/rubocop/cop/style/comment_annotation.rb +3 -2
  187. data/lib/rubocop/cop/style/comment_indentation.rb +4 -6
  188. data/lib/rubocop/cop/style/conditional_assignment.rb +362 -0
  189. data/lib/rubocop/cop/style/constant_name.rb +2 -1
  190. data/lib/rubocop/cop/style/copyright.rb +7 -6
  191. data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -1
  192. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +3 -2
  193. data/lib/rubocop/cop/style/documentation.rb +7 -11
  194. data/lib/rubocop/cop/style/dot_position.rb +3 -2
  195. data/lib/rubocop/cop/style/double_negation.rb +2 -1
  196. data/lib/rubocop/cop/style/each_with_object.rb +4 -3
  197. data/lib/rubocop/cop/style/else_alignment.rb +3 -2
  198. data/lib/rubocop/cop/style/empty_else.rb +4 -3
  199. data/lib/rubocop/cop/style/empty_line_between_defs.rb +2 -1
  200. data/lib/rubocop/cop/style/empty_lines.rb +10 -4
  201. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +13 -5
  202. data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +7 -3
  203. data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +6 -3
  204. data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +4 -3
  205. data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +4 -2
  206. data/lib/rubocop/cop/style/empty_literal.rb +20 -5
  207. data/lib/rubocop/cop/style/encoding.rb +8 -11
  208. data/lib/rubocop/cop/style/end_block.rb +3 -1
  209. data/lib/rubocop/cop/style/end_of_line.rb +2 -1
  210. data/lib/rubocop/cop/style/even_odd.rb +4 -3
  211. data/lib/rubocop/cop/style/extra_spacing.rb +110 -74
  212. data/lib/rubocop/cop/style/file_name.rb +103 -6
  213. data/lib/rubocop/cop/style/first_array_element_line_break.rb +3 -2
  214. data/lib/rubocop/cop/style/first_hash_element_line_break.rb +5 -6
  215. data/lib/rubocop/cop/style/first_method_argument_line_break.rb +14 -1
  216. data/lib/rubocop/cop/style/first_method_parameter_line_break.rb +2 -1
  217. data/lib/rubocop/cop/style/first_parameter_indentation.rb +6 -4
  218. data/lib/rubocop/cop/style/flip_flop.rb +2 -1
  219. data/lib/rubocop/cop/style/for.rb +2 -1
  220. data/lib/rubocop/cop/style/format_string.rb +1 -0
  221. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -0
  222. data/lib/rubocop/cop/style/global_vars.rb +2 -1
  223. data/lib/rubocop/cop/style/guard_clause.rb +63 -11
  224. data/lib/rubocop/cop/style/hash_syntax.rb +10 -10
  225. data/lib/rubocop/cop/style/identical_conditional_branches.rb +93 -0
  226. data/lib/rubocop/cop/style/if_inside_else.rb +49 -0
  227. data/lib/rubocop/cop/style/if_unless_modifier.rb +6 -5
  228. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -1
  229. data/lib/rubocop/cop/style/indent_array.rb +89 -38
  230. data/lib/rubocop/cop/style/indent_assignment.rb +43 -0
  231. data/lib/rubocop/cop/style/indent_hash.rb +16 -77
  232. data/lib/rubocop/cop/style/indentation_consistency.rb +2 -1
  233. data/lib/rubocop/cop/style/indentation_width.rb +11 -11
  234. data/lib/rubocop/cop/style/infinite_loop.rb +5 -9
  235. data/lib/rubocop/cop/style/initial_indentation.rb +2 -1
  236. data/lib/rubocop/cop/style/inline_comment.rb +2 -1
  237. data/lib/rubocop/cop/style/lambda.rb +14 -11
  238. data/lib/rubocop/cop/style/lambda_call.rb +4 -4
  239. data/lib/rubocop/cop/style/leading_comment_space.rb +2 -1
  240. data/lib/rubocop/cop/style/line_end_concatenation.rb +3 -1
  241. data/lib/rubocop/cop/style/method_call_parentheses.rb +9 -1
  242. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -2
  243. data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -4
  244. data/lib/rubocop/cop/style/method_name.rb +1 -0
  245. data/lib/rubocop/cop/style/missing_else.rb +5 -3
  246. data/lib/rubocop/cop/style/module_function.rb +2 -1
  247. data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +95 -0
  248. data/lib/rubocop/cop/style/multiline_assignment_layout.rb +91 -0
  249. data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
  250. data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -9
  251. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -0
  252. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +137 -0
  253. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +25 -135
  254. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
  255. data/lib/rubocop/cop/style/mutable_constant.rb +4 -5
  256. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  257. data/lib/rubocop/cop/style/negated_while.rb +3 -3
  258. data/lib/rubocop/cop/style/nested_modifier.rb +6 -5
  259. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +48 -0
  260. data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -1
  261. data/lib/rubocop/cop/style/next.rb +79 -15
  262. data/lib/rubocop/cop/style/nil_comparison.rb +5 -5
  263. data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
  264. data/lib/rubocop/cop/style/not.rb +5 -9
  265. data/lib/rubocop/cop/style/numeric_literals.rb +5 -4
  266. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
  267. data/lib/rubocop/cop/style/op_method.rb +7 -4
  268. data/lib/rubocop/cop/style/option_hash.rb +13 -7
  269. data/lib/rubocop/cop/style/optional_arguments.rb +3 -2
  270. data/lib/rubocop/cop/style/parallel_assignment.rb +40 -16
  271. data/lib/rubocop/cop/style/parentheses_around_condition.rb +3 -16
  272. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -2
  273. data/lib/rubocop/cop/style/percent_q_literals.rb +3 -6
  274. data/lib/rubocop/cop/style/perl_backrefs.rb +4 -3
  275. data/lib/rubocop/cop/style/predicate_name.rb +1 -0
  276. data/lib/rubocop/cop/style/proc.rb +3 -2
  277. data/lib/rubocop/cop/style/raise_args.rb +2 -1
  278. data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
  279. data/lib/rubocop/cop/style/redundant_exception.rb +5 -5
  280. data/lib/rubocop/cop/style/redundant_freeze.rb +5 -4
  281. data/lib/rubocop/cop/style/redundant_parentheses.rb +80 -0
  282. data/lib/rubocop/cop/style/redundant_return.rb +5 -4
  283. data/lib/rubocop/cop/style/redundant_self.rb +7 -8
  284. data/lib/rubocop/cop/style/regexp_literal.rb +9 -8
  285. data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +3 -2
  286. data/lib/rubocop/cop/style/rescue_modifier.rb +11 -9
  287. data/lib/rubocop/cop/style/self_assignment.rb +4 -5
  288. data/lib/rubocop/cop/style/semicolon.rb +3 -2
  289. data/lib/rubocop/cop/style/send.rb +3 -1
  290. data/lib/rubocop/cop/style/signal_exception.rb +5 -3
  291. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -1
  292. data/lib/rubocop/cop/style/single_line_methods.rb +7 -7
  293. data/lib/rubocop/cop/style/space_after_colon.rb +2 -1
  294. data/lib/rubocop/cop/style/space_after_comma.rb +1 -0
  295. data/lib/rubocop/cop/style/space_after_control_keyword.rb +5 -5
  296. data/lib/rubocop/cop/style/space_after_method_name.rb +3 -2
  297. data/lib/rubocop/cop/style/space_after_not.rb +4 -3
  298. data/lib/rubocop/cop/style/space_after_semicolon.rb +1 -0
  299. data/lib/rubocop/cop/style/space_around_block_parameters.rb +8 -7
  300. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -0
  301. data/lib/rubocop/cop/style/space_around_operators.rb +72 -32
  302. data/lib/rubocop/cop/style/space_before_block_braces.rb +2 -1
  303. data/lib/rubocop/cop/style/space_before_comma.rb +1 -0
  304. data/lib/rubocop/cop/style/space_before_comment.rb +2 -1
  305. data/lib/rubocop/cop/style/{single_space_before_first_arg.rb → space_before_first_arg.rb} +13 -4
  306. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +4 -3
  307. data/lib/rubocop/cop/style/space_before_semicolon.rb +1 -0
  308. data/lib/rubocop/cop/style/space_inside_block_braces.rb +3 -2
  309. data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -0
  310. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +4 -1
  311. data/lib/rubocop/cop/style/space_inside_parens.rb +1 -0
  312. data/lib/rubocop/cop/style/space_inside_range_literal.rb +5 -4
  313. data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +8 -17
  314. data/lib/rubocop/cop/style/special_global_vars.rb +97 -52
  315. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +16 -9
  316. data/lib/rubocop/cop/style/string_literals.rb +41 -1
  317. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +2 -1
  318. data/lib/rubocop/cop/style/string_methods.rb +2 -1
  319. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -2
  320. data/lib/rubocop/cop/style/symbol_array.rb +74 -7
  321. data/lib/rubocop/cop/style/symbol_literal.rb +4 -7
  322. data/lib/rubocop/cop/style/symbol_proc.rb +11 -7
  323. data/lib/rubocop/cop/style/tab.rb +25 -2
  324. data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -2
  325. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  326. data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +56 -0
  327. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +8 -7
  328. data/lib/rubocop/cop/style/trailing_whitespace.rb +2 -1
  329. data/lib/rubocop/cop/style/trivial_accessors.rb +18 -9
  330. data/lib/rubocop/cop/style/unless_else.rb +2 -1
  331. data/lib/rubocop/cop/style/unneeded_capital_w.rb +4 -3
  332. data/lib/rubocop/cop/style/unneeded_interpolation.rb +87 -0
  333. data/lib/rubocop/cop/style/unneeded_percent_q.rb +23 -7
  334. data/lib/rubocop/cop/style/variable_interpolation.rb +8 -6
  335. data/lib/rubocop/cop/style/variable_name.rb +1 -0
  336. data/lib/rubocop/cop/style/when_then.rb +2 -1
  337. data/lib/rubocop/cop/style/while_until_do.rb +3 -2
  338. data/lib/rubocop/cop/style/while_until_modifier.rb +3 -4
  339. data/lib/rubocop/cop/style/word_array.rb +74 -51
  340. data/lib/rubocop/cop/team.rb +21 -15
  341. data/lib/rubocop/cop/util.rb +102 -69
  342. data/lib/rubocop/cop/variable_force.rb +2 -1
  343. data/lib/rubocop/cop/variable_force/assignment.rb +2 -1
  344. data/lib/rubocop/cop/variable_force/locatable.rb +1 -0
  345. data/lib/rubocop/cop/variable_force/reference.rb +1 -0
  346. data/lib/rubocop/cop/variable_force/scope.rb +2 -1
  347. data/lib/rubocop/cop/variable_force/variable.rb +2 -1
  348. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -1
  349. data/lib/rubocop/error.rb +12 -0
  350. data/lib/rubocop/formatter/base_formatter.rb +10 -1
  351. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -0
  352. data/lib/rubocop/formatter/colorizable.rb +6 -1
  353. data/lib/rubocop/formatter/disabled_config_formatter.rb +29 -15
  354. data/lib/rubocop/formatter/disabled_lines_formatter.rb +3 -1
  355. data/lib/rubocop/formatter/emacs_style_formatter.rb +7 -3
  356. data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
  357. data/lib/rubocop/formatter/formatter_set.rb +10 -19
  358. data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -1
  359. data/lib/rubocop/formatter/html_formatter.rb +15 -14
  360. data/lib/rubocop/formatter/json_formatter.rb +2 -1
  361. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -0
  362. data/lib/rubocop/formatter/progress_formatter.rb +3 -3
  363. data/lib/rubocop/formatter/simple_text_formatter.rb +50 -17
  364. data/lib/rubocop/formatter/text_util.rb +8 -10
  365. data/lib/rubocop/formatter/worst_offenders_formatter.rb +61 -0
  366. data/lib/rubocop/name_similarity.rb +22 -0
  367. data/lib/rubocop/node_pattern.rb +126 -35
  368. data/lib/rubocop/options.rb +28 -19
  369. data/lib/rubocop/path_util.rb +1 -0
  370. data/lib/rubocop/processed_source.rb +41 -16
  371. data/lib/rubocop/rake_task.rb +6 -9
  372. data/lib/rubocop/remote_config.rb +1 -0
  373. data/lib/rubocop/result_cache.rb +60 -43
  374. data/lib/rubocop/runner.rb +48 -45
  375. data/lib/rubocop/string_util.rb +1 -0
  376. data/lib/rubocop/target_finder.rb +2 -1
  377. data/lib/rubocop/token.rb +1 -0
  378. data/lib/rubocop/version.rb +3 -2
  379. data/lib/rubocop/warning.rb +1 -0
  380. data/relnotes/v0.36.0.md +306 -0
  381. data/rubocop.gemspec +3 -9
  382. metadata +48 -92
  383. data/lib/rubocop/cop/lint/space_before_first_arg.rb +0 -44
  384. data/lib/rubocop/cop/rails/default_scope.rb +0 -33
  385. data/lib/rubocop/cop/style/trailing_comma.rb +0 -182
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
@@ -9,7 +10,7 @@ module RuboCop
9
10
  #
10
11
  # "result is #{}"
11
12
  class EmptyInterpolation < Cop
12
- MSG = 'Empty interpolation detected.'
13
+ MSG = 'Empty interpolation detected.'.freeze
13
14
 
14
15
  def on_dstr(node)
15
16
  node.children.select { |n| n.type == :begin }.each do |begin_node|
@@ -1,51 +1,64 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
5
6
  module Lint
6
7
  # This cop checks whether the end keywords are aligned properly.
7
8
  #
8
- # Two modes are supported through the AlignWith configuration
9
- # parameter. If it's set to `keyword` (which is the default), the `end`
10
- # shall be aligned with the start of the keyword (if, class, etc.). If
11
- # it's set to `variable` the `end` shall be aligned with the
9
+ # Three modes are supported through the `AlignWith` configuration
10
+ # parameter:
11
+ #
12
+ # If it's set to `keyword` (which is the default), the `end`
13
+ # shall be aligned with the start of the keyword (if, class, etc.).
14
+ #
15
+ # If it's set to `variable` the `end` shall be aligned with the
12
16
  # left-hand-side of the variable assignment, if there is one.
13
17
  #
14
- # @example
18
+ # If it's set to `start_of_line`, the `end` shall be aligned with the
19
+ # start of the line where the matching keyword appears.
15
20
  #
21
+ # @example
22
+ # @good
23
+ # # keyword style
16
24
  # variable = if true
17
25
  # end
26
+ #
27
+ # # variable style
28
+ # variable = if true
29
+ # end
30
+ #
31
+ # # start_of_line style
32
+ # puts(if true
33
+ # end)
18
34
  class EndAlignment < Cop
19
35
  include CheckAssignment
20
36
  include EndKeywordAlignment
21
37
  include IfNode
22
38
 
23
39
  def on_class(node)
24
- check_offset_of_node(node)
40
+ check_other_alignment(node)
25
41
  end
26
42
 
27
43
  def on_module(node)
28
- check_offset_of_node(node)
44
+ check_other_alignment(node)
29
45
  end
30
46
 
31
47
  def on_if(node)
32
- check_offset_of_node(node) unless ternary_op?(node)
48
+ check_other_alignment(node) unless ternary_op?(node)
33
49
  end
34
50
 
35
51
  def on_while(node)
36
- check_offset_of_node(node)
52
+ check_other_alignment(node)
37
53
  end
38
54
 
39
55
  def on_until(node)
40
- check_offset_of_node(node)
56
+ check_other_alignment(node)
41
57
  end
42
58
 
43
59
  def on_case(node)
44
- if argument_case?(node)
45
- return check_alignment(node.ancestors.first, node)
46
- end
47
-
48
- check_offset_of_node(node)
60
+ return check_asgn_alignment(node.parent, node) if argument_case?(node)
61
+ check_other_alignment(node)
49
62
  end
50
63
 
51
64
  private
@@ -54,47 +67,72 @@ module RuboCop
54
67
  # If there are method calls chained to the right hand side of the
55
68
  # assignment, we let rhs be the receiver of those method calls before
56
69
  # we check if it's an if/unless/while/until.
57
- rhs = first_part_of_call_chain(rhs)
58
-
59
- return unless rhs
60
-
70
+ return unless (rhs = first_part_of_call_chain(rhs))
61
71
  return unless [:if, :while, :until, :case].include?(rhs.type)
62
72
  return if ternary_op?(rhs)
63
73
 
64
- check_alignment(node, rhs)
74
+ check_asgn_alignment(node, rhs)
65
75
  end
66
76
 
67
- def check_alignment(outer_node, inner_node)
68
- expr = outer_node.loc.expression
69
- if variable_alignment?(expr, inner_node, style)
70
- range = Parser::Source::Range.new(expr.source_buffer,
71
- expr.begin_pos,
72
- inner_node.loc.keyword.end_pos)
73
- offset =
74
- inner_node.loc.keyword.column - outer_node.loc.expression.column
75
- else
76
- range = inner_node.loc.keyword
77
- offset = 0
78
- end
77
+ def check_asgn_alignment(outer_node, inner_node)
78
+ expr = outer_node.source_range
79
+
80
+ align_with = {
81
+ keyword: inner_node.loc.keyword,
82
+ start_of_line: start_line_range(outer_node)
83
+ }
79
84
 
80
- check_offset(inner_node, range.source, offset)
85
+ align_with[:variable] =
86
+ if !line_break_before_keyword?(expr, inner_node)
87
+ Parser::Source::Range.new(expr.source_buffer,
88
+ expr.begin_pos,
89
+ inner_node.loc.keyword.end_pos)
90
+ else
91
+ inner_node.loc.keyword
92
+ end
93
+
94
+ check_end_kw_alignment(inner_node, align_with)
81
95
  ignore_node(inner_node) # Don't check again.
82
96
  end
83
97
 
98
+ def check_other_alignment(node)
99
+ align_with = {
100
+ keyword: node.loc.keyword,
101
+ variable: node.loc.keyword,
102
+ start_of_line: start_line_range(node)
103
+ }
104
+ check_end_kw_alignment(node, align_with)
105
+ end
106
+
84
107
  def autocorrect(node)
85
108
  align(node, alignment_node(node))
86
109
  end
87
110
 
88
111
  def alignment_node(node)
89
- return node unless style == :variable
90
- return node.ancestors.first if argument_case?(node)
91
-
92
- node.each_ancestor(:lvasgn).first
112
+ if style == :keyword
113
+ node
114
+ elsif style == :variable
115
+ return node.parent if argument_case?(node)
116
+ # Fall back to 'keyword' style if this node is not on the RHS
117
+ # of an assignment
118
+ node.ancestors.find(&:assignment?) || node
119
+ else
120
+ start_line_range(node)
121
+ end
93
122
  end
94
123
 
95
124
  def argument_case?(node)
96
- node.case_type? && !node.ancestors.empty? &&
97
- node.ancestors.first.send_type?
125
+ node.case_type? && node.parent && node.parent.send_type?
126
+ end
127
+
128
+ def start_line_range(node)
129
+ expr = node.source_range
130
+ buffer = expr.source_buffer
131
+ source = buffer.source_line(expr.line)
132
+ range = buffer.line_range(expr.line)
133
+ Parser::Source::Range.new(buffer,
134
+ range.begin_pos + (source =~ /\S/),
135
+ range.begin_pos + (source =~ /\s*\z/))
98
136
  end
99
137
  end
100
138
  end
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
5
6
  module Lint
6
7
  # This cop checks for END blocks in method definitions.
7
8
  class EndInMethod < Cop
8
- MSG = '`END` found in method definition. Use `at_exit` instead.'
9
+ MSG = '`END` found in method definition. Use `at_exit` instead.'.freeze
9
10
 
10
11
  def on_postexe(node)
11
12
  inside_of_method = node.each_ancestor(:def, :defs).count.nonzero?
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
5
6
  module Lint
6
7
  # This cop checks for *return* from an *ensure* block.
7
8
  class EnsureReturn < Cop
8
- MSG = 'Do not return from an `ensure` block.'
9
+ MSG = 'Do not return from an `ensure` block.'.freeze
9
10
 
10
11
  def on_ensure(node)
11
12
  _body, ensure_body = *node
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
5
6
  module Lint
6
7
  # This cop checks for the use of *Kernel#eval*.
7
8
  class Eval < Cop
8
- MSG = 'The use of `eval` is a serious security risk.'
9
+ MSG = 'The use of `eval` is a serious security risk.'.freeze
9
10
 
10
11
  def on_send(node)
11
12
  receiver, method_name, *args = *node
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Lint
7
+ # This cop identifies Float literals which are, like, really really really
8
+ # really really really really really big. Too big. No-one needs Floats
9
+ # that big. If you need a float that big, something is wrong with you.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # float = 3.0e400
14
+ #
15
+ # # good
16
+ # float = 42.9
17
+ class FloatOutOfRange < Cop
18
+ MSG = 'Float out of range.'.freeze
19
+
20
+ def on_float(node)
21
+ value, = *node
22
+ if value.infinite?
23
+ add_offense(node, :expression, MSG)
24
+ elsif value.zero? && node.source =~ /[1-9]/
25
+ add_offense(node, :expression, MSG)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
@@ -13,15 +14,17 @@ module RuboCop
13
14
  #
14
15
  class FormatParameterMismatch < Cop
15
16
  # http://rubular.com/r/CvpbxkcTzy
16
- MSG = 'Number arguments (%i) to `%s` mismatches expected fields (%i).'
17
- FIELD_REGEX = /(%(([\s#+-0\*])?(\d*)?(.\d+)?(\.)?[bBdiouxXeEfgGaAcps]|%))/.freeze # rubocop:disable Metrics/LineLength
18
- NAMED_FIELD_REGEX = /%\{[_a-zA-Z][_a-zA-Z]+\}/.freeze
17
+ MSG = "Number of arguments (%i) to `%s` doesn't match the number of " \
18
+ 'fields (%i).'.freeze
19
+ FIELD_REGEX =
20
+ /(%(([\s#+-0\*]*)(\d*)?(.\d+)?[bBdiouxXeEfgGaAcps]|%))/
21
+ NAMED_FIELD_REGEX = /%\{[_a-zA-Z][_a-zA-Z]+\}/
19
22
  KERNEL = 'Kernel'.freeze
20
23
  SHOVEL = '<<'.freeze
21
24
  PERCENT = '%'.freeze
22
25
  PERCENT_PERCENT = '%%'.freeze
23
- SPLAT = '*'.freeze
24
26
  STRING_TYPES = [:str, :dstr].freeze
27
+ NAMED_INTERPOLATION = /%(?:<\w+>|\{\w+\})/
25
28
 
26
29
  def on_send(node)
27
30
  add_offense(node, :selector) if offending_node?(node)
@@ -65,7 +68,7 @@ module RuboCop
65
68
  receiver_node
66
69
  end
67
70
 
68
- relevant_node.loc.expression.source.scan(NAMED_FIELD_REGEX).size > 0
71
+ relevant_node.source.scan(NAMED_FIELD_REGEX).size > 0
69
72
  end
70
73
 
71
74
  def node_with_splat_args?(node)
@@ -73,22 +76,13 @@ module RuboCop
73
76
 
74
77
  _receiver_node, _method_name, *args = *node
75
78
 
76
- args[1..-1].any? { |arg| arg.type == :splat }
79
+ args.butfirst.any? { |arg| arg.type == :splat }
77
80
  end
78
81
 
79
82
  def heredoc?(node)
80
83
  _receiver, _name, args = *node
81
84
 
82
- args.loc.expression.source[0, 2] == SHOVEL
83
- end
84
-
85
- def literal?(node)
86
- node.int_type? ||
87
- node.str_type? ||
88
- node.sym_type? ||
89
- node.float_type? ||
90
- node.dstr_type? ||
91
- node.dsym_type?
85
+ args.source[0, 2] == SHOVEL
92
86
  end
93
87
 
94
88
  def count_matches(node)
@@ -99,17 +93,7 @@ module RuboCop
99
93
  number_of_expected_fields = expected_fields_count(args.first)
100
94
  elsif percent?(node) && args.first.array_type?
101
95
  number_of_expected_fields = expected_fields_count(receiver_node)
102
-
103
- first_child_argument = args.first
104
- if first_child_argument.array_type?
105
- number_of_args_for_format = args.first.child_nodes.size
106
- elsif literal?(first_child_argument)
107
- number_of_args_for_format = 1
108
- else
109
- # non-literals might evaluate to an Array, or they might not
110
- # so we can't tell just how many format args there will be
111
- number_of_args_for_format = :unknown
112
- end
96
+ number_of_args_for_format = args.first.child_nodes.size
113
97
  else
114
98
  number_of_args_for_format = number_of_expected_fields = :unknown
115
99
  end
@@ -131,13 +115,13 @@ module RuboCop
131
115
 
132
116
  def expected_fields_count(node)
133
117
  return :unknown unless node.str_type?
118
+ return 1 if node.source =~ NAMED_INTERPOLATION
119
+
134
120
  node
135
- .loc
136
- .expression
137
121
  .source
138
122
  .scan(FIELD_REGEX)
139
123
  .select { |x| x.first != PERCENT_PERCENT }
140
- .reduce(0) { |a, e| a + (e[2] == SPLAT ? 2 : 1) }
124
+ .reduce(0) { |a, e| a + (e[2] =~ /\*/ ? 2 : 1) }
141
125
  end
142
126
 
143
127
  def format?(node)
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  module Cop
5
6
  module Lint
6
7
  # This cop checks for *rescue* blocks with no body.
7
8
  class HandleExceptions < Cop
8
- MSG = 'Do not suppress exceptions.'
9
+ MSG = 'Do not suppress exceptions.'.freeze
9
10
 
10
11
  def on_resbody(node)
11
12
  _exc_list_node, _exc_var_node, body_node = *node
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Lint
7
+ # This cop checks for implicit string concatenation of string literals
8
+ # which are on the same line.
9
+ #
10
+ # @example
11
+ # @bad
12
+ # array = ['Item 1' 'Item 2']
13
+ #
14
+ # @good
15
+ # array = ['Item 1Item 2']
16
+ # array = ['Item 1' + 'Item 2']
17
+ # array = [
18
+ # 'Item 1' \
19
+ # 'Item 2'
20
+ # ]
21
+ class ImplicitStringConcatenation < Cop
22
+ MSG = 'Combine %s and %s into a single string literal, rather than ' \
23
+ 'using implicit string concatenation.'.freeze
24
+ FOR_ARRAY = ' Or, if they were intended to be separate array ' \
25
+ 'elements, separate them with a comma.'.freeze
26
+ FOR_METHOD = ' Or, if they were intended to be separate method ' \
27
+ 'arguments, separate them with a comma.'.freeze
28
+
29
+ def on_dstr(node)
30
+ node.children.each_cons(2) do |child1, child2|
31
+ # `'abc' 'def'` -> (dstr (str "abc") (str "def"))
32
+ next unless string_literal?(child1) && string_literal?(child2)
33
+ next unless child1.loc.last_line == child2.loc.line
34
+
35
+ # Make sure we don't flag a string literal which simply has
36
+ # embedded newlines
37
+ # `"abc\ndef"` also -> (dstr (str "abc") (str "def"))
38
+ next unless child1.source[-1] == ending_delimiter(child1)
39
+
40
+ range = child1.source_range.join(child2.source_range)
41
+ message = format(MSG, display_str(child1), display_str(child2))
42
+ if node.parent && node.parent.array_type?
43
+ message << FOR_ARRAY
44
+ elsif node.parent && node.parent.send_type?
45
+ message << FOR_METHOD
46
+ end
47
+ add_offense(node, range, message)
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def ending_delimiter(str)
54
+ # implicit string concatenation does not work with %{}, etc.
55
+ if str.source[0] == "'"
56
+ "'"
57
+ elsif str.source[0] == '"'
58
+ '"'
59
+ end
60
+ end
61
+
62
+ def string_literal?(node)
63
+ node.str_type? ||
64
+ (node.dstr_type? && node.children.all? { |c| string_literal?(c) })
65
+ end
66
+
67
+ def display_str(node)
68
+ if node.source =~ /\n/
69
+ str_content(node).inspect
70
+ else
71
+ node.source
72
+ end
73
+ end
74
+
75
+ def str_content(node)
76
+ if node.str_type?
77
+ node.children[0]
78
+ else
79
+ node.children.map { |c| str_content(c) }.join
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end