rubocop 0.80.1 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -29,18 +29,39 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def file_finished(file, offenses)
32
- offenses.group_by(&:cop_name).each do |cop_name, grouped_offenses|
32
+ # TODO: Returns all cops with the same behavior as
33
+ # the original rubocop-junit-formatter.
34
+ # https://github.com/mikian/rubocop-junit-formatter/blob/v0.1.4/lib/rubocop/formatter/junit_formatter.rb#L9
35
+ #
36
+ # In the future, it would be preferable to return only enabled cops.
37
+ Cop::Cop.all.each do |cop|
38
+ target_offenses = offenses_for_cop(offenses, cop)
39
+
40
+ next unless relevant_for_output?(options, target_offenses)
41
+
33
42
  REXML::Element.new('testcase', @testsuite).tap do |testcase|
34
- testcase.attributes['classname'] = file.gsub(
35
- /\.rb\Z/, ''
36
- ).gsub("#{Dir.pwd}/", '').tr('/', '.')
37
- testcase.attributes['name'] = cop_name
43
+ testcase.attributes['classname'] = classname_attribute_value(file)
44
+ testcase.attributes['name'] = cop.cop_name
38
45
 
39
- add_failure_to(testcase, grouped_offenses, cop_name)
46
+ add_failure_to(testcase, target_offenses, cop.cop_name)
40
47
  end
41
48
  end
42
49
  end
43
50
 
51
+ def relevant_for_output?(options, target_offenses)
52
+ !options[:display_only_failed] || target_offenses.any?
53
+ end
54
+
55
+ def offenses_for_cop(all_offenses, cop)
56
+ all_offenses.select do |offense|
57
+ offense.cop_name == cop.cop_name
58
+ end
59
+ end
60
+
61
+ def classname_attribute_value(file)
62
+ file.gsub(/\.rb\Z/, '').gsub("#{Dir.pwd}/", '').tr('/', '.')
63
+ end
64
+
44
65
  def finished(_inspected_files)
45
66
  @document.write(output, 2)
46
67
  end
@@ -69,7 +69,7 @@ module RuboCop
69
69
  regex = /#{Regexp.quote(PACMAN)}|#{Regexp.quote(PACDOT)}/
70
70
  @progress_line = @progress_line.sub(regex, character)
71
71
  output.printf("%<line>s\r", line: @progress_line)
72
- return unless @progress_line[-1] =~ /ᗣ|\./
72
+ return unless /ᗣ|\./.match?(@progress_line[-1])
73
73
 
74
74
  @repetitions += 1
75
75
  output.puts
@@ -56,7 +56,7 @@ module RuboCop
56
56
 
57
57
  report_line(offense.location)
58
58
  report_highlighted_area(offense.highlighted_area)
59
- rescue IndexError # rubocop:disable Lint/SuppressedException
59
+ rescue IndexError
60
60
  # range is not on a valid line; perhaps the source file is empty
61
61
  end
62
62
  end
@@ -133,7 +133,7 @@ module RuboCop
133
133
  # @see https://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html
134
134
  # @see https://git.io/vMCXh Emacs handling in Ruby's parse.y
135
135
  class EmacsComment < EditorComment
136
- FORMAT = /\-\*\-(.+)\-\*\-/.freeze
136
+ FORMAT = /-\*-(.+)-\*-/.freeze
137
137
  SEPARATOR = ';'
138
138
  OPERATOR = ':'
139
139
 
@@ -3,19 +3,22 @@
3
3
  module RuboCop
4
4
  # Common functionality for finding names that are similar to a given name.
5
5
  module NameSimilarity
6
- MINIMUM_SIMILARITY_TO_SUGGEST = 0.9
6
+ module_function
7
7
 
8
- def find_similar_name(target_name, scope)
9
- names = collect_variable_like_names(scope)
8
+ def find_similar_name(target_name, names)
9
+ similar_names = find_similar_names(target_name, names)
10
+
11
+ similar_names.first
12
+ end
13
+
14
+ def find_similar_names(target_name, names)
15
+ names = names.dup
10
16
  names.delete(target_name)
11
17
 
12
- scores = names.each_with_object({}) do |name, hash|
13
- score = StringUtil.similarity(target_name, name)
14
- hash[name] = score if score >= MINIMUM_SIMILARITY_TO_SUGGEST
15
- end
18
+ spell_checker = DidYouMean::SpellChecker.new(dictionary: names)
19
+ similar_names = spell_checker.correct(target_name)
16
20
 
17
- most_similar_name, _max_score = scores.max_by { |_, score| score }
18
- most_similar_name
21
+ similar_names
19
22
  end
20
23
  end
21
24
  end
@@ -83,6 +83,12 @@ module RuboCop
83
83
 
84
84
  def add_cop_selection_csv_option(option, opts)
85
85
  option(opts, "--#{option} [COP1,COP2,...]") do |list|
86
+ unless list
87
+ message = "--#{option} argument should be [COP1,COP2,...]."
88
+
89
+ raise OptionArgumentError, message
90
+ end
91
+
86
92
  @options[:"#{option}"] =
87
93
  if list.empty?
88
94
  ['']
@@ -97,6 +103,7 @@ module RuboCop
97
103
  def add_configuration_options(opts)
98
104
  option(opts, '-c', '--config FILE')
99
105
  option(opts, '--force-exclusion')
106
+ option(opts, '--only-recognized-file-types')
100
107
  option(opts, '--ignore-parent-exclusion')
101
108
  option(opts, '--force-default-config')
102
109
  add_auto_gen_options(opts)
@@ -136,6 +143,8 @@ module RuboCop
136
143
  @options[:output_path] = path
137
144
  end
138
145
  end
146
+
147
+ option(opts, '--display-only-failed')
139
148
  end
140
149
 
141
150
  def add_severity_option(opts)
@@ -154,6 +163,7 @@ module RuboCop
154
163
  end
155
164
  end
156
165
 
166
+ # rubocop:disable Metrics/MethodLength
157
167
  def add_boolean_flags(opts)
158
168
  option(opts, '-F', '--fail-fast')
159
169
  option(opts, '-C', '--cache FLAG')
@@ -162,6 +172,8 @@ module RuboCop
162
172
  option(opts, '-E', '--extra-details')
163
173
  option(opts, '-S', '--display-style-guide')
164
174
  option(opts, '-a', '--auto-correct')
175
+ option(opts, '--disable-pending-cops')
176
+ option(opts, '--enable-pending-cops')
165
177
  option(opts, '--ignore-disable-comments')
166
178
 
167
179
  option(opts, '--safe')
@@ -172,6 +184,7 @@ module RuboCop
172
184
  option(opts, '-V', '--verbose-version')
173
185
  option(opts, '-P', '--parallel')
174
186
  end
187
+ # rubocop:enable Metrics/MethodLength
175
188
 
176
189
  def add_aliases(opts)
177
190
  option(opts, '-l', '--lint') do
@@ -237,10 +250,7 @@ module RuboCop
237
250
  def format_message_from(name, cop_names)
238
251
  message = 'Unrecognized cop or department: %<name>s.'
239
252
  message_with_candidate = "%<message>s\nDid you mean? %<candidate>s"
240
- corrections = cop_names.select do |cn|
241
- score = StringUtil.similarity(cn, name)
242
- score >= NameSimilarity::MINIMUM_SIMILARITY_TO_SUGGEST
243
- end.sort
253
+ corrections = NameSimilarity.find_similar_names(name, cop_names)
244
254
 
245
255
  if corrections.empty?
246
256
  format(message, name: name)
@@ -267,9 +277,7 @@ module RuboCop
267
277
  raise OptionArgumentError, 'Lint/RedundantCopDisableDirective cannot ' \
268
278
  'be used with --only.'
269
279
  end
270
- if except_syntax?
271
- raise OptionArgumentError, 'Syntax checking cannot be turned off.'
272
- end
280
+ raise OptionArgumentError, 'Syntax checking cannot be turned off.' if except_syntax?
273
281
  unless boolean_or_empty_cache?
274
282
  raise OptionArgumentError, '-C/--cache argument must be true or false'
275
283
  end
@@ -280,6 +288,7 @@ module RuboCop
280
288
  end
281
289
  validate_auto_gen_config
282
290
  validate_auto_correct
291
+ validate_display_only_failed
283
292
  validate_parallel
284
293
 
285
294
  return if incompatible_options.size <= 1
@@ -303,13 +312,20 @@ module RuboCop
303
312
  end
304
313
  end
305
314
 
315
+ def validate_display_only_failed
316
+ return unless @options.key?(:display_only_failed)
317
+ return if @options[:format] == 'junit'
318
+
319
+ raise OptionArgumentError,
320
+ format('--display-only-failed can only be used together with --format junit.')
321
+ end
322
+
306
323
  def validate_auto_correct
307
324
  return if @options.key?(:auto_correct)
308
325
  return unless @options.key?(:disable_uncorrectable)
309
326
 
310
327
  raise OptionArgumentError,
311
- format('--%<flag>s can only be used together with --auto-correct.',
312
- flag: '--disable-uncorrectable')
328
+ format('--disable-uncorrectable can only be used together with --auto-correct.')
313
329
  end
314
330
 
315
331
  def validate_parallel
@@ -362,7 +378,7 @@ module RuboCop
362
378
  end
363
379
 
364
380
  def validate_exclude_limit_option
365
- return if @options[:exclude_limit] =~ /^\d+$/
381
+ return if /^\d+$/.match?(@options[:exclude_limit])
366
382
 
367
383
  # Emulate OptionParser's behavior to make failures consistent regardless
368
384
  # of option order.
@@ -373,7 +389,6 @@ module RuboCop
373
389
  # This module contains help texts for command line options.
374
390
  module OptionsHelp
375
391
  MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
376
- # rubocop:disable Layout/LineLength
377
392
  FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
378
393
 
379
394
  TEXT = {
@@ -405,6 +420,9 @@ module RuboCop
405
420
  force_exclusion: ['Force excluding files specified in the',
406
421
  'configuration `Exclude` even if they are',
407
422
  'explicitly passed as arguments.'],
423
+ only_recognized_file_types: ['Inspect files given on the command line only if',
424
+ 'they are listed in AllCops/Include parameters',
425
+ 'of user configuration or default configuration.'],
408
426
  ignore_disable_comments: ['Run cops even when they are disabled locally',
409
427
  'with a comment.'],
410
428
  ignore_parent_exclusion: ['Prevent from inheriting AllCops/Exclude from',
@@ -423,6 +441,8 @@ module RuboCop
423
441
  'if no format is specified.'],
424
442
  fail_level: ['Minimum severity (A/R/C/W/E/F) for exit',
425
443
  'with error code.'],
444
+ display_only_failed: ['Only output offense messages. Omit passing',
445
+ 'cops. Only valid for --format junit.'],
426
446
  display_only_fail_level_offenses:
427
447
  ['Only output offense messages at',
428
448
  'the specified --fail-level or above'],
@@ -438,7 +458,9 @@ module RuboCop
438
458
  debug: 'Display debug info.',
439
459
  display_cop_names: ['Display cop names in offense messages.',
440
460
  'Default is true.'],
461
+ disable_pending_cops: 'Run without pending cops.',
441
462
  display_style_guide: 'Display style guide URLs in offense messages.',
463
+ enable_pending_cops: 'Run with pending cops.',
442
464
  extra_details: 'Display extra details in offense messages.',
443
465
  lint: 'Run only lint cops.',
444
466
  safe: 'Run only safe cops.',
@@ -455,6 +477,5 @@ module RuboCop
455
477
  'reports. This is useful for editor integration.'],
456
478
  init: 'Generate a .rubocop.yml file in the current directory.'
457
479
  }.freeze
458
- # rubocop:enable Layout/LineLength
459
480
  end
460
481
  end
@@ -56,9 +56,7 @@ module RuboCop
56
56
  def generate_request(uri)
57
57
  request = Net::HTTP::Get.new(uri.request_uri)
58
58
 
59
- if cache_path_exists?
60
- request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822
61
- end
59
+ request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822 if cache_path_exists?
62
60
 
63
61
  yield request
64
62
  end
@@ -33,16 +33,14 @@ module RuboCop
33
33
 
34
34
  def requires_file_removal?(file_count, config_store)
35
35
  file_count > 1 &&
36
- file_count > config_store.for('.').for_all_cops['MaxFilesInCache']
36
+ file_count > config_store.for_dir('.').for_all_cops['MaxFilesInCache']
37
37
  end
38
38
 
39
39
  def remove_oldest_files(files, dirs, cache_root, verbose)
40
40
  # Add 1 to half the number of files, so that we remove the file if
41
41
  # there's only 1 left.
42
42
  remove_count = 1 + files.length / 2
43
- if verbose
44
- puts "Removing the #{remove_count} oldest files from #{cache_root}"
45
- end
43
+ puts "Removing the #{remove_count} oldest files from #{cache_root}" if verbose
46
44
  sorted = files.sort_by { |path| File.mtime(path) }
47
45
  remove_files(sorted, dirs, remove_count)
48
46
  rescue Errno::ENOENT
@@ -62,7 +60,7 @@ module RuboCop
62
60
  end
63
61
 
64
62
  def self.cache_root(config_store)
65
- root = config_store.for('.').for_all_cops['CacheRootDirectory']
63
+ root = config_store.for_dir('.').for_all_cops['CacheRootDirectory']
66
64
  root ||= if ENV.key?('XDG_CACHE_HOME')
67
65
  # Include user ID in the path to make sure the user has write
68
66
  # access.
@@ -74,7 +72,7 @@ module RuboCop
74
72
  end
75
73
 
76
74
  def self.allow_symlinks_in_cache_location?(config_store)
77
- config_store.for('.').for_all_cops['AllowSymlinksInCacheRootDirectory']
75
+ config_store.for_dir('.').for_all_cops['AllowSymlinksInCacheRootDirectory']
78
76
  end
79
77
 
80
78
  def initialize(file, team, options, config_store, cache_root = nil)
@@ -145,7 +143,7 @@ module RuboCop
145
143
  digester = Digest::SHA1.new
146
144
  mode = File.stat(file).mode
147
145
  digester.update(
148
- "#{file}#{mode}#{config_store.for(file).signature}"
146
+ "#{file}#{mode}#{config_store.for_file(file).signature}"
149
147
  )
150
148
  digester.file(file)
151
149
  digester.hexdigest
@@ -6,7 +6,7 @@ require 'tempfile'
6
6
  module CopHelper
7
7
  extend RSpec::SharedContext
8
8
 
9
- let(:ruby_version) { 2.3 }
9
+ let(:ruby_version) { 2.4 }
10
10
  let(:rails_version) { false }
11
11
 
12
12
  def inspect_source_file(source)
@@ -48,32 +48,9 @@ module CopHelper
48
48
  corrector.rewrite
49
49
  end
50
50
 
51
- def autocorrect_source_with_loop(source, file = nil)
52
- cnt = 0
53
- loop do
54
- cop.instance_variable_set(:@corrections, [])
55
- new_source = autocorrect_source(source, file)
56
- return new_source if new_source == source
57
-
58
- source = new_source
59
- cnt += 1
60
- if cnt > RuboCop::Runner::MAX_ITERATIONS
61
- raise RuboCop::Runner::InfiniteCorrectionLoop.new(file, [])
62
- end
63
- end
64
- end
65
-
66
51
  def _investigate(cop, processed_source)
67
- forces = RuboCop::Cop::Force.all.each_with_object([]) do |klass, instances|
68
- next unless cop.join_force?(klass)
69
-
70
- instances << klass.new([cop])
71
- end
72
-
73
- commissioner =
74
- RuboCop::Cop::Commissioner.new([cop], forces, raise_error: true)
75
- commissioner.investigate(processed_source)
76
- commissioner
52
+ team = RuboCop::Cop::Team.new([cop], nil, raise_error: true)
53
+ team.inspect_file(processed_source)
77
54
  end
78
55
  end
79
56
 
@@ -71,9 +71,27 @@ module RuboCop
71
71
  # RUBY
72
72
  #
73
73
  # expect_no_corrections
74
+ #
75
+ # If your code has variables of different lengths, you can use `%{foo}`
76
+ # and `^{foo}` to format your template:
77
+ #
78
+ # %w[raise fail].each do |keyword|
79
+ # expect_offense(<<~RUBY, keyword: keyword)
80
+ # %{keyword}(RuntimeError, msg)
81
+ # ^{keyword}^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed.
82
+ # RUBY
74
83
  module ExpectOffense
84
+ def format_offense(source, **replacements)
85
+ replacements.each do |keyword, value|
86
+ source = source.gsub("%{#{keyword}}", value)
87
+ .gsub("^{#{keyword}}", '^' * value.size)
88
+ end
89
+ source
90
+ end
91
+
75
92
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
76
- def expect_offense(source, file = nil)
93
+ def expect_offense(source, file = nil, **replacements)
94
+ source = format_offense(source, **replacements)
77
95
  RuboCop::Formatter::DisabledConfigFormatter
78
96
  .config_to_allow_offenses = {}
79
97
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
@@ -88,9 +106,7 @@ module RuboCop
88
106
  @processed_source = parse_source(expected_annotations.plain_source,
89
107
  file)
90
108
 
91
- unless @processed_source.valid_syntax?
92
- raise 'Error parsing example code'
93
- end
109
+ raise 'Error parsing example code' unless @processed_source.valid_syntax?
94
110
 
95
111
  _investigate(cop, @processed_source)
96
112
  actual_annotations =
@@ -98,24 +114,38 @@ module RuboCop
98
114
 
99
115
  expect(actual_annotations.to_s).to eq(expected_annotations.to_s)
100
116
  end
101
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
102
117
 
103
- def expect_correction(correction)
104
- unless @processed_source
105
- raise '`expect_correction` must follow `expect_offense`'
106
- end
118
+ def expect_correction(correction, loop: false)
119
+ raise '`expect_correction` must follow `expect_offense`' unless @processed_source
107
120
 
108
- corrector =
109
- RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
110
- new_source = corrector.rewrite
121
+ iteration = 0
122
+ new_source = loop do
123
+ iteration += 1
124
+
125
+ corrector =
126
+ RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
127
+ corrected_source = corrector.rewrite
128
+
129
+ break corrected_source unless loop
130
+ break corrected_source if cop.corrections.empty?
131
+
132
+ if iteration > RuboCop::Runner::MAX_ITERATIONS
133
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
134
+ end
135
+
136
+ # Prepare for next loop
137
+ cop.instance_variable_set(:@corrections, [])
138
+ @processed_source = parse_source(corrected_source,
139
+ @processed_source.path)
140
+ _investigate(cop, @processed_source)
141
+ end
111
142
 
112
143
  expect(new_source).to eq(correction)
113
144
  end
145
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
114
146
 
115
147
  def expect_no_corrections
116
- unless @processed_source
117
- raise '`expect_no_corrections` must follow `expect_offense`'
118
- end
148
+ raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
119
149
 
120
150
  return if cop.corrections.empty?
121
151
 
@@ -153,7 +183,7 @@ module RuboCop
153
183
  annotations = []
154
184
 
155
185
  annotated_source.each_line do |source_line|
156
- if source_line =~ ANNOTATION_PATTERN
186
+ if ANNOTATION_PATTERN.match?(source_line)
157
187
  annotations << [source.size, source_line]
158
188
  else
159
189
  source << source_line