rubocop 0.89.1 → 0.90.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +79 -11
  4. data/lib/rubocop.rb +13 -0
  5. data/lib/rubocop/cached_data.rb +1 -0
  6. data/lib/rubocop/cli/command.rb +1 -0
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -0
  8. data/lib/rubocop/cli/command/base.rb +1 -0
  9. data/lib/rubocop/cli/command/execute_runner.rb +1 -0
  10. data/lib/rubocop/cli/command/init_dotfile.rb +1 -0
  11. data/lib/rubocop/cli/command/show_cops.rb +1 -0
  12. data/lib/rubocop/cli/command/version.rb +1 -0
  13. data/lib/rubocop/cli/environment.rb +1 -0
  14. data/lib/rubocop/comment_config.rb +5 -0
  15. data/lib/rubocop/config_loader.rb +17 -6
  16. data/lib/rubocop/config_loader_resolver.rb +1 -0
  17. data/lib/rubocop/config_obsoletion.rb +1 -0
  18. data/lib/rubocop/config_validator.rb +3 -0
  19. data/lib/rubocop/cop/base.rb +23 -0
  20. data/lib/rubocop/cop/bundler/gem_comment.rb +7 -3
  21. data/lib/rubocop/cop/commissioner.rb +47 -7
  22. data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -4
  23. data/lib/rubocop/cop/correctors/condition_corrector.rb +3 -5
  24. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +9 -10
  25. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  26. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +8 -3
  27. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -8
  28. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +4 -9
  29. data/lib/rubocop/cop/correctors/punctuation_corrector.rb +8 -10
  30. data/lib/rubocop/cop/documentation.rb +22 -0
  31. data/lib/rubocop/cop/generator.rb +1 -0
  32. data/lib/rubocop/cop/layout/block_alignment.rb +23 -19
  33. data/lib/rubocop/cop/layout/class_structure.rb +10 -9
  34. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +4 -6
  35. data/lib/rubocop/cop/layout/condition_position.rb +13 -15
  36. data/lib/rubocop/cop/layout/def_end_alignment.rb +7 -4
  37. data/lib/rubocop/cop/layout/dot_position.rb +21 -17
  38. data/lib/rubocop/cop/layout/empty_comment.rb +30 -23
  39. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +19 -16
  40. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +13 -13
  41. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +144 -0
  42. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +21 -23
  43. data/lib/rubocop/cop/layout/empty_lines.rb +6 -7
  44. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +4 -6
  45. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +7 -8
  46. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +3 -6
  47. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +2 -5
  48. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -5
  49. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -5
  50. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -5
  51. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +2 -5
  52. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +2 -5
  53. data/lib/rubocop/cop/layout/end_alignment.rb +6 -7
  54. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +2 -5
  55. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +2 -5
  56. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -8
  57. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +2 -5
  58. data/lib/rubocop/cop/layout/hash_alignment.rb +17 -20
  59. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +15 -14
  60. data/lib/rubocop/cop/layout/heredoc_indentation.rb +14 -11
  61. data/lib/rubocop/cop/layout/initial_indentation.rb +6 -7
  62. data/lib/rubocop/cop/layout/leading_comment_space.rb +11 -9
  63. data/lib/rubocop/cop/layout/leading_empty_lines.rb +6 -11
  64. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +2 -5
  65. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +2 -5
  66. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +10 -14
  67. data/lib/rubocop/cop/layout/multiline_block_layout.rb +21 -19
  68. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +2 -5
  69. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +2 -5
  70. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +5 -9
  71. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +2 -5
  72. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +2 -5
  73. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +18 -21
  74. data/lib/rubocop/cop/layout/space_after_colon.rb +11 -7
  75. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -5
  76. data/lib/rubocop/cop/layout/space_after_method_name.rb +5 -6
  77. data/lib/rubocop/cop/layout/space_after_not.rb +9 -11
  78. data/lib/rubocop/cop/layout/space_after_semicolon.rb +2 -5
  79. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +20 -15
  80. data/lib/rubocop/cop/layout/space_around_keyword.rb +17 -18
  81. data/lib/rubocop/cop/layout/space_around_operators.rb +17 -16
  82. data/lib/rubocop/cop/layout/space_before_block_braces.rb +23 -22
  83. data/lib/rubocop/cop/layout/space_before_comma.rb +3 -5
  84. data/lib/rubocop/cop/layout/space_before_comment.rb +10 -7
  85. data/lib/rubocop/cop/layout/space_before_first_arg.rb +7 -7
  86. data/lib/rubocop/cop/layout/space_before_semicolon.rb +2 -5
  87. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -17
  88. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +13 -16
  89. data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +3 -8
  90. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +17 -16
  91. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +16 -19
  92. data/lib/rubocop/cop/layout/space_inside_parens.rb +9 -14
  93. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +5 -10
  94. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +8 -17
  95. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +13 -16
  96. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +10 -11
  97. data/lib/rubocop/cop/layout/trailing_empty_lines.rb +10 -15
  98. data/lib/rubocop/cop/layout/trailing_whitespace.rb +11 -11
  99. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
  100. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  101. data/lib/rubocop/cop/lint/duplicate_require.rb +41 -0
  102. data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +0 -11
  103. data/lib/rubocop/cop/lint/empty_file.rb +53 -0
  104. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  105. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +2 -35
  106. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +9 -19
  107. data/lib/rubocop/cop/lint/percent_string_array.rb +8 -12
  108. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -4
  109. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  110. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +57 -0
  111. data/lib/rubocop/cop/lint/useless_method_definition.rb +77 -0
  112. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -0
  113. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -0
  114. data/lib/rubocop/cop/mixin/alignment.rb +3 -0
  115. data/lib/rubocop/cop/mixin/allowed_methods.rb +2 -0
  116. data/lib/rubocop/cop/mixin/annotation_comment.rb +5 -0
  117. data/lib/rubocop/cop/mixin/check_line_breakable.rb +16 -7
  118. data/lib/rubocop/cop/mixin/comments_help.rb +54 -0
  119. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +8 -7
  120. data/lib/rubocop/cop/mixin/empty_parameter.rb +3 -1
  121. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +3 -1
  122. data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -1
  123. data/lib/rubocop/cop/mixin/hash_transform_method.rb +17 -0
  124. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +3 -1
  125. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +12 -10
  126. data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -2
  127. data/lib/rubocop/cop/mixin/percent_array.rb +14 -3
  128. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +1 -1
  129. data/lib/rubocop/cop/mixin/rescue_node.rb +10 -1
  130. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +4 -3
  131. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +4 -3
  132. data/lib/rubocop/cop/mixin/surrounding_space.rb +8 -4
  133. data/lib/rubocop/cop/mixin/trailing_comma.rb +7 -7
  134. data/lib/rubocop/cop/offense.rb +1 -0
  135. data/lib/rubocop/cop/severity.rb +0 -8
  136. data/lib/rubocop/cop/style/case_equality.rb +8 -3
  137. data/lib/rubocop/cop/style/case_like_if.rb +20 -4
  138. data/lib/rubocop/cop/style/class_methods_definitions.rb +131 -0
  139. data/lib/rubocop/cop/style/combinable_loops.rb +89 -0
  140. data/lib/rubocop/cop/style/empty_block_parameter.rb +9 -10
  141. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +9 -10
  142. data/lib/rubocop/cop/style/guard_clause.rb +1 -0
  143. data/lib/rubocop/cop/style/hash_syntax.rb +6 -5
  144. data/lib/rubocop/cop/style/hash_transform_keys.rb +14 -1
  145. data/lib/rubocop/cop/style/hash_transform_values.rb +14 -1
  146. data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
  147. data/lib/rubocop/cop/style/keyword_parameters_order.rb +58 -0
  148. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +10 -1
  149. data/lib/rubocop/cop/style/multiline_when_then.rb +2 -2
  150. data/lib/rubocop/cop/style/negated_if.rb +6 -6
  151. data/lib/rubocop/cop/style/negated_unless.rb +6 -6
  152. data/lib/rubocop/cop/style/negated_while.rb +7 -15
  153. data/lib/rubocop/cop/style/nested_modifier.rb +10 -13
  154. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +11 -11
  155. data/lib/rubocop/cop/style/nested_ternary_operator.rb +14 -16
  156. data/lib/rubocop/cop/style/next.rb +10 -14
  157. data/lib/rubocop/cop/style/nil_comparison.rb +11 -11
  158. data/lib/rubocop/cop/style/non_nil_check.rb +32 -26
  159. data/lib/rubocop/cop/style/not.rb +19 -26
  160. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +4 -9
  161. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -11
  162. data/lib/rubocop/cop/style/one_line_conditional.rb +71 -23
  163. data/lib/rubocop/cop/style/option_hash.rb +1 -1
  164. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  165. data/lib/rubocop/cop/style/or_assignment.rb +13 -10
  166. data/lib/rubocop/cop/style/parallel_assignment.rb +14 -14
  167. data/lib/rubocop/cop/style/parentheses_around_condition.rb +6 -6
  168. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +13 -19
  169. data/lib/rubocop/cop/style/percent_q_literals.rb +8 -10
  170. data/lib/rubocop/cop/style/perl_backrefs.rb +8 -10
  171. data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -14
  172. data/lib/rubocop/cop/style/proc.rb +6 -6
  173. data/lib/rubocop/cop/style/raise_args.rb +13 -24
  174. data/lib/rubocop/cop/style/random_with_offset.rb +15 -16
  175. data/lib/rubocop/cop/style/redundant_assignment.rb +8 -10
  176. data/lib/rubocop/cop/style/redundant_begin.rb +7 -9
  177. data/lib/rubocop/cop/style/redundant_capital_w.rb +6 -9
  178. data/lib/rubocop/cop/style/redundant_condition.rb +5 -6
  179. data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -12
  180. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +8 -8
  181. data/lib/rubocop/cop/style/redundant_freeze.rb +3 -6
  182. data/lib/rubocop/cop/style/redundant_interpolation.rb +25 -24
  183. data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -9
  184. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +6 -13
  185. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +5 -14
  186. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  187. data/lib/rubocop/cop/style/redundant_self_assignment.rb +116 -0
  188. data/lib/rubocop/cop/style/regexp_literal.rb +10 -21
  189. data/lib/rubocop/cop/style/rescue_modifier.rb +29 -9
  190. data/lib/rubocop/cop/style/return_nil.rb +5 -5
  191. data/lib/rubocop/cop/style/safe_navigation.rb +13 -12
  192. data/lib/rubocop/cop/style/sample.rb +10 -13
  193. data/lib/rubocop/cop/style/self_assignment.rb +26 -22
  194. data/lib/rubocop/cop/style/semicolon.rb +6 -9
  195. data/lib/rubocop/cop/style/send.rb +2 -2
  196. data/lib/rubocop/cop/style/signal_exception.rb +21 -19
  197. data/lib/rubocop/cop/style/single_line_block_params.rb +4 -2
  198. data/lib/rubocop/cop/style/single_line_methods.rb +17 -16
  199. data/lib/rubocop/cop/style/slicing_with_range.rb +4 -7
  200. data/lib/rubocop/cop/style/sole_nested_conditional.rb +66 -0
  201. data/lib/rubocop/cop/style/special_global_vars.rb +10 -15
  202. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +17 -21
  203. data/lib/rubocop/cop/style/stderr_puts.rb +4 -6
  204. data/lib/rubocop/cop/style/string_hash_keys.rb +6 -7
  205. data/lib/rubocop/cop/style/string_methods.rb +7 -17
  206. data/lib/rubocop/cop/style/strip.rb +8 -14
  207. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -6
  208. data/lib/rubocop/cop/style/symbol_array.rb +5 -16
  209. data/lib/rubocop/cop/style/symbol_literal.rb +4 -6
  210. data/lib/rubocop/cop/style/symbol_proc.rb +14 -18
  211. data/lib/rubocop/cop/style/ternary_parentheses.rb +21 -20
  212. data/lib/rubocop/cop/style/trailing_body_on_class.rb +3 -6
  213. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +4 -7
  214. data/lib/rubocop/cop/style/trailing_body_on_module.rb +3 -6
  215. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +2 -5
  216. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +2 -5
  217. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +7 -6
  218. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +2 -5
  219. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +8 -17
  220. data/lib/rubocop/cop/style/trivial_accessors.rb +26 -30
  221. data/lib/rubocop/cop/style/unless_else.rb +5 -8
  222. data/lib/rubocop/cop/style/unpack_first.rb +4 -8
  223. data/lib/rubocop/cop/style/variable_interpolation.rb +7 -10
  224. data/lib/rubocop/cop/style/when_then.rb +4 -6
  225. data/lib/rubocop/cop/style/while_until_do.rb +6 -16
  226. data/lib/rubocop/cop/style/while_until_modifier.rb +6 -20
  227. data/lib/rubocop/cop/style/word_array.rb +5 -23
  228. data/lib/rubocop/cop/style/yoda_condition.rb +4 -15
  229. data/lib/rubocop/cop/style/zero_length_predicate.rb +11 -13
  230. data/lib/rubocop/cop/team.rb +1 -0
  231. data/lib/rubocop/cop/util.rb +1 -1
  232. data/lib/rubocop/cop/utils/format_string.rb +3 -5
  233. data/lib/rubocop/cop/variable_force.rb +2 -0
  234. data/lib/rubocop/cops_documentation_generator.rb +4 -2
  235. data/lib/rubocop/core_ext/string.rb +1 -1
  236. data/lib/rubocop/ext/regexp_node.rb +46 -0
  237. data/lib/rubocop/file_finder.rb +1 -0
  238. data/lib/rubocop/formatter/auto_gen_config_formatter.rb +2 -1
  239. data/lib/rubocop/formatter/html_formatter.rb +2 -0
  240. data/lib/rubocop/formatter/progress_formatter.rb +2 -1
  241. data/lib/rubocop/formatter/quiet_formatter.rb +1 -1
  242. data/lib/rubocop/formatter/simple_text_formatter.rb +36 -6
  243. data/lib/rubocop/name_similarity.rb +1 -0
  244. data/lib/rubocop/options.rb +3 -0
  245. data/lib/rubocop/remote_config.rb +1 -0
  246. data/lib/rubocop/result_cache.rb +1 -0
  247. data/lib/rubocop/rspec/cop_helper.rb +4 -1
  248. data/lib/rubocop/rspec/expect_offense.rb +10 -5
  249. data/lib/rubocop/rspec/shared_contexts.rb +12 -0
  250. data/lib/rubocop/runner.rb +1 -0
  251. data/lib/rubocop/string_interpreter.rb +3 -0
  252. data/lib/rubocop/target_finder.rb +1 -0
  253. data/lib/rubocop/target_ruby.rb +6 -0
  254. data/lib/rubocop/version.rb +2 -1
  255. data/lib/rubocop/yaml_duplication_checker.rb +1 -0
  256. metadata +15 -2
@@ -90,9 +90,11 @@ module RuboCop
90
90
  end
91
91
 
92
92
  # Make Kernel#binding public.
93
+ # rubocop:disable Lint/UselessMethodDefinition
93
94
  def binding
94
95
  super
95
96
  end
97
+ # rubocop:enable Lint/UselessMethodDefinition
96
98
 
97
99
  def decorated_message(offense)
98
100
  offense.message.gsub(/`(.+?)`/) do
@@ -45,7 +45,8 @@ module RuboCop
45
45
 
46
46
  report_summary(inspected_files.size,
47
47
  @total_offense_count,
48
- @total_correction_count)
48
+ @total_correction_count,
49
+ @total_correctable_count)
49
50
  end
50
51
 
51
52
  def report_file_as_mark(offenses)
@@ -5,7 +5,7 @@ module RuboCop
5
5
  # If no offenses are found, no output is displayed.
6
6
  # Otherwise, SimpleTextFormatter's output is displayed.
7
7
  class QuietFormatter < SimpleTextFormatter
8
- def report_summary(file_count, offense_count, correction_count)
8
+ def report_summary(file_count, offense_count, correction_count, correctable_count)
9
9
  super unless offense_count.zero?
10
10
  end
11
11
  end
@@ -23,6 +23,7 @@ module RuboCop
23
23
  def started(_target_files)
24
24
  @total_offense_count = 0
25
25
  @total_correction_count = 0
26
+ @total_correctable_count = 0
26
27
  end
27
28
 
28
29
  def file_finished(file, offenses)
@@ -35,7 +36,8 @@ module RuboCop
35
36
  def finished(inspected_files)
36
37
  report_summary(inspected_files.count,
37
38
  @total_offense_count,
38
- @total_correction_count)
39
+ @total_correction_count,
40
+ @total_correctable_count)
39
41
  end
40
42
 
41
43
  def report_file(file, offenses)
@@ -52,11 +54,13 @@ module RuboCop
52
54
  end
53
55
  end
54
56
 
55
- def report_summary(file_count, offense_count, correction_count)
57
+ def report_summary(file_count, offense_count, correction_count, correctable_count)
56
58
  report = Report.new(file_count,
57
59
  offense_count,
58
60
  correction_count,
59
- rainbow)
61
+ correctable_count,
62
+ rainbow,
63
+ safe_auto_correct: @options[:safe_auto_correct])
60
64
 
61
65
  output.puts
62
66
  output.puts report.summary
@@ -66,7 +70,9 @@ module RuboCop
66
70
 
67
71
  def count_stats(offenses)
68
72
  @total_offense_count += offenses.count
69
- @total_correction_count += offenses.count(&:corrected?)
73
+ corrected = offenses.count(&:corrected?)
74
+ @total_correction_count += corrected
75
+ @total_correctable_count += offenses.count(&:correctable?) - corrected
70
76
  end
71
77
 
72
78
  def colored_severity_code(offense)
@@ -96,16 +102,30 @@ module RuboCop
96
102
  include Colorizable
97
103
  include TextUtil
98
104
 
99
- def initialize(file_count, offense_count, correction_count, rainbow)
105
+ # rubocop:disable Metrics/ParameterLists
106
+ def initialize(
107
+ file_count, offense_count, correction_count, correctable_count, rainbow,
108
+ safe_auto_correct: false
109
+ )
100
110
  @file_count = file_count
101
111
  @offense_count = offense_count
102
112
  @correction_count = correction_count
113
+ @correctable_count = correctable_count
103
114
  @rainbow = rainbow
115
+ @safe_auto_correct = safe_auto_correct
104
116
  end
117
+ # rubocop:enable Metrics/ParameterLists
105
118
 
106
119
  def summary
107
120
  if @correction_count.positive?
108
- "#{files} inspected, #{offenses} detected, #{corrections} corrected"
121
+ if @correctable_count.positive?
122
+ "#{files} inspected, #{offenses} detected, #{corrections} corrected,"\
123
+ " #{correctable}"
124
+ else
125
+ "#{files} inspected, #{offenses} detected, #{corrections} corrected"
126
+ end
127
+ elsif @correctable_count.positive?
128
+ "#{files} inspected, #{offenses} detected, #{correctable}"
109
129
  else
110
130
  "#{files} inspected, #{offenses} detected"
111
131
  end
@@ -132,6 +152,16 @@ module RuboCop
132
152
 
133
153
  colorize(text, color)
134
154
  end
155
+
156
+ def correctable
157
+ if @safe_auto_correct
158
+ text = pluralize(@correctable_count, 'more offense')
159
+ "#{colorize(text, :yellow)} can be corrected with `rubocop -A`"
160
+ else
161
+ text = pluralize(@correctable_count, 'offense')
162
+ "#{colorize(text, :yellow)} auto-correctable"
163
+ end
164
+ end
135
165
  end
136
166
  end
137
167
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  # Common functionality for finding names that are similar to a given name.
5
+ # @api private
5
6
  module NameSimilarity
6
7
  module_function
7
8
 
@@ -8,6 +8,7 @@ module RuboCop
8
8
  class OptionArgumentError < StandardError; end
9
9
 
10
10
  # This class handles command line options.
11
+ # @api private
11
12
  class Options
12
13
  E_STDIN_NO_PATH = '-s/--stdin requires exactly one path, relative to the ' \
13
14
  'root of the project. RuboCop will use this path to determine which ' \
@@ -232,6 +233,7 @@ module RuboCop
232
233
  end
233
234
 
234
235
  # Validates option arguments and the options' compatibility with each other.
236
+ # @api private
235
237
  class OptionsValidator
236
238
  class << self
237
239
  # Cop name validation must be done later than option parsing, so it's not
@@ -393,6 +395,7 @@ module RuboCop
393
395
  end
394
396
 
395
397
  # This module contains help texts for command line options.
398
+ # @api private
396
399
  module OptionsHelp
397
400
  MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
398
401
  FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
@@ -5,6 +5,7 @@ require 'time'
5
5
 
6
6
  module RuboCop
7
7
  # Common methods and behaviors for dealing with remote config files.
8
+ # @api private
8
9
  class RemoteConfig
9
10
  attr_reader :uri
10
11
 
@@ -6,6 +6,7 @@ require 'etc'
6
6
 
7
7
  module RuboCop
8
8
  # Provides functionality for caching rubocop runs.
9
+ # @api private
9
10
  class ResultCache
10
11
  NON_CHANGING = %i[color format formatters out debug fail_level auto_correct
11
12
  cache fail_fast stdin parallel].freeze
@@ -17,7 +17,10 @@ module CopHelper
17
17
  RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
18
18
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
19
19
  processed_source = parse_source(source, file)
20
- raise 'Error parsing example code' unless processed_source.valid_syntax?
20
+ unless processed_source.valid_syntax?
21
+ raise 'Error parsing example code: ' \
22
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
23
+ end
21
24
 
22
25
  _investigate(cop, processed_source)
23
26
  end
@@ -128,7 +128,10 @@ module RuboCop
128
128
  @processed_source = parse_source(expected_annotations.plain_source,
129
129
  file)
130
130
 
131
- raise 'Error parsing example code' unless @processed_source.valid_syntax?
131
+ unless @processed_source.valid_syntax?
132
+ raise 'Error parsing example code: ' \
133
+ "#{@processed_source.diagnostics.map(&:render).join("\n")}"
134
+ end
132
135
 
133
136
  offenses = _investigate(cop, @processed_source)
134
137
  actual_annotations =
@@ -136,6 +139,8 @@ module RuboCop
136
139
 
137
140
  expect(actual_annotations).to eq(expected_annotations), ''
138
141
  expect(offenses.map(&:severity).uniq).to eq([severity]) if severity
142
+
143
+ offenses
139
144
  end
140
145
 
141
146
  def expect_correction(correction, loop: true)
@@ -236,10 +241,10 @@ module RuboCop
236
241
  def match_annotations?(other)
237
242
  annotations.zip(other.annotations) do |(_actual_line, actual_annotation),
238
243
  (_expected_line, expected_annotation)|
239
- if expected_annotation&.end_with?(ABBREV)
240
- if actual_annotation.start_with?(expected_annotation[0...-ABBREV.length])
241
- expected_annotation.replace(actual_annotation)
242
- end
244
+ if expected_annotation&.end_with?(ABBREV) &&
245
+ actual_annotation.start_with?(expected_annotation[0...-ABBREV.length])
246
+
247
+ expected_annotation.replace(actual_annotation)
243
248
  end
244
249
  end
245
250
 
@@ -40,6 +40,18 @@ RSpec.shared_context 'isolated environment', :isolated_environment do
40
40
  end
41
41
  end
42
42
 
43
+ RSpec.shared_context 'maintain registry', :restore_registry do
44
+ around(:each) do |example|
45
+ RuboCop::Cop::Registry.with_temporary_global { example.run }
46
+ end
47
+
48
+ def stub_cop_class(name, inherit: RuboCop::Cop::Base, &block)
49
+ klass = Class.new(inherit, &block)
50
+ stub_const(name, klass)
51
+ klass
52
+ end
53
+ end
54
+
43
55
  # This context assumes nothing and defines `cop`, among others.
44
56
  RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
45
57
  ### Meant to be overridden at will
@@ -17,6 +17,7 @@ module RuboCop
17
17
  end
18
18
  end
19
19
 
20
+ # @api private
20
21
  MAX_ITERATIONS = 200
21
22
 
22
23
  attr_reader :errors, :warnings
@@ -17,6 +17,9 @@ module RuboCop
17
17
  u\{[^}]*\} | # extended unicode escape
18
18
  . # any other escaped char
19
19
  )/x.freeze
20
+
21
+ private_constant :STRING_ESCAPES, :STRING_ESCAPE_REGEX
22
+
20
23
  class << self
21
24
  def interpret(string)
22
25
  # We currently don't handle \cx, \C-x, and \M-x
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  # This class finds target files to inspect by scanning the directory tree
5
5
  # and picking ruby files.
6
+ # @api private
6
7
  class TargetFinder
7
8
  def initialize(config_store, options = {})
8
9
  @config_store = config_store
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
+ # @api private
5
6
  class TargetRuby
6
7
  KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7, 2.8].freeze
7
8
  DEFAULT_VERSION = KNOWN_RUBIES.first
@@ -12,6 +13,7 @@ module RuboCop
12
13
  private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
13
14
 
14
15
  # A place where information about a target ruby version is found.
16
+ # @api private
15
17
  class Source
16
18
  attr_reader :version, :name
17
19
 
@@ -26,6 +28,7 @@ module RuboCop
26
28
  end
27
29
 
28
30
  # The target ruby version may be configured in RuboCop's config.
31
+ # @api private
29
32
  class RuboCopConfig < Source
30
33
  def name
31
34
  "`TargetRubyVersion` parameter (in #{@config.smart_loaded_path})"
@@ -39,6 +42,7 @@ module RuboCop
39
42
  end
40
43
 
41
44
  # The target ruby version may be found in a .ruby-version file.
45
+ # @api private
42
46
  class RubyVersionFile < Source
43
47
  FILENAME = '.ruby-version'
44
48
 
@@ -68,6 +72,7 @@ module RuboCop
68
72
  end
69
73
 
70
74
  # The lock file of Bundler may identify the target ruby version.
75
+ # @api private
71
76
  class BundlerLockFile < Source
72
77
  def name
73
78
  "`#{bundler_lock_file_path}`"
@@ -108,6 +113,7 @@ module RuboCop
108
113
  end
109
114
 
110
115
  # If all else fails, a default version will be picked.
116
+ # @api private
111
117
  class Default < Source
112
118
  def name
113
119
  'default'
@@ -3,12 +3,13 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.89.1'
6
+ STRING = '0.90.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
10
10
  'running on %<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'
11
11
 
12
+ # @api private
12
13
  def self.version(debug: false)
13
14
  if debug
14
15
  format(MSG, version: STRING, parser_version: Parser::VERSION,
@@ -2,6 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  # Find duplicated keys from YAML.
5
+ # @api private
5
6
  module YAMLDuplicationChecker
6
7
  def self.check(yaml_string, filename, &on_duplicated)
7
8
  # Ruby 2.6+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.89.1
4
+ version: 0.90.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-08-10 00:00:00.000000000 Z
13
+ date: 2020-09-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -226,6 +226,7 @@ files:
226
226
  - lib/rubocop/cop/correctors/space_corrector.rb
227
227
  - lib/rubocop/cop/correctors/string_literal_corrector.rb
228
228
  - lib/rubocop/cop/correctors/unused_arg_corrector.rb
229
+ - lib/rubocop/cop/documentation.rb
229
230
  - lib/rubocop/cop/force.rb
230
231
  - lib/rubocop/cop/gemspec/duplicated_assignment.rb
231
232
  - lib/rubocop/cop/gemspec/ordered_dependencies.rb
@@ -261,6 +262,7 @@ files:
261
262
  - lib/rubocop/cop/layout/empty_comment.rb
262
263
  - lib/rubocop/cop/layout/empty_line_after_guard_clause.rb
263
264
  - lib/rubocop/cop/layout/empty_line_after_magic_comment.rb
265
+ - lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb
264
266
  - lib/rubocop/cop/layout/empty_line_between_defs.rb
265
267
  - lib/rubocop/cop/layout/empty_lines.rb
266
268
  - lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb
@@ -352,12 +354,14 @@ files:
352
354
  - lib/rubocop/cop/lint/duplicate_elsif_condition.rb
353
355
  - lib/rubocop/cop/lint/duplicate_hash_key.rb
354
356
  - lib/rubocop/cop/lint/duplicate_methods.rb
357
+ - lib/rubocop/cop/lint/duplicate_require.rb
355
358
  - lib/rubocop/cop/lint/duplicate_rescue_exception.rb
356
359
  - lib/rubocop/cop/lint/each_with_object_argument.rb
357
360
  - lib/rubocop/cop/lint/else_layout.rb
358
361
  - lib/rubocop/cop/lint/empty_conditional_body.rb
359
362
  - lib/rubocop/cop/lint/empty_ensure.rb
360
363
  - lib/rubocop/cop/lint/empty_expression.rb
364
+ - lib/rubocop/cop/lint/empty_file.rb
361
365
  - lib/rubocop/cop/lint/empty_interpolation.rb
362
366
  - lib/rubocop/cop/lint/empty_when.rb
363
367
  - lib/rubocop/cop/lint/ensure_return.rb
@@ -417,6 +421,7 @@ files:
417
421
  - lib/rubocop/cop/lint/syntax.rb
418
422
  - lib/rubocop/cop/lint/to_json.rb
419
423
  - lib/rubocop/cop/lint/top_level_return_with_argument.rb
424
+ - lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb
420
425
  - lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
421
426
  - lib/rubocop/cop/lint/unified_integer.rb
422
427
  - lib/rubocop/cop/lint/unreachable_code.rb
@@ -428,6 +433,7 @@ files:
428
433
  - lib/rubocop/cop/lint/useless_access_modifier.rb
429
434
  - lib/rubocop/cop/lint/useless_assignment.rb
430
435
  - lib/rubocop/cop/lint/useless_else_without_rescue.rb
436
+ - lib/rubocop/cop/lint/useless_method_definition.rb
431
437
  - lib/rubocop/cop/lint/useless_setter_call.rb
432
438
  - lib/rubocop/cop/lint/void.rb
433
439
  - lib/rubocop/cop/message_annotator.rb
@@ -454,6 +460,7 @@ files:
454
460
  - lib/rubocop/cop/mixin/check_assignment.rb
455
461
  - lib/rubocop/cop/mixin/check_line_breakable.rb
456
462
  - lib/rubocop/cop/mixin/code_length.rb
463
+ - lib/rubocop/cop/mixin/comments_help.rb
457
464
  - lib/rubocop/cop/mixin/configurable_enforced_style.rb
458
465
  - lib/rubocop/cop/mixin/configurable_formatting.rb
459
466
  - lib/rubocop/cop/mixin/configurable_max.rb
@@ -554,10 +561,12 @@ files:
554
561
  - lib/rubocop/cop/style/class_and_module_children.rb
555
562
  - lib/rubocop/cop/style/class_check.rb
556
563
  - lib/rubocop/cop/style/class_methods.rb
564
+ - lib/rubocop/cop/style/class_methods_definitions.rb
557
565
  - lib/rubocop/cop/style/class_vars.rb
558
566
  - lib/rubocop/cop/style/collection_methods.rb
559
567
  - lib/rubocop/cop/style/colon_method_call.rb
560
568
  - lib/rubocop/cop/style/colon_method_definition.rb
569
+ - lib/rubocop/cop/style/combinable_loops.rb
561
570
  - lib/rubocop/cop/style/command_literal.rb
562
571
  - lib/rubocop/cop/style/comment_annotation.rb
563
572
  - lib/rubocop/cop/style/commented_keyword.rb
@@ -611,6 +620,7 @@ files:
611
620
  - lib/rubocop/cop/style/inline_comment.rb
612
621
  - lib/rubocop/cop/style/inverse_methods.rb
613
622
  - lib/rubocop/cop/style/ip_addresses.rb
623
+ - lib/rubocop/cop/style/keyword_parameters_order.rb
614
624
  - lib/rubocop/cop/style/lambda.rb
615
625
  - lib/rubocop/cop/style/lambda_call.rb
616
626
  - lib/rubocop/cop/style/line_end_concatenation.rb
@@ -678,6 +688,7 @@ files:
678
688
  - lib/rubocop/cop/style/redundant_regexp_escape.rb
679
689
  - lib/rubocop/cop/style/redundant_return.rb
680
690
  - lib/rubocop/cop/style/redundant_self.rb
691
+ - lib/rubocop/cop/style/redundant_self_assignment.rb
681
692
  - lib/rubocop/cop/style/redundant_sort.rb
682
693
  - lib/rubocop/cop/style/redundant_sort_by.rb
683
694
  - lib/rubocop/cop/style/regexp_literal.rb
@@ -694,6 +705,7 @@ files:
694
705
  - lib/rubocop/cop/style/single_line_block_params.rb
695
706
  - lib/rubocop/cop/style/single_line_methods.rb
696
707
  - lib/rubocop/cop/style/slicing_with_range.rb
708
+ - lib/rubocop/cop/style/sole_nested_conditional.rb
697
709
  - lib/rubocop/cop/style/special_global_vars.rb
698
710
  - lib/rubocop/cop/style/stabby_lambda_parentheses.rb
699
711
  - lib/rubocop/cop/style/stderr_puts.rb
@@ -743,6 +755,7 @@ files:
743
755
  - lib/rubocop/core_ext/string.rb
744
756
  - lib/rubocop/error.rb
745
757
  - lib/rubocop/ext/processed_source.rb
758
+ - lib/rubocop/ext/regexp_node.rb
746
759
  - lib/rubocop/file_finder.rb
747
760
  - lib/rubocop/formatter/auto_gen_config_formatter.rb
748
761
  - lib/rubocop/formatter/base_formatter.rb