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
  # Common methods and behaviors for dealing with paths.
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
- require 'astrolabe/builder'
4
4
  require 'digest/md5'
5
5
 
6
6
  module RuboCop
@@ -8,29 +8,32 @@ module RuboCop
8
8
  # and other information such as disabled lines for cops.
9
9
  # It also provides a convenient way to access source lines.
10
10
  class ProcessedSource
11
- STRING_SOURCE_NAME = '(string)'
11
+ STRING_SOURCE_NAME = '(string)'.freeze
12
+
12
13
  attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
13
- :parser_error, :raw_source
14
+ :parser_error, :raw_source, :ruby_version
14
15
 
15
- def self.from_file(path)
16
+ def self.from_file(path, ruby_version)
16
17
  file = File.read(path)
17
- new(file, path)
18
+ new(file, ruby_version, path)
18
19
  rescue Errno::ENOENT
19
- abort("#{Rainbow('rubocop: No such file or directory').red} -- #{path}")
20
- rescue => ex
21
- abort("#{Rainbow("rubocop: #{ex.message}").red} -- #{path}")
20
+ raise RuboCop::Error, "No such file or directory: #{path}"
22
21
  end
23
22
 
24
- def initialize(source, path = nil)
23
+ def initialize(source, ruby_version, path = nil)
25
24
  # In Ruby 2, source code encoding defaults to UTF-8. We follow the same
26
25
  # principle regardless of which Ruby version we're running under.
27
26
  # Encoding comments will override this setting.
28
- source.force_encoding(Encoding::UTF_8)
27
+ unless source.encoding == Encoding::UTF_8
28
+ source.force_encoding(Encoding::UTF_8)
29
+ end
29
30
 
30
31
  @raw_source = source
31
32
  @path = path
32
33
  @diagnostics = []
33
- parse(source)
34
+ @ruby_version = ruby_version
35
+
36
+ parse(source, ruby_version)
34
37
  end
35
38
 
36
39
  def comment_config
@@ -72,7 +75,7 @@ module RuboCop
72
75
 
73
76
  private
74
77
 
75
- def parse(source)
78
+ def parse(source, ruby_version)
76
79
  buffer_name = @path || STRING_SOURCE_NAME
77
80
  @buffer = Parser::Source::Buffer.new(buffer_name, 1)
78
81
 
@@ -83,7 +86,7 @@ module RuboCop
83
86
  return
84
87
  end
85
88
 
86
- parser = create_parser
89
+ parser = create_parser(ruby_version)
87
90
 
88
91
  begin
89
92
  @ast, @comments, tokens = parser.tokenize(@buffer)
@@ -94,10 +97,32 @@ module RuboCop
94
97
  @tokens = tokens.map { |t| Token.from_parser_token(t) } if tokens
95
98
  end
96
99
 
97
- def create_parser
98
- builder = Astrolabe::Builder.new
100
+ def parser_class(ruby_version)
101
+ case ruby_version
102
+ when 1.9
103
+ require 'parser/ruby19'
104
+ Parser::Ruby19
105
+ when 2.0
106
+ require 'parser/ruby20'
107
+ Parser::Ruby20
108
+ when 2.1
109
+ require 'parser/ruby21'
110
+ Parser::Ruby21
111
+ when 2.2
112
+ require 'parser/ruby22'
113
+ Parser::Ruby22
114
+ when 2.3
115
+ require 'parser/ruby23'
116
+ Parser::Ruby23
117
+ else
118
+ fail ArgumentError, "Unknown Ruby version: #{ruby_version.inspect}"
119
+ end
120
+ end
121
+
122
+ def create_parser(ruby_version)
123
+ builder = RuboCop::Node::Builder.new
99
124
 
100
- Parser::CurrentRuby.new(builder).tap do |parser|
125
+ parser_class(ruby_version).new(builder).tap do |parser|
101
126
  # On JRuby and Rubinius, there's a risk that we hang in tokenize() if we
102
127
  # don't set the all errors as fatal flag. The problem is caused by a bug
103
128
  # in Racc that is discussed in issue #93 of the whitequark/parser
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rake'
4
5
  require 'rake/tasklib'
@@ -24,9 +25,7 @@ module RuboCop
24
25
 
25
26
  task(name, *args) do |_, task_args|
26
27
  RakeFileUtils.send(:verbose, verbose) do
27
- if task_block
28
- task_block.call(*[self, task_args].slice(0, task_block.arity))
29
- end
28
+ yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
30
29
  run_main_task(verbose)
31
30
  end
32
31
  end
@@ -53,8 +52,8 @@ module RuboCop
53
52
 
54
53
  def full_options
55
54
  [].tap do |result|
56
- result.concat(formatters.map { |f| ['--format', f] }.flatten)
57
- result.concat(requires.map { |r| ['--require', r] }.flatten)
55
+ result.concat(formatters.flat_map { |f| ['--format', f] })
56
+ result.concat(requires.flat_map { |r| ['--require', r] })
58
57
  result.concat(options)
59
58
  result.concat(patterns)
60
59
  end
@@ -70,7 +69,7 @@ module RuboCop
70
69
  @patterns = []
71
70
  @requires = []
72
71
  @options = []
73
- @formatters = [RuboCop::Options::DEFAULT_FORMATTER]
72
+ @formatters = []
74
73
  end
75
74
 
76
75
  def setup_subtasks(name, *args, &task_block)
@@ -78,9 +77,7 @@ module RuboCop
78
77
  desc 'Auto-correct RuboCop offenses'
79
78
 
80
79
  task(:auto_correct, *args) do |_, task_args|
81
- if task_block
82
- task_block.call(*[self, task_args].slice(0, task_block.arity))
83
- end
80
+ yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
84
81
  options = full_options.unshift('--auto-correct')
85
82
  run_cli(verbose, options)
86
83
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'net/http'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'digest/md5'
4
5
  require 'find'
@@ -8,44 +9,12 @@ require 'etc'
8
9
  module RuboCop
9
10
  # Provides functionality for caching rubocop runs.
10
11
  class ResultCache
11
- # Include the user name in the path as a simple means of avoiding write
12
- # collisions.
13
- def initialize(file, options, config_store, cache_root = nil)
14
- cache_root ||= ResultCache.cache_root(config_store)
15
- @path = File.join(cache_root, rubocop_checksum, RUBY_VERSION,
16
- relevant_options(options),
17
- file_checksum(file, config_store))
18
- end
19
-
20
- def valid?
21
- File.exist?(@path)
22
- end
23
-
24
- def load
25
- Marshal.load(IO.binread(@path))
26
- end
27
-
28
- def save(offenses, disabled_line_ranges, comments)
29
- FileUtils.mkdir_p(File.dirname(@path))
30
- preliminary_path = "#{@path}_#{rand(1_000_000_000)}"
31
- File.open(preliminary_path, 'wb') do |f|
32
- # The Hash[x.sort] call is a trick that converts a Hash with a default
33
- # block to a Hash without a default block. Thus making it possible to
34
- # dump.
35
- f.write(Marshal.dump([offenses, Hash[disabled_line_ranges.sort],
36
- comments]))
37
- end
38
- # The preliminary path is used so that if there are multiple RuboCop
39
- # processes trying to save data for the same inspected file
40
- # simultaneously, the only problem we run in to is a competition who gets
41
- # to write to the final file. The contents are the same, so no corruption
42
- # of data should occur.
43
- FileUtils.mv(preliminary_path, @path)
44
- end
12
+ NON_CHANGING = [:color, :format, :formatters, :out, :debug, :fail_level,
13
+ :cache, :fail_fast, :stdin].freeze
45
14
 
46
15
  # Remove old files so that the cache doesn't grow too big. When the
47
- # threshold MaxFilesInCache has been exceeded, the oldest 50% all the files
48
- # in the cache are removed. The reason for removing so much is that
16
+ # threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
17
+ # files in the cache are removed. The reason for removing so much is that
49
18
  # cleaning should be done relatively seldom, since there is a slight risk
50
19
  # that some other RuboCop process was just about to read the file, when
51
20
  # there's parallel execution and the cache is shared.
@@ -65,7 +34,7 @@ module RuboCop
65
34
  end
66
35
  sorted = files.sort_by { |path| File.mtime(path) }
67
36
  begin
68
- sorted[0, remove_count].each { |path| File.delete(path) }
37
+ File.delete(*sorted[0, remove_count])
69
38
  dirs.each { |dir| Dir.rmdir(dir) if Dir["#{dir}/*"].empty? }
70
39
  rescue Errno::ENOENT
71
40
  # This can happen if parallel RuboCop invocations try to remove the
@@ -75,14 +44,65 @@ module RuboCop
75
44
  end
76
45
  end
77
46
 
78
- private
79
-
80
47
  def self.cache_root(config_store)
81
48
  root = config_store.for('.')['AllCops']['CacheRootDirectory']
82
- root = File.join(Dir.tmpdir, Process.uid.to_s) if root == '/tmp'
49
+ if root == '/tmp'
50
+ tmpdir = File.realpath(Dir.tmpdir)
51
+ # Include user ID in the path to make sure the user has write access.
52
+ root = File.join(tmpdir, Process.uid.to_s)
53
+ end
83
54
  File.join(root, 'rubocop_cache')
84
55
  end
85
56
 
57
+ def initialize(file, options, config_store, cache_root = nil)
58
+ cache_root ||= ResultCache.cache_root(config_store)
59
+ @path = File.join(cache_root, rubocop_checksum, RUBY_VERSION,
60
+ relevant_options(options),
61
+ file_checksum(file, config_store))
62
+ @cached_data = CachedData.new(file)
63
+ end
64
+
65
+ def valid?
66
+ File.exist?(@path)
67
+ end
68
+
69
+ def load
70
+ @cached_data.from_json(IO.binread(@path))
71
+ end
72
+
73
+ def save(offenses)
74
+ dir = File.dirname(@path)
75
+ FileUtils.mkdir_p(dir)
76
+ preliminary_path = "#{@path}_#{rand(1_000_000_000)}"
77
+ # RuboCop must be in control of where its cached data is stored. A
78
+ # symbolic link anywhere in the cache directory tree is an indication
79
+ # that a symlink attack is being waged.
80
+ return if any_symlink?(dir)
81
+
82
+ File.open(preliminary_path, 'wb') do |f|
83
+ f.write(@cached_data.to_json(offenses))
84
+ end
85
+ # The preliminary path is used so that if there are multiple RuboCop
86
+ # processes trying to save data for the same inspected file
87
+ # simultaneously, the only problem we run in to is a competition who gets
88
+ # to write to the final file. The contents are the same, so no corruption
89
+ # of data should occur.
90
+ FileUtils.mv(preliminary_path, @path)
91
+ end
92
+
93
+ private
94
+
95
+ def any_symlink?(path)
96
+ while path != File.dirname(path)
97
+ if File.symlink?(path)
98
+ warn "Warning: #{path} is a symlink, which is not allowed."
99
+ return true
100
+ end
101
+ path = File.dirname(path)
102
+ end
103
+ false
104
+ end
105
+
86
106
  def file_checksum(file, config_store)
87
107
  Digest::MD5.hexdigest(Dir.pwd + file + IO.read(file) +
88
108
  config_store.for(file).to_s)
@@ -109,9 +129,6 @@ module RuboCop
109
129
  end
110
130
  end
111
131
 
112
- NON_CHANGING = [:color, :format, :formatters, :out, :debug, :fail_level,
113
- :cache, :fail_fast, :stdin]
114
-
115
132
  # Return the options given at invocation, minus the ones that have no
116
133
  # effect on which offenses and disabled line ranges are found, and thus
117
134
  # don't affect caching.
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module RuboCop
4
5
  # This class handles the processing of files, which includes dealing with
@@ -16,7 +17,7 @@ module RuboCop
16
17
  end
17
18
 
18
19
  attr_reader :errors, :warnings, :aborting
19
- alias_method :aborting?, :aborting
20
+ alias aborting? aborting
20
21
 
21
22
  def initialize(options, config_store)
22
23
  @options = options
@@ -76,37 +77,43 @@ module RuboCop
76
77
 
77
78
  def process_file(file)
78
79
  puts "Scanning #{file}" if @options[:debug]
80
+ file_started(file)
79
81
 
80
82
  cache = ResultCache.new(file, @options, @config_store) if cached_run?
81
83
  if cache && cache.valid?
82
- offenses, disabled_line_ranges, comments = cache.load
83
- file_started(file, disabled_line_ranges, comments)
84
+ offenses = cache.load
84
85
  else
85
- processed_source = get_processed_source(file)
86
- # Use delegators for objects sent to the formatters. These can be
87
- # updated when the file is re-inspected.
88
- disabled_line_ranges =
89
- SimpleDelegator.new(processed_source.disabled_line_ranges)
90
- comments = SimpleDelegator.new(processed_source.comments)
91
-
92
- file_started(file, disabled_line_ranges, comments)
93
- offenses = do_inspection_loop(file, processed_source,
94
- disabled_line_ranges, comments)
95
- save_in_cache(cache, offenses, processed_source)
86
+ source = get_processed_source(file)
87
+ source, offenses = do_inspection_loop(file, source)
88
+ offenses = add_unneeded_disables(file, offenses.compact.sort, source)
89
+ save_in_cache(cache, offenses)
96
90
  end
97
91
 
98
- offenses = formatter_set.file_finished(file, offenses.compact.sort.freeze)
99
-
92
+ formatter_set.file_finished(file, offenses)
100
93
  offenses
101
94
  rescue InfiniteCorrectionLoop => e
102
95
  formatter_set.file_finished(file, e.offenses.compact.sort.freeze)
103
96
  raise
104
97
  end
105
98
 
106
- def file_started(file, disabled_line_ranges, comments)
99
+ def add_unneeded_disables(file, offenses, source)
100
+ if source.disabled_line_ranges.any? &&
101
+ # Don't check unneeded disable if --only or --except option is
102
+ # given, because these options override configuration.
103
+ (@options[:except] || []).empty? && (@options[:only] || []).empty?
104
+ config = @config_store.for(file)
105
+ if config['Lint/UnneededDisable']['Enabled']
106
+ cop = Cop::Lint::UnneededDisable.new(config, @options)
107
+ cop.check(offenses, source.disabled_line_ranges, source.comments)
108
+ offenses += cop.offenses
109
+ end
110
+ end
111
+
112
+ offenses.sort.reject(&:disabled?).freeze
113
+ end
114
+
115
+ def file_started(file)
107
116
  formatter_set.file_started(file,
108
- cop_disabled_line_ranges: disabled_line_ranges,
109
- comments: comments,
110
117
  cli_options: @options,
111
118
  config_store: @config_store)
112
119
  end
@@ -121,22 +128,22 @@ module RuboCop
121
128
  # need to do that processing and can not use caching.
122
129
  !@options[:auto_gen_config] &&
123
130
  # Auto-correction needs a full run. It can not use cached results.
124
- !@options[:auto_correct]
131
+ !@options[:auto_correct] &&
132
+ # We can't cache results from code which is piped in to stdin
133
+ !@options[:stdin]
125
134
  end
126
135
 
127
- def save_in_cache(cache, offenses, processed_source)
136
+ def save_in_cache(cache, offenses)
128
137
  return unless cache
129
138
  # Caching results when a cop has crashed would prevent the crash in the
130
139
  # next run, since the cop would not be called then. We want crashes to
131
140
  # show up the same in each run.
132
141
  return if errors.any? || warnings.any?
133
142
 
134
- cache.save(offenses, processed_source.disabled_line_ranges,
135
- processed_source.comments)
143
+ cache.save(offenses)
136
144
  end
137
145
 
138
- def do_inspection_loop(file, processed_source, disabled_line_ranges,
139
- comments)
146
+ def do_inspection_loop(file, processed_source)
140
147
  offenses = []
141
148
 
142
149
  # Keep track of the state of the source. If a cop modifies the source
@@ -163,13 +170,9 @@ module RuboCop
163
170
  break unless updated_source_file
164
171
 
165
172
  processed_source = get_processed_source(file)
166
-
167
- # Update delegators with new objects.
168
- disabled_line_ranges.__setobj__(processed_source.disabled_line_ranges)
169
- comments.__setobj__(processed_source.comments)
170
173
  end
171
174
 
172
- offenses
175
+ [processed_source, offenses]
173
176
  end
174
177
 
175
178
  # Check whether a run created source identical to a previous run, which
@@ -186,6 +189,7 @@ module RuboCop
186
189
 
187
190
  def inspect_file(processed_source)
188
191
  config = @config_store.for(processed_source.path)
192
+ enable_rails_cops(config) if @options[:rails]
189
193
  team = Cop::Team.new(mobilized_cop_classes(config), config, @options)
190
194
  offenses = team.inspect_file(processed_source)
191
195
  @errors.concat(team.errors)
@@ -193,6 +197,11 @@ module RuboCop
193
197
  [offenses, team.updated_source_file?]
194
198
  end
195
199
 
200
+ def enable_rails_cops(config)
201
+ config['Rails'] ||= {}
202
+ config['Rails']['Enabled'] = true
203
+ end
204
+
196
205
  def mobilized_cop_classes(config)
197
206
  @mobilized_cop_classes ||= {}
198
207
  @mobilized_cop_classes[config.object_id] ||= begin
@@ -219,13 +228,6 @@ module RuboCop
219
228
  if style_guide_cops_only?(config)
220
229
  cop_classes.select! { |cop| config.for_cop(cop)['StyleGuide'] }
221
230
  end
222
-
223
- # filter out Rails cops unless requested
224
- cop_classes.reject!(&:rails?) unless run_rails_cops?(config)
225
- end
226
-
227
- def run_rails_cops?(config)
228
- @options[:rails] || config['AllCops']['RunRailsCops']
229
231
  end
230
232
 
231
233
  def style_guide_cops_only?(config)
@@ -234,16 +236,12 @@ module RuboCop
234
236
 
235
237
  def formatter_set
236
238
  @formatter_set ||= begin
237
- set = Formatter::FormatterSet.new
238
- pairs = @options[:formatters] || [[Options::DEFAULT_FORMATTER]]
239
+ set = Formatter::FormatterSet.new(@options)
240
+ pairs = @options[:formatters] || [['progress']]
239
241
  pairs.each do |formatter_key, output_path|
240
242
  set.add_formatter(formatter_key, output_path)
241
243
  end
242
244
  set
243
- rescue => error
244
- warn error.message
245
- $stderr.puts error.backtrace
246
- exit(1)
247
245
  end
248
246
  end
249
247
 
@@ -264,8 +262,13 @@ module RuboCop
264
262
  end
265
263
 
266
264
  def get_processed_source(file)
267
- return ProcessedSource.new(@options[:stdin], file) if @options[:stdin]
268
- ProcessedSource.from_file(file)
265
+ ruby_version = @config_store.for(file)['AllCops']['TargetRubyVersion']
266
+
267
+ if @options[:stdin]
268
+ ProcessedSource.new(@options[:stdin], ruby_version, file)
269
+ else
270
+ ProcessedSource.from_file(file, ruby_version)
271
+ end
269
272
  end
270
273
  end
271
274
  end