rubocop 0.75.0 → 0.79.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 (192) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +341 -316
  4. data/lib/rubocop.rb +48 -31
  5. data/lib/rubocop/ast/builder.rb +43 -41
  6. data/lib/rubocop/ast/node.rb +5 -1
  7. data/lib/rubocop/ast/node/block_node.rb +2 -0
  8. data/lib/rubocop/ast/node/def_node.rb +11 -0
  9. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  10. data/lib/rubocop/ast/node/return_node.rb +24 -0
  11. data/lib/rubocop/ast/traversal.rb +11 -3
  12. data/lib/rubocop/cli.rb +11 -227
  13. data/lib/rubocop/cli/command.rb +21 -0
  14. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  15. data/lib/rubocop/cli/command/base.rb +33 -0
  16. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  17. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  18. data/lib/rubocop/cli/command/show_cops.rb +80 -0
  19. data/lib/rubocop/cli/command/version.rb +17 -0
  20. data/lib/rubocop/cli/environment.rb +21 -0
  21. data/lib/rubocop/comment_config.rb +2 -2
  22. data/lib/rubocop/config.rb +8 -1
  23. data/lib/rubocop/config_loader.rb +20 -20
  24. data/lib/rubocop/config_loader_resolver.rb +2 -1
  25. data/lib/rubocop/config_obsoletion.rb +73 -11
  26. data/lib/rubocop/config_validator.rb +77 -110
  27. data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
  28. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  29. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  30. data/lib/rubocop/cop/commissioner.rb +15 -7
  31. data/lib/rubocop/cop/cop.rb +31 -6
  32. data/lib/rubocop/cop/corrector.rb +8 -7
  33. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  34. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  35. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  36. data/lib/rubocop/cop/generator.rb +3 -4
  37. data/lib/rubocop/cop/generator/configuration_injector.rb +2 -2
  38. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  39. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  40. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  41. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  42. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +3 -2
  43. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  44. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  45. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
  46. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
  47. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
  48. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  49. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  50. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
  51. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  52. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
  53. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  54. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
  55. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
  56. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  57. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
  58. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
  60. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  61. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  62. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  63. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  64. data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
  65. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  66. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  67. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  68. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  69. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  70. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  71. data/lib/rubocop/cop/lint/debugger.rb +2 -2
  72. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  73. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  74. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  75. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  76. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  77. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  78. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  79. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  80. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
  81. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
  82. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  83. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
  84. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  85. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  86. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  87. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  88. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  89. data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
  90. data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
  91. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  92. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  93. data/lib/rubocop/cop/lint/void.rb +7 -26
  94. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  95. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  96. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  97. data/lib/rubocop/cop/migration/department_name.rb +16 -1
  98. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  99. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -7
  100. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  101. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  102. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  103. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  104. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  105. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
  106. data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
  107. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  108. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  109. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  110. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
  111. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  112. data/lib/rubocop/cop/offense.rb +11 -0
  113. data/lib/rubocop/cop/registry.rb +8 -3
  114. data/lib/rubocop/cop/style/alias.rb +1 -1
  115. data/lib/rubocop/cop/style/array_join.rb +1 -1
  116. data/lib/rubocop/cop/style/attr.rb +10 -2
  117. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
  118. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  119. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  120. data/lib/rubocop/cop/style/copyright.rb +11 -7
  121. data/lib/rubocop/cop/style/documentation_method.rb +44 -0
  122. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  123. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  124. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  125. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  126. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  127. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  128. data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
  129. data/lib/rubocop/cop/style/format_string.rb +10 -7
  130. data/lib/rubocop/cop/style/format_string_token.rb +15 -34
  131. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
  132. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  133. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  134. data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
  135. data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
  136. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  137. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  138. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  139. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +24 -227
  140. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +168 -0
  141. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  142. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  143. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  144. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  145. data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
  146. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  147. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  148. data/lib/rubocop/cop/style/next.rb +5 -5
  149. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  150. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  151. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
  152. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  153. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  154. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  155. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  156. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  157. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  158. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  159. data/lib/rubocop/cop/style/redundant_return.rb +39 -29
  160. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
  161. data/lib/rubocop/cop/style/safe_navigation.rb +19 -8
  162. data/lib/rubocop/cop/style/semicolon.rb +13 -2
  163. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  164. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  165. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  166. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  167. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  168. data/lib/rubocop/cop/team.rb +5 -0
  169. data/lib/rubocop/cop/util.rb +1 -1
  170. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  171. data/lib/rubocop/cop/variable_force.rb +7 -5
  172. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  173. data/lib/rubocop/formatter/clang_style_formatter.rb +9 -6
  174. data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -12
  175. data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
  176. data/lib/rubocop/formatter/formatter_set.rb +16 -16
  177. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  178. data/lib/rubocop/formatter/pacman_formatter.rb +3 -3
  179. data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
  180. data/lib/rubocop/formatter/tap_formatter.rb +9 -6
  181. data/lib/rubocop/node_pattern.rb +4 -2
  182. data/lib/rubocop/options.rb +20 -26
  183. data/lib/rubocop/processed_source.rb +1 -1
  184. data/lib/rubocop/rake_task.rb +1 -0
  185. data/lib/rubocop/result_cache.rb +24 -8
  186. data/lib/rubocop/rspec/shared_contexts.rb +5 -0
  187. data/lib/rubocop/runner.rb +50 -29
  188. data/lib/rubocop/target_finder.rb +12 -6
  189. data/lib/rubocop/target_ruby.rb +151 -0
  190. data/lib/rubocop/version.rb +1 -1
  191. metadata +50 -34
  192. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Style
6
6
  # Checks for while and until statements that would fit on one line
7
7
  # if written as a modifier while/until. The maximum line length is
8
- # configured in the `Metrics/LineLength` cop.
8
+ # configured in the `Layout/LineLength` cop.
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -67,9 +67,16 @@ module RuboCop
67
67
 
68
68
  NONCOMMUTATIVE_OPERATORS = %i[===].freeze
69
69
 
70
+ PROGRAM_NAMES = %i[$0 $PROGRAM_NAME].freeze
71
+
72
+ def_node_matcher :file_constant_equal_program_name?, <<~PATTERN
73
+ (send #source_file_path_constant? {:== :!=} (gvar #program_name?))
74
+ PATTERN
75
+
70
76
  def on_send(node)
71
77
  return unless yoda_compatible_condition?(node)
72
- return if equality_only? && non_equality_operator?(node)
78
+ return if equality_only? && non_equality_operator?(node) ||
79
+ file_constant_equal_program_name?(node)
73
80
 
74
81
  valid_yoda?(node) || add_offense(node)
75
82
  end
@@ -135,6 +142,14 @@ module RuboCop
135
142
  def noncommutative_operator?(node)
136
143
  NONCOMMUTATIVE_OPERATORS.include?(node.method_name)
137
144
  end
145
+
146
+ def source_file_path_constant?(node)
147
+ node.source == '__FILE__'
148
+ end
149
+
150
+ def program_name?(name)
151
+ PROGRAM_NAMES.include?(name)
152
+ end
138
153
  end
139
154
  end
140
155
  end
@@ -86,6 +86,11 @@ module RuboCop
86
86
  raise e.cause
87
87
  end
88
88
 
89
+ def external_dependency_checksum
90
+ keys = cops.map(&:external_dependency_checksum).compact
91
+ Digest::SHA1.hexdigest(keys.join)
92
+ end
93
+
89
94
  private
90
95
 
91
96
  def offenses(processed_source)
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # Match literal regex characters, not including anchors, character
10
10
  # classes, alternatives, groups, repetitions, references, etc
11
11
  LITERAL_REGEX =
12
- /[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]/.freeze
12
+ %r{[\w\s\-,"'!#%&<>=;:`~/]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]}.freeze
13
13
 
14
14
  module_function
15
15
 
@@ -44,15 +44,15 @@ module RuboCop
44
44
  attr_reader :begin_pos, :end_pos
45
45
  attr_reader :flags, :width, :precision, :name, :type
46
46
 
47
- def initialize(string, **opts)
48
- @source = string
49
- @begin_pos = opts[:begin_pos]
50
- @end_pos = opts[:end_pos]
51
- @flags = opts[:flags]
52
- @width = opts[:width]
53
- @precision = opts[:precision]
54
- @name = opts[:name]
55
- @type = opts[:type]
47
+ def initialize(match)
48
+ @source = match[0]
49
+ @begin_pos = match.begin(0)
50
+ @end_pos = match.end(0)
51
+ @flags = match[:flags].to_s + match[:more_flags].to_s
52
+ @width = match[:width]
53
+ @precision = match[:precision]
54
+ @name = match[:name]
55
+ @type = match[:type]
56
56
  end
57
57
 
58
58
  def percent?
@@ -109,16 +109,8 @@ module RuboCop
109
109
 
110
110
  def parse
111
111
  @source.to_enum(:scan, SEQUENCE).map do
112
- match = Regexp.last_match
113
112
  FormatSequence.new(
114
- match[0],
115
- begin_pos: match.begin(0),
116
- end_pos: match.end(0),
117
- flags: match[:flags].to_s + match[:more_flags].to_s,
118
- width: match[:width],
119
- precision: match[:precision],
120
- name: match[:name],
121
- type: match[:type]
113
+ Regexp.last_match
122
114
  )
123
115
  end
124
116
  end
@@ -284,11 +284,7 @@ module RuboCop
284
284
  def process_scope(node)
285
285
  if TWISTED_SCOPE_TYPES.include?(node.type)
286
286
  # See the comment at the end of file for this behavior.
287
- twisted_nodes = [node.children[0]]
288
- twisted_nodes << node.children[1] if node.class_type?
289
- twisted_nodes.compact!
290
-
291
- twisted_nodes.each do |twisted_node|
287
+ twisted_nodes(node).each do |twisted_node|
292
288
  process_node(twisted_node)
293
289
  scanned_nodes << twisted_node
294
290
  end
@@ -298,6 +294,12 @@ module RuboCop
298
294
  skip_children!
299
295
  end
300
296
 
297
+ def twisted_nodes(node)
298
+ twisted_nodes = [node.children[0]]
299
+ twisted_nodes << node.children[1] if node.class_type?
300
+ twisted_nodes.compact
301
+ end
302
+
301
303
  def process_send(node)
302
304
  _receiver, method_name, args = *node
303
305
  return unless method_name == :binding
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/LineLength
3
+ # rubocop:disable Layout/LineLength
4
4
 
5
5
  module RuboCop
6
6
  module Formatter
@@ -41,7 +41,7 @@ module RuboCop
41
41
  # * `#finished`
42
42
  #
43
43
  class BaseFormatter
44
- # rubocop:enable Metrics/LineLength
44
+ # rubocop:enable Layout/LineLength
45
45
 
46
46
  # @api public
47
47
  #
@@ -15,20 +15,23 @@ module RuboCop
15
15
  private
16
16
 
17
17
  def report_offense(file, offense)
18
- output.printf("%s:%d:%d: %s: %s\n",
19
- cyan(smart_path(file)), offense.line, offense.real_column,
20
- colored_severity_code(offense), message(offense))
18
+ output.printf(
19
+ "%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
20
+ path: cyan(smart_path(file)),
21
+ line: offense.line,
22
+ column: offense.real_column,
23
+ severity: colored_severity_code(offense),
24
+ message: message(offense)
25
+ )
21
26
 
22
- # rubocop:disable Lint/HandleExceptions
23
27
  begin
24
28
  return unless valid_line?(offense)
25
29
 
26
30
  report_line(offense.location)
27
31
  report_highlighted_area(offense.highlighted_area)
28
- rescue IndexError
32
+ rescue IndexError # rubocop:disable Lint/SuppressedException
29
33
  # range is not on a valid line; perhaps the source file is empty
30
34
  end
31
- # rubocop:enable Lint/HandleExceptions
32
35
  end
33
36
 
34
37
  def valid_line?(offense)
@@ -8,20 +8,30 @@ module RuboCop
8
8
  class EmacsStyleFormatter < BaseFormatter
9
9
  def file_finished(file, offenses)
10
10
  offenses.each do |o|
11
- message =
12
- if o.corrected_with_todo?
13
- "[Todo] #{o.message}"
14
- elsif o.corrected?
15
- "[Corrected] #{o.message}"
16
- else
17
- o.message
18
- end
19
-
20
- output.printf("%s:%d:%d: %s: %s\n",
21
- file, o.line, o.real_column, o.severity.code,
22
- message.tr("\n", ' '))
11
+ output.printf(
12
+ "%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
13
+ path: file,
14
+ line: o.line,
15
+ column: o.real_column,
16
+ severity: o.severity.code,
17
+ message: message(o)
18
+ )
23
19
  end
24
20
  end
21
+
22
+ private
23
+
24
+ def message(offense)
25
+ message =
26
+ if offense.corrected_with_todo?
27
+ "[Todo] #{offense.message}"
28
+ elsif offense.corrected?
29
+ "[Corrected] #{offense.message}"
30
+ else
31
+ offense.message
32
+ end
33
+ message.tr("\n", ' ')
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
  def file_finished(file, offenses)
14
14
  return if offenses.empty?
15
15
 
16
- output.printf("%s\n", file)
16
+ output.printf("%<path>s\n", path: file)
17
17
  end
18
18
  end
19
19
  end
@@ -9,21 +9,21 @@ module RuboCop
9
9
  # which invoke same method of each formatters.
10
10
  class FormatterSet < Array
11
11
  BUILTIN_FORMATTERS_FOR_KEYS = {
12
- 'progress' => ProgressFormatter,
13
- 'simple' => SimpleTextFormatter,
14
- 'clang' => ClangStyleFormatter,
15
- 'fuubar' => FuubarStyleFormatter,
16
- 'emacs' => EmacsStyleFormatter,
17
- 'json' => JSONFormatter,
18
- 'html' => HTMLFormatter,
19
- 'files' => FileListFormatter,
20
- 'offenses' => OffenseCountFormatter,
21
- 'disabled' => DisabledLinesFormatter,
22
- 'worst' => WorstOffendersFormatter,
23
- 'tap' => TapFormatter,
24
- 'quiet' => QuietFormatter,
25
- 'autogenconf' => AutoGenConfigFormatter,
26
- 'pacman' => PacmanFormatter
12
+ '[a]utogenconf' => AutoGenConfigFormatter,
13
+ '[c]lang' => ClangStyleFormatter,
14
+ '[d]isabled' => DisabledLinesFormatter,
15
+ '[e]macs' => EmacsStyleFormatter,
16
+ '[fi]les' => FileListFormatter,
17
+ '[fu]ubar' => FuubarStyleFormatter,
18
+ '[h]tml' => HTMLFormatter,
19
+ '[j]son' => JSONFormatter,
20
+ '[o]ffenses' => OffenseCountFormatter,
21
+ '[pa]cman' => PacmanFormatter,
22
+ '[p]rogress' => ProgressFormatter,
23
+ '[q]uiet' => QuietFormatter,
24
+ '[s]imple' => SimpleTextFormatter,
25
+ '[t]ap' => TapFormatter,
26
+ '[w]orst' => WorstOffendersFormatter
27
27
  }.freeze
28
28
 
29
29
  FORMATTER_APIS = %i[started finished].freeze
@@ -82,7 +82,7 @@ module RuboCop
82
82
 
83
83
  def builtin_formatter_class(specified_key)
84
84
  matching_keys = BUILTIN_FORMATTERS_FOR_KEYS.keys.select do |key|
85
- key.start_with?(specified_key)
85
+ key =~ /^\[#{specified_key}\]/ || specified_key == key.delete('[]')
86
86
  end
87
87
 
88
88
  raise %(No formatter for "#{specified_key}") if matching_keys.empty?
@@ -53,11 +53,12 @@ module RuboCop
53
53
 
54
54
  def hash_for_offense(offense)
55
55
  {
56
- severity: offense.severity.name,
57
- message: offense.message,
58
- cop_name: offense.cop_name,
59
- corrected: offense.corrected?,
60
- location: hash_for_location(offense)
56
+ severity: offense.severity.name,
57
+ message: offense.message,
58
+ cop_name: offense.cop_name,
59
+ corrected: offense.corrected?,
60
+ correctable: offense.correctable?,
61
+ location: hash_for_location(offense)
61
62
  }
62
63
  end
63
64
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RuboCop
4
4
  module Formatter
5
- # This formatter prints a PACDOT per every file to be analized.
5
+ # This formatter prints a PACDOT per every file to be analyzed.
6
6
  # Pacman will "eat" one PACDOT per file when no offense is detected.
7
7
  # Otherwise it will print a Ghost.
8
8
  # This is inspired by the Pacman formatter for RSpec by Carlos Rojas.
@@ -49,7 +49,7 @@ module RuboCop
49
49
 
50
50
  def cols
51
51
  @cols ||= begin
52
- width = `tput cols`.chomp.to_i
52
+ _height, width = $stdout.winsize
53
53
  width.nil? || width.zero? ? FALLBACK_TERMINAL_WIDTH : width
54
54
  end
55
55
  end
@@ -68,7 +68,7 @@ module RuboCop
68
68
  def step(character)
69
69
  regex = /#{Regexp.quote(PACMAN)}|#{Regexp.quote(PACDOT)}/
70
70
  @progress_line = @progress_line.sub(regex, character)
71
- output.printf("%s\r", @progress_line)
71
+ output.printf("%<line>s\r", line: @progress_line)
72
72
  return unless @progress_line[-1] =~ /ᗣ|\./
73
73
 
74
74
  @repetitions += 1
@@ -42,9 +42,13 @@ module RuboCop
42
42
  output.puts yellow("== #{smart_path(file)} ==")
43
43
 
44
44
  offenses.each do |o|
45
- output.printf("%s:%3d:%3d: %s\n",
46
- colored_severity_code(o),
47
- o.line, o.real_column, message(o))
45
+ output.printf(
46
+ "%<severity>s:%3<line>d:%3<column>d: %<message>s\n",
47
+ severity: colored_severity_code(o),
48
+ line: o.line,
49
+ column: o.real_column,
50
+ message: message(o)
51
+ )
48
52
  end
49
53
  end
50
54
 
@@ -42,20 +42,23 @@ module RuboCop
42
42
  end
43
43
 
44
44
  def report_offense(file, offense)
45
- output.printf("# %s:%d:%d: %s: %s\n",
46
- cyan(smart_path(file)), offense.line, offense.real_column,
47
- colored_severity_code(offense), message(offense))
45
+ output.printf(
46
+ "# %<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
47
+ path: cyan(smart_path(file)),
48
+ line: offense.line,
49
+ column: offense.real_column,
50
+ severity: colored_severity_code(offense),
51
+ message: message(offense)
52
+ )
48
53
 
49
- # rubocop:disable Lint/HandleExceptions
50
54
  begin
51
55
  return unless valid_line?(offense)
52
56
 
53
57
  report_line(offense.location)
54
58
  report_highlighted_area(offense.highlighted_area)
55
- rescue IndexError
59
+ rescue IndexError # rubocop:disable Lint/SuppressedException
56
60
  # range is not on a valid line; perhaps the source file is empty
57
61
  end
58
- # rubocop:enable Lint/HandleExceptions
59
62
  end
60
63
 
61
64
  def annotate_message(msg)
@@ -380,7 +380,7 @@ module RuboCop
380
380
  def compile_seq_head
381
381
  return unless seq_head?
382
382
 
383
- fail_due_to 'sequences can not start with <' \
383
+ fail_due_to 'sequences cannot start with <' \
384
384
  if @terms[0].respond_to? :call
385
385
 
386
386
  with_seq_head_context(@terms[0])
@@ -429,12 +429,13 @@ module RuboCop
429
429
  [0..Float::INFINITY, 'true']
430
430
  end
431
431
 
432
+ # rubocop:disable Metrics/AbcSize
432
433
  # rubocop:disable Metrics/MethodLength
433
434
  def compile_any_order(capture_all = nil)
434
435
  rest = capture_rest = nil
435
436
  patterns = []
436
437
  with_temp_variables do |child, matched|
437
- tokens_until('>', 'any child').each do
438
+ tokens_until('>', 'any child') do
438
439
  fail_due_to 'ellipsis must be at the end of <>' if rest
439
440
  token = tokens.shift
440
441
  case token
@@ -448,6 +449,7 @@ module RuboCop
448
449
  end
449
450
  end
450
451
  # rubocop:enable Metrics/MethodLength
452
+ # rubocop:enable Metrics/AbcSize
451
453
 
452
454
  def insure_same_captures(enum, what)
453
455
  return to_enum __method__, enum, what unless block_given?
@@ -255,21 +255,27 @@ module RuboCop
255
255
  @options = options
256
256
  end
257
257
 
258
+ def validate_cop_options
259
+ %i[only except].each do |opt|
260
+ OptionsValidator.validate_cop_list(@options[opt])
261
+ end
262
+ end
263
+
258
264
  # rubocop:disable Metrics/AbcSize
259
265
  def validate_compatibility # rubocop:disable Metrics/MethodLength
260
- if only_includes_unneeded_disable?
261
- raise OptionArgumentError, 'Lint/UnneededCopDisableDirective can not ' \
266
+ if only_includes_redundant_disable?
267
+ raise OptionArgumentError, 'Lint/RedundantCopDisableDirective cannot ' \
262
268
  'be used with --only.'
263
269
  end
264
270
  if except_syntax?
265
- raise OptionArgumentError, 'Syntax checking can not be turned off.'
271
+ raise OptionArgumentError, 'Syntax checking cannot be turned off.'
266
272
  end
267
273
  unless boolean_or_empty_cache?
268
274
  raise OptionArgumentError, '-C/--cache argument must be true or false'
269
275
  end
270
276
 
271
277
  if display_only_fail_level_offenses_with_autocorrect?
272
- raise OptionArgumentError, '--autocorrect can not be used with ' \
278
+ raise OptionArgumentError, '--autocorrect cannot be used with ' \
273
279
  '--display-only-fail-level-offenses'
274
280
  end
275
281
  validate_auto_gen_config
@@ -323,8 +329,8 @@ module RuboCop
323
329
  auto_gen_config: '-P/--parallel uses caching to speed up execution, ' \
324
330
  'while --auto-gen-config needs a non-cached run, ' \
325
331
  'so they cannot be combined.',
326
- fail_fast: '-P/--parallel can not be combined with -F/--fail-fast.',
327
- auto_correct: '-P/--parallel can not be combined with --auto-correct.'
332
+ fail_fast: '-P/--parallel cannot be combined with -F/--fail-fast.',
333
+ auto_correct: '-P/--parallel cannot be combined with --auto-correct.'
328
334
  }
329
335
 
330
336
  combos.each do |key, msg|
@@ -332,10 +338,10 @@ module RuboCop
332
338
  end
333
339
  end
334
340
 
335
- def only_includes_unneeded_disable?
341
+ def only_includes_redundant_disable?
336
342
  @options.key?(:only) &&
337
- (@options[:only] & %w[Lint/UnneededCopDisableDirective
338
- UnneededCopDisableDirective]).any?
343
+ (@options[:only] & %w[Lint/RedundantCopDisableDirective
344
+ RedundantCopDisableDirective]).any?
339
345
  end
340
346
 
341
347
  def display_only_fail_level_offenses_with_autocorrect?
@@ -367,8 +373,9 @@ module RuboCop
367
373
  # This module contains help texts for command line options.
368
374
  module OptionsHelp
369
375
  MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
376
+ # rubocop:disable Layout/LineLength
377
+ FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
370
378
 
371
- # rubocop:disable Metrics/LineLength
372
379
  TEXT = {
373
380
  only: 'Run only the given cop(s).',
374
381
  only_guide_cops: ['Run only cops for rules that link to a',
@@ -407,21 +414,8 @@ module RuboCop
407
414
  format: ['Choose an output formatter. This option',
408
415
  'can be specified multiple times to enable',
409
416
  'multiple formatters at the same time.',
410
- ' [p]rogress (default)',
411
- ' [s]imple',
412
- ' [c]lang',
413
- ' [d]isabled cops via inline comments',
414
- ' [fu]ubar',
415
- ' [pa]cman',
416
- ' [e]macs',
417
- ' [j]son',
418
- ' [h]tml',
419
- ' [fi]les',
420
- ' [o]ffenses',
421
- ' [w]orst',
422
- ' [t]ap',
423
- ' [q]uiet',
424
- ' [a]utogenconf',
417
+ '[p]rogress is used by default',
418
+ *FORMATTER_OPTION_LIST.map { |item| " #{item}" },
425
419
  ' custom formatter class name'],
426
420
  out: ['Write output to a file instead of STDOUT.',
427
421
  'This option applies to the previously',
@@ -461,6 +455,6 @@ module RuboCop
461
455
  'reports. This is useful for editor integration.'],
462
456
  init: 'Generate a .rubocop.yml file in the current directory.'
463
457
  }.freeze
464
- # rubocop:enable Metrics/LineLength
458
+ # rubocop:enable Layout/LineLength
465
459
  end
466
460
  end