rubocop 0.59.2 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -2
  3. data/config/default.yml +2960 -552
  4. data/lib/rubocop.rb +1 -0
  5. data/lib/rubocop/ast/builder.rb +29 -29
  6. data/lib/rubocop/ast/node.rb +29 -25
  7. data/lib/rubocop/ast/node/args_node.rb +1 -1
  8. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +1 -1
  9. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +26 -0
  10. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +5 -1
  11. data/lib/rubocop/ast/node/pair_node.rb +8 -1
  12. data/lib/rubocop/ast/node/str_node.rb +1 -1
  13. data/lib/rubocop/cached_data.rb +2 -2
  14. data/lib/rubocop/config.rb +1 -1
  15. data/lib/rubocop/config_loader.rb +8 -0
  16. data/lib/rubocop/cop/autocorrect_logic.rb +7 -1
  17. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  18. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -1
  19. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -1
  20. data/lib/rubocop/cop/generator.rb +10 -3
  21. data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
  22. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +1 -1
  23. data/lib/rubocop/cop/layout/align_hash.rb +9 -1
  24. data/lib/rubocop/cop/layout/block_end_newline.rb +2 -4
  25. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -7
  26. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  27. data/lib/rubocop/cop/layout/dot_position.rb +2 -2
  28. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  29. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +1 -2
  30. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  31. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +25 -25
  32. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
  33. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
  34. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -1
  35. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  36. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
  37. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
  38. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -1
  39. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  40. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  41. data/lib/rubocop/cop/layout/indent_hash.rb +1 -1
  42. data/lib/rubocop/cop/layout/indent_heredoc.rb +2 -2
  43. data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
  44. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  45. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  46. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
  47. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  48. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +84 -43
  49. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  50. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  51. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -2
  52. data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
  53. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +2 -2
  54. data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -5
  55. data/lib/rubocop/cop/lint/assignment_in_condition.rb +10 -20
  56. data/lib/rubocop/cop/lint/ensure_return.rb +3 -0
  57. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +3 -3
  58. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  59. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
  60. data/lib/rubocop/cop/lint/percent_symbol_array.rb +10 -7
  61. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +3 -4
  62. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -2
  63. data/lib/rubocop/cop/lint/syntax.rb +3 -2
  64. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -3
  65. data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -7
  66. data/lib/rubocop/cop/metrics/abc_size.rb +1 -17
  67. data/lib/rubocop/cop/metrics/line_length.rb +14 -10
  68. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +45 -0
  69. data/lib/rubocop/cop/mixin/check_assignment.rb +12 -6
  70. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
  71. data/lib/rubocop/cop/mixin/configurable_formatting.rb +0 -2
  72. data/lib/rubocop/cop/mixin/configurable_max.rb +4 -2
  73. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  74. data/lib/rubocop/cop/mixin/configurable_numbering.rb +2 -2
  75. data/lib/rubocop/cop/mixin/hash_alignment.rb +32 -5
  76. data/lib/rubocop/cop/mixin/heredoc.rb +1 -1
  77. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -4
  78. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  79. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -0
  80. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  81. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  82. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  83. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  84. data/lib/rubocop/cop/naming/method_name.rb +2 -0
  85. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  86. data/lib/rubocop/cop/offense.rb +1 -1
  87. data/lib/rubocop/cop/performance/regexp_match.rb +1 -1
  88. data/lib/rubocop/cop/performance/sample.rb +3 -2
  89. data/lib/rubocop/cop/performance/start_with.rb +1 -1
  90. data/lib/rubocop/cop/performance/string_replacement.rb +1 -1
  91. data/lib/rubocop/cop/rails/date.rb +8 -8
  92. data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
  93. data/lib/rubocop/cop/rails/exit.rb +8 -9
  94. data/lib/rubocop/cop/rails/output_safety.rb +3 -3
  95. data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -4
  96. data/lib/rubocop/cop/rails/refute_methods.rb +13 -13
  97. data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
  98. data/lib/rubocop/cop/rails/skips_model_validations.rb +17 -0
  99. data/lib/rubocop/cop/registry.rb +11 -2
  100. data/lib/rubocop/cop/style/and_or.rb +3 -3
  101. data/lib/rubocop/cop/style/collection_methods.rb +26 -0
  102. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  103. data/lib/rubocop/cop/style/encoding.rb +1 -1
  104. data/lib/rubocop/cop/style/even_odd.rb +2 -2
  105. data/lib/rubocop/cop/style/for.rb +3 -3
  106. data/lib/rubocop/cop/style/global_vars.rb +1 -1
  107. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  108. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -13
  109. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  110. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  111. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +4 -7
  112. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  113. data/lib/rubocop/cop/style/module_function.rb +1 -1
  114. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  115. data/lib/rubocop/cop/style/mutable_constant.rb +15 -1
  116. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  117. data/lib/rubocop/cop/style/not.rb +2 -1
  118. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +6 -6
  119. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  120. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  121. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
  122. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  123. data/lib/rubocop/cop/style/proc.rb +1 -1
  124. data/lib/rubocop/cop/style/redundant_freeze.rb +10 -0
  125. data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -2
  126. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  127. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  128. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  129. data/lib/rubocop/cop/style/ternary_parentheses.rb +4 -3
  130. data/lib/rubocop/cop/style/unneeded_condition.rb +2 -2
  131. data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -2
  132. data/lib/rubocop/cop/style/unpack_first.rb +1 -1
  133. data/lib/rubocop/cop/team.rb +3 -2
  134. data/lib/rubocop/cop/util.rb +2 -22
  135. data/lib/rubocop/cop/variable_force/scope.rb +3 -3
  136. data/lib/rubocop/cop/variable_force/variable.rb +3 -4
  137. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  138. data/lib/rubocop/formatter/base_formatter.rb +3 -3
  139. data/lib/rubocop/formatter/disabled_config_formatter.rb +16 -1
  140. data/lib/rubocop/formatter/formatter_set.rb +14 -14
  141. data/lib/rubocop/formatter/html_formatter.rb +4 -4
  142. data/lib/rubocop/formatter/json_formatter.rb +13 -13
  143. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -4
  144. data/lib/rubocop/magic_comment.rb +4 -4
  145. data/lib/rubocop/node_pattern.rb +17 -17
  146. data/lib/rubocop/options.rb +93 -82
  147. data/lib/rubocop/result_cache.rb +9 -1
  148. data/lib/rubocop/rspec/expect_offense.rb +2 -2
  149. data/lib/rubocop/rspec/shared_contexts.rb +11 -11
  150. data/lib/rubocop/rspec/shared_examples.rb +4 -4
  151. data/lib/rubocop/string_interpreter.rb +1 -1
  152. data/lib/rubocop/version.rb +1 -1
  153. metadata +6 -13
  154. data/config/disabled.yml +0 -161
  155. data/config/enabled.yml +0 -2092
@@ -34,11 +34,21 @@ module RuboCop
34
34
  private
35
35
 
36
36
  def immutable_literal?(node)
37
+ node = strip_parenthesis(node)
38
+
37
39
  return true if node.immutable_literal?
38
40
 
39
41
  FROZEN_STRING_LITERAL_TYPES.include?(node.type) &&
40
42
  frozen_string_literals_enabled?
41
43
  end
44
+
45
+ def strip_parenthesis(node)
46
+ if node.begin_type? && node.children.first
47
+ node.children.first
48
+ else
49
+ node
50
+ end
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -108,8 +108,8 @@ module RuboCop
108
108
  def check_unary(begin_node, node)
109
109
  return if begin_node.chained?
110
110
 
111
- # parens are not redundant in `(!recv.method arg)`
112
- node = node.children.first while node.unary_operation?
111
+ node = node.children.first while suspect_unary?(node)
112
+
113
113
  if node.send_type?
114
114
  return unless method_call_with_redundant_parentheses?(node)
115
115
  end
@@ -121,6 +121,10 @@ module RuboCop
121
121
  add_offense(node, message: "Don't use parentheses around #{msg}.")
122
122
  end
123
123
 
124
+ def suspect_unary?(node)
125
+ node.send_type? && node.unary_operation? && !node.prefix_not?
126
+ end
127
+
124
128
  def keyword_ancestor?(node)
125
129
  node.parent && node.parent.keyword?
126
130
  end
@@ -121,7 +121,7 @@ module RuboCop
121
121
  end
122
122
 
123
123
  def regular_method_call?(node)
124
- !(operator?(node.method_name) ||
124
+ !(node.operator_method? ||
125
125
  keyword?(node.method_name) ||
126
126
  node.camel_case_method? ||
127
127
  node.setter_method? ||
@@ -60,7 +60,7 @@ module RuboCop
60
60
  include ConfigurableEnforcedStyle
61
61
 
62
62
  MSG_BOTH = 'Prefer `%<prefer>s` from the stdlib \'English\' ' \
63
- 'module (don\'t forget to require it), or `%<regular>s` over ' \
63
+ 'module (don\'t forget to require it) or `%<regular>s` over ' \
64
64
  '`%<global>s`.'.freeze
65
65
  MSG_ENGLISH = 'Prefer `%<prefer>s` from the stdlib \'English\' ' \
66
66
  'module (don\'t forget to require it) over `%<global>s`.'.freeze
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Style
6
6
  # This cop identifies places where `$stderr.puts` can be replaced by
7
7
  # `warn`. The latter has the advantage of easily being disabled by,
8
- # e.g. the -W0 interpreter flag, or setting $VERBOSE to nil.
8
+ # the `-W0` interpreter flag or setting `$VERBOSE` to `nil`.
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -155,12 +155,13 @@ module RuboCop
155
155
 
156
156
  def unparenthesized_method_call?(child)
157
157
  argument = method_call_argument(child)
158
- argument && argument !~ /^\(/
158
+
159
+ argument && !argument.parenthesized?
159
160
  end
160
161
 
161
162
  def_node_matcher :method_call_argument, <<-PATTERN
162
- {(:defined? $...)
163
- (send {_ nil?} _ $(send nil? _)...)}
163
+ {(:defined? $(send nil? _) ...)
164
+ (send {_ nil?} _ $(send nil? _) ...)}
164
165
  PATTERN
165
166
 
166
167
  def correct_parenthesized(condition)
@@ -90,8 +90,8 @@ module RuboCop
90
90
  end
91
91
 
92
92
  def else_source(else_branch)
93
- wrap_else = MODIFIER_NODES.include?(else_branch.type) &&
94
- else_branch.modifier_form?
93
+ wrap_else =
94
+ else_branch.basic_conditional? && else_branch.modifier_form?
95
95
  wrap_else ? "(#{else_branch.source})" : else_branch.source
96
96
  end
97
97
 
@@ -27,8 +27,8 @@ module RuboCop
27
27
  EMPTY = ''.freeze
28
28
  PERCENT_Q = '%q'.freeze
29
29
  PERCENT_CAPITAL_Q = '%Q'.freeze
30
- STRING_INTERPOLATION_REGEXP = /#\{.+}/
31
- ESCAPED_NON_BACKSLASH = /\\[^\\]/
30
+ STRING_INTERPOLATION_REGEXP = /#\{.+}/.freeze
31
+ ESCAPED_NON_BACKSLASH = /\\[^\\]/.freeze
32
32
 
33
33
  def on_dstr(node)
34
34
  return unless string_literal?(node)
@@ -36,7 +36,7 @@ module RuboCop
36
36
  unpack_and_first_element?(node) do |unpack_call, unpack_arg|
37
37
  range = first_element_range(node, unpack_call)
38
38
  message = format(MSG,
39
- receiver: unpack_call.receiver.source,
39
+ receiver: unpack_call.receiver.source,
40
40
  format: unpack_arg.source,
41
41
  method: range.source)
42
42
  add_offense(node, message: message)
@@ -45,8 +45,9 @@ module RuboCop
45
45
  end
46
46
 
47
47
  def cops
48
- only_options = @options.fetch(:only, [])
49
- @cops ||= @cop_classes.enabled(@config, only_options).map do |cop_class|
48
+ only = @options.fetch(:only, [])
49
+ safe = @options.fetch(:safe, false)
50
+ @cops ||= @cop_classes.enabled(@config, only, safe).map do |cop_class|
50
51
  cop_class.new(@config, @options)
51
52
  end
52
53
  end
@@ -5,34 +5,14 @@ module RuboCop
5
5
  # This module contains a collection of useful utility methods.
6
6
  module Util
7
7
  include PathUtil
8
- extend RuboCop::AST::Sexp
9
-
10
- EQUALS_ASGN_NODES = %i[lvasgn ivasgn cvasgn gvasgn
11
- casgn masgn].freeze
12
- SHORTHAND_ASGN_NODES = %i[op_asgn or_asgn and_asgn].freeze
13
- ASGN_NODES = (EQUALS_ASGN_NODES + SHORTHAND_ASGN_NODES).freeze
14
-
15
- MODIFIER_NODES = %i[if while until].freeze
16
- CONDITIONAL_NODES = (MODIFIER_NODES + [:case]).freeze
17
- LOGICAL_OPERATOR_NODES = %i[and or].freeze
18
-
19
- # http://phrogz.net/programmingruby/language.html#table_18.4
20
- # Backtick is added last just to help editors parse this code.
21
- OPERATOR_METHODS = %w(
22
- | ^ & <=> == === =~ > >= < <= << >>
23
- + - * / % ** ~ +@ -@ !@ ~@ [] []= ! != !~
24
- ).map(&:to_sym).push(:'`').freeze
25
8
 
26
9
  # Match literal regex characters, not including anchors, character
27
10
  # classes, alternatives, groups, repetitions, references, etc
28
- LITERAL_REGEX = /[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]/
11
+ LITERAL_REGEX =
12
+ /[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]/.freeze
29
13
 
30
14
  module_function
31
15
 
32
- def operator?(symbol)
33
- OPERATOR_METHODS.include?(symbol)
34
- end
35
-
36
16
  def comment_line?(line_source)
37
17
  line_source =~ /^\s*#/
38
18
  end
@@ -8,11 +8,11 @@ module RuboCop
8
8
  # A scope instance holds a scope node and variable entries.
9
9
  class Scope
10
10
  OUTER_SCOPE_CHILD_INDICES = {
11
- defs: 0..0,
11
+ defs: 0..0,
12
12
  module: 0..0,
13
- class: 0..1,
13
+ class: 0..1,
14
14
  sclass: 0..0,
15
- block: 0..0
15
+ block: 0..0
16
16
  }.freeze
17
17
 
18
18
  attr_reader :node, :variables, :naked_top_level
@@ -4,8 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  class VariableForce
6
6
  # A Variable represents existence of a local variable.
7
- # This holds a variable declaration node,
8
- # and some states of the variable.
7
+ # This holds a variable declaration node and some states of the variable.
9
8
  class Variable
10
9
  VARIABLE_DECLARATION_TYPES =
11
10
  (VARIABLE_ASSIGNMENT_TYPES + ARGUMENT_DECLARATION_TYPES).freeze
@@ -67,8 +66,8 @@ module RuboCop
67
66
  # For more precise usage check, refer Assignment#used?.
68
67
  #
69
68
  # Once the variable is captured by a block, we have no idea
70
- # when, where and how many times the block would be invoked
71
- # and it means we cannot track the usage of the variable.
69
+ # when, where, and how many times the block would be invoked.
70
+ # This means we cannot track the usage of the variable.
72
71
  # So we consider it's used to suppress false positive offenses.
73
72
  def used?
74
73
  @captured_by_block || referenced?
@@ -5,8 +5,8 @@ module RuboCop
5
5
  class VariableForce
6
6
  # A VariableTable manages the lifetime of all scopes and local variables
7
7
  # in a program.
8
- # This holds scopes as stack structure, and provides a way to add local
9
- # variables to current scope and find local variables by considering
8
+ # This holds scopes as stack structure, provides a way to add local
9
+ # variables to current scope, and find local variables by considering
10
10
  # variable visibility of the current scope.
11
11
  class VariableTable
12
12
  def initialize(hook_receiver = nil)
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # ## Creating Custom Formatter
10
10
  #
11
11
  # You can create a custom formatter by subclassing
12
- # `RuboCop::Formatter::BaseFormatter` and overriding some methods,
12
+ # `RuboCop::Formatter::BaseFormatter` and overriding some methods
13
13
  # or by implementing all the methods by duck typing.
14
14
  #
15
15
  # ## Using Custom Formatter in Command Line
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # `Kernel.require`.
26
26
  # If your custom formatter file is not in `$LOAD_PATH`,
27
27
  # you need to specify the path as relative path prefixed with `./`
28
- # explicitly, or absolute path.
28
+ # explicitly or absolute path.
29
29
  #
30
30
  # ## Method Invocation Order
31
31
  #
@@ -109,7 +109,7 @@ module RuboCop
109
109
 
110
110
  # @api public
111
111
  #
112
- # Invoked after all files are inspected, or interrupted by user.
112
+ # Invoked after all files are inspected or interrupted by user.
113
113
  #
114
114
  # @param inspected_files [Array(String)]
115
115
  # the inspected file paths.
@@ -85,6 +85,7 @@ module RuboCop
85
85
  def output_cop(cop_name, offense_count)
86
86
  output.puts
87
87
  cfg = self.class.config_to_allow_offenses[cop_name] || {}
88
+ set_max(cfg, offense_count)
88
89
 
89
90
  # To avoid malformed YAML when potentially reading the config in
90
91
  # #excludes, we use an output buffer and append it to the actual output
@@ -95,6 +96,19 @@ module RuboCop
95
96
  output.puts(output_buffer.string)
96
97
  end
97
98
 
99
+ def set_max(cfg, offense_count)
100
+ return unless cfg[:exclude_limit]
101
+
102
+ # In case auto_gen_only_exclude is set, only modify the maximum if the
103
+ # files are not excluded one by one.
104
+ if !@options[:auto_gen_only_exclude] || offense_count > @exclude_limit
105
+ cfg.merge! cfg[:exclude_limit]
106
+ end
107
+
108
+ # Remove already used exclude_limit.
109
+ cfg.reject! { |key| key == :exclude_limit }
110
+ end
111
+
98
112
  def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
99
113
  if @show_offense_counts
100
114
  output_buffer.puts "# Offense count: #{offense_count}"
@@ -116,7 +130,8 @@ module RuboCop
116
130
 
117
131
  def cop_config_params(default_cfg, cfg)
118
132
  default_cfg.keys -
119
- %w[Description StyleGuide Reference Enabled Exclude] -
133
+ %w[Description StyleGuide Reference Enabled Exclude Safe
134
+ SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
120
135
  cfg.keys
121
136
  end
122
137
 
@@ -9,20 +9,20 @@ 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
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
26
  }.freeze
27
27
 
28
28
  FORMATTER_APIS = %i[started finished].freeze
@@ -72,11 +72,11 @@ module RuboCop
72
72
  include TextUtil
73
73
 
74
74
  SEVERITY_COLORS = {
75
- refactor: Color.new(0xED, 0x9C, 0x28, 1.0),
75
+ refactor: Color.new(0xED, 0x9C, 0x28, 1.0),
76
76
  convention: Color.new(0xED, 0x9C, 0x28, 1.0),
77
- warning: Color.new(0x96, 0x28, 0xEF, 1.0),
78
- error: Color.new(0xD2, 0x32, 0x2D, 1.0),
79
- fatal: Color.new(0xD2, 0x32, 0x2D, 1.0)
77
+ warning: Color.new(0x96, 0x28, 0xEF, 1.0),
78
+ error: Color.new(0xD2, 0x32, 0x2D, 1.0),
79
+ fatal: Color.new(0xD2, 0x32, 0x2D, 1.0)
80
80
  }.freeze
81
81
 
82
82
  LOGO_IMAGE_PATH =
@@ -15,8 +15,8 @@ module RuboCop
15
15
  super
16
16
  @output_hash = {
17
17
  metadata: metadata_hash,
18
- files: [],
19
- summary: { offense_count: 0 }
18
+ files: [],
19
+ summary: { offense_count: 0 }
20
20
  }
21
21
  end
22
22
 
@@ -37,16 +37,16 @@ module RuboCop
37
37
  def metadata_hash
38
38
  {
39
39
  rubocop_version: RuboCop::Version::STRING,
40
- ruby_engine: RUBY_ENGINE,
41
- ruby_version: RUBY_VERSION,
40
+ ruby_engine: RUBY_ENGINE,
41
+ ruby_version: RUBY_VERSION,
42
42
  ruby_patchlevel: RUBY_PATCHLEVEL.to_s,
43
- ruby_platform: RUBY_PLATFORM
43
+ ruby_platform: RUBY_PLATFORM
44
44
  }
45
45
  end
46
46
 
47
47
  def hash_for_file(file, offenses)
48
48
  {
49
- path: smart_path(file),
49
+ path: smart_path(file),
50
50
  offenses: offenses.map { |o| hash_for_offense(o) }
51
51
  }
52
52
  end
@@ -54,7 +54,7 @@ module RuboCop
54
54
  def hash_for_offense(offense)
55
55
  {
56
56
  severity: offense.severity.name,
57
- message: offense.message,
57
+ message: offense.message,
58
58
  cop_name: offense.cop_name,
59
59
  corrected: offense.corrected?,
60
60
  location: hash_for_location(offense)
@@ -64,15 +64,15 @@ module RuboCop
64
64
  # TODO: Consider better solution for Offense#real_column.
65
65
  def hash_for_location(offense)
66
66
  {
67
- start_line: offense.line,
68
- start_column: offense.real_column,
69
- last_line: offense.last_line,
67
+ start_line: offense.line,
68
+ start_column: offense.real_column,
69
+ last_line: offense.last_line,
70
70
  last_column: offense.last_column,
71
- length: offense.location.length,
71
+ length: offense.location.length,
72
72
  # `line` and `column` exist for compatibility.
73
73
  # Use `start_line` and `start_column` instead.
74
- line: offense.line,
75
- column: offense.real_column
74
+ line: offense.line,
75
+ column: offense.real_column
76
76
  }
77
77
  end
78
78
  end
@@ -13,11 +13,11 @@ module RuboCop
13
13
  include PathUtil
14
14
 
15
15
  COLOR_FOR_SEVERITY = {
16
- refactor: :yellow,
16
+ refactor: :yellow,
17
17
  convention: :yellow,
18
- warning: :magenta,
19
- error: :red,
20
- fatal: :red
18
+ warning: :magenta,
19
+ error: :red,
20
+ fatal: :red
21
21
  }.freeze
22
22
 
23
23
  def started(_target_files)
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # @abstract parent of three different magic comment handlers
7
7
  class MagicComment
8
8
  # @see https://git.io/vMC1C IRB's pattern for matching magic comment tokens
9
- TOKEN = /[[:alnum:]\-_]+/
9
+ TOKEN = /[[:alnum:]\-_]+/.freeze
10
10
 
11
11
  # Detect magic comment format and pass it to the appropriate wrapper.
12
12
  #
@@ -129,7 +129,7 @@ module RuboCop
129
129
  # @see https://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html
130
130
  # @see https://git.io/vMCXh Emacs handling in Ruby's parse.y
131
131
  class EmacsComment < EditorComment
132
- FORMAT = /\-\*\-(.+)\-\*\-/
132
+ FORMAT = /\-\*\-(.+)\-\*\-/.freeze
133
133
  SEPARATOR = ';'.freeze
134
134
  OPERATOR = ':'.freeze
135
135
 
@@ -140,7 +140,7 @@ module RuboCop
140
140
  private
141
141
 
142
142
  def extract_frozen_string_literal
143
- match('frozen_string_literal')
143
+ match('frozen[_-]string[_-]literal')
144
144
  end
145
145
  end
146
146
 
@@ -153,7 +153,7 @@ module RuboCop
153
153
  #
154
154
  # comment.encoding # => 'ascii-8bit'
155
155
  class VimComment < EditorComment
156
- FORMAT = /#\s*vim:\s*(.+)/
156
+ FORMAT = /#\s*vim:\s*(.+)/.freeze
157
157
  SEPARATOR = ', '.freeze
158
158
  OPERATOR = '='.freeze
159
159