rubocop 0.52.0 → 0.52.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -5
  3. data/config/default.yml +1 -11
  4. data/config/disabled.yml +5 -0
  5. data/config/enabled.yml +6 -8
  6. data/lib/rubocop.rb +13 -2
  7. data/lib/rubocop/ast/node.rb +23 -15
  8. data/lib/rubocop/cli.rb +25 -2
  9. data/lib/rubocop/config.rb +23 -8
  10. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
  11. data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
  12. data/lib/rubocop/cop/commissioner.rb +1 -1
  13. data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
  14. data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
  15. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
  16. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
  17. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
  18. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
  19. data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
  20. data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
  21. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
  22. data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
  23. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  24. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
  25. data/lib/rubocop/cop/generator.rb +18 -87
  26. data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
  27. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
  28. data/lib/rubocop/cop/layout/align_array.rb +5 -1
  29. data/lib/rubocop/cop/layout/align_hash.rb +1 -1
  30. data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
  31. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  32. data/lib/rubocop/cop/layout/class_structure.rb +2 -2
  33. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
  34. data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
  35. data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
  36. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
  37. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
  38. data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
  39. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
  40. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
  41. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
  42. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
  43. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
  44. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
  45. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
  46. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
  47. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
  48. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
  49. data/lib/rubocop/cop/layout/indent_array.rb +6 -2
  50. data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
  51. data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
  52. data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
  53. data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
  54. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
  55. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
  56. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
  57. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
  58. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
  59. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
  60. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
  61. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
  62. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
  63. data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
  64. data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
  65. data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
  66. data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
  67. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
  68. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
  69. data/lib/rubocop/cop/layout/tab.rb +1 -1
  70. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  71. data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
  72. data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
  73. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  74. data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
  75. data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
  76. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
  77. data/lib/rubocop/cop/mixin/alignment.rb +70 -0
  78. data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
  79. data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
  80. data/lib/rubocop/cop/mixin/code_length.rb +2 -0
  81. data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
  82. data/lib/rubocop/cop/mixin/def_node.rb +3 -1
  83. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  84. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
  85. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
  86. data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
  87. data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
  88. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
  89. data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
  90. data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
  91. data/lib/rubocop/cop/mixin/match_range.rb +2 -0
  92. data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
  93. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  94. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
  95. data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
  96. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
  97. data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
  98. data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
  99. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
  100. data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
  101. data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
  102. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
  103. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
  104. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
  105. data/lib/rubocop/cop/mixin/string_help.rb +2 -0
  106. data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
  107. data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
  108. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
  109. data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
  110. data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
  111. data/lib/rubocop/cop/rails/action_filter.rb +3 -2
  112. data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
  113. data/lib/rubocop/cop/rails/application_job.rb +6 -0
  114. data/lib/rubocop/cop/rails/application_record.rb +6 -0
  115. data/lib/rubocop/cop/rails/blank.rb +10 -9
  116. data/lib/rubocop/cop/rails/date.rb +22 -14
  117. data/lib/rubocop/cop/rails/delegate.rb +1 -1
  118. data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
  119. data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
  120. data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
  121. data/lib/rubocop/cop/rails/file_path.rb +1 -1
  122. data/lib/rubocop/cop/rails/find_by.rb +2 -2
  123. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
  124. data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
  125. data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
  126. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
  127. data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
  128. data/lib/rubocop/cop/rails/presence.rb +31 -18
  129. data/lib/rubocop/cop/rails/present.rb +11 -8
  130. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
  131. data/lib/rubocop/cop/rails/request_referer.rb +2 -3
  132. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
  133. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
  134. data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
  135. data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
  136. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  137. data/lib/rubocop/cop/style/format_string_token.rb +24 -4
  138. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
  139. data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
  140. data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
  141. data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
  142. data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
  143. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  144. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
  145. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  146. data/lib/rubocop/cop/style/negated_while.rb +6 -4
  147. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  148. data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
  149. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  150. data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
  151. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  152. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  153. data/lib/rubocop/cop/style/string_literals.rb +4 -0
  154. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
  155. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
  156. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
  157. data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
  158. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
  159. data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
  160. data/lib/rubocop/options.rb +33 -10
  161. data/lib/rubocop/path_util.rb +7 -0
  162. data/lib/rubocop/token.rb +4 -0
  163. data/lib/rubocop/version.rb +1 -1
  164. metadata +14 -4
  165. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
  166. data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -10,6 +10,8 @@ module RuboCop
10
10
  MSG = 'Favor `%<inverse>s` over `%<current>s` for ' \
11
11
  'negative conditions.'.freeze
12
12
 
13
+ private
14
+
13
15
  def_node_matcher :single_negative?, '(send !(send _ :!) :!)'
14
16
  def_node_matcher :empty_condition?, '(begin)'
15
17
 
@@ -25,22 +27,6 @@ module RuboCop
25
27
 
26
28
  add_offense(node)
27
29
  end
28
-
29
- def negative_conditional_corrector(node)
30
- condition = negated_condition(node)
31
-
32
- lambda do |corrector|
33
- corrector.replace(node.loc.keyword, node.inverse_keyword)
34
- corrector.replace(condition.source_range,
35
- condition.children.first.source)
36
- end
37
- end
38
-
39
- def negated_condition(node)
40
- condition = node.condition
41
- condition = condition.children.first while condition.begin_type?
42
- condition
43
- end
44
30
  end
45
31
  end
46
32
  end
@@ -5,25 +5,25 @@ module RuboCop
5
5
  # Common functionality for Bundler/OrderedGems and
6
6
  # Gemspec/OrderedDependencies.
7
7
  module OrderedGemNode
8
- def autocorrect(node)
9
- previous = previous_declaration(node)
10
-
11
- current_range = declaration_with_comment(node)
12
- previous_range = declaration_with_comment(previous)
8
+ private
13
9
 
14
- lambda do |corrector|
15
- swap_range(corrector, current_range, previous_range)
10
+ def get_source_range(node, comments_as_separators)
11
+ unless comments_as_separators
12
+ first_comment = processed_source.ast_with_comments[node].first
13
+ return first_comment.loc.expression unless first_comment.nil?
16
14
  end
15
+ node.source_range
17
16
  end
18
17
 
19
- private
20
-
21
18
  def case_insensitive_out_of_order?(string_a, string_b)
22
19
  string_a.downcase < string_b.downcase
23
20
  end
24
21
 
25
22
  def consecutive_lines(previous, current)
26
- first_line = get_source_range(current).first_line
23
+ first_line = get_source_range(
24
+ current,
25
+ treat_comments_as_separators
26
+ ).first_line
27
27
  previous.source_range.last_line == first_line - 1
28
28
  end
29
29
 
@@ -40,27 +40,8 @@ module RuboCop
40
40
  declaration_node.first_argument.str_content
41
41
  end
42
42
 
43
- def declaration_with_comment(node)
44
- buffer = processed_source.buffer
45
- begin_pos = get_source_range(node).begin_pos
46
- end_line = buffer.line_for_position(node.loc.expression.end_pos)
47
- end_pos = buffer.line_range(end_line).end_pos
48
- Parser::Source::Range.new(buffer, begin_pos, end_pos)
49
- end
50
-
51
- def swap_range(corrector, range1, range2)
52
- src1 = range1.source
53
- src2 = range2.source
54
- corrector.replace(range1, src2)
55
- corrector.replace(range2, src1)
56
- end
57
-
58
- def get_source_range(node)
59
- unless cop_config['TreatCommentsAsGroupSeparators']
60
- first_comment = processed_source.ast_with_comments[node].first
61
- return first_comment.loc.expression unless first_comment.nil?
62
- end
63
- node.source_range
43
+ def treat_comments_as_separators
44
+ cop_config['TreatCommentsAsGroupSeparators']
64
45
  end
65
46
  end
66
47
  end
@@ -4,31 +4,14 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for handling parentheses.
6
6
  module Parentheses
7
+ private
8
+
7
9
  def parens_required?(node)
8
10
  range = node.source_range
9
11
  source = range.source_buffer.source
10
12
  source[range.begin_pos - 1] =~ /[a-z]/ ||
11
13
  source[range.end_pos] =~ /[a-z]/
12
14
  end
13
-
14
- def autocorrect(node)
15
- lambda do |corrector|
16
- corrector.remove(node.loc.begin)
17
- corrector.remove(node.loc.end)
18
-
19
- if ternary_condition?(node) && next_char_is_question_mark?(node)
20
- corrector.insert_after(node.loc.end, ' ')
21
- end
22
- end
23
- end
24
-
25
- def ternary_condition?(node)
26
- node.parent && node.parent.if_type? && node.parent.ternary?
27
- end
28
-
29
- def next_char_is_question_mark?(node)
30
- node.loc.last_column == node.parent.loc.question.column
31
- end
32
15
  end
33
16
  end
34
17
  end
@@ -38,7 +38,7 @@ module RuboCop
38
38
  escape = words.any? { |w| needs_escaping?(w.children[0]) }
39
39
  char = char.upcase if escape
40
40
  delimiters = preferred_delimiters_for("%#{char}")
41
- contents = autocorrect_words(words, escape, node.loc.line, delimiters)
41
+ contents = autocorrect_words(words, escape, node.first_line, delimiters)
42
42
 
43
43
  lambda do |corrector|
44
44
  corrector.replace(
@@ -51,9 +51,9 @@ module RuboCop
51
51
  def autocorrect_words(word_nodes, escape, base_line_number, delimiters)
52
52
  previous_node_line_number = base_line_number
53
53
  word_nodes.map do |node|
54
- number_of_line_breaks = node.loc.line - previous_node_line_number
54
+ number_of_line_breaks = node.first_line - previous_node_line_number
55
55
  line_breaks = "\n" * number_of_line_breaks
56
- previous_node_line_number = node.loc.line
56
+ previous_node_line_number = node.first_line
57
57
  content = node.children.first.to_s
58
58
  content = escape ? escape_string(content) : content
59
59
  delimiters.each do |delimiter|
@@ -5,6 +5,8 @@ module RuboCop
5
5
  # Common functionality for checking whether an AST node/token is aligned
6
6
  # with something on a preceding or following line
7
7
  module PrecedingFollowingAlignment
8
+ private
9
+
8
10
  def allow_for_alignment?
9
11
  cop_config['AllowForAlignment']
10
12
  end
@@ -11,6 +11,8 @@ module RuboCop
11
11
  .map(&:pos)
12
12
  end
13
13
 
14
+ private
15
+
14
16
  def rescue_modifier?(node)
15
17
  node &&
16
18
  node.resbody_type? &&
@@ -8,6 +8,8 @@ module RuboCop
8
8
  module SafeAssignment
9
9
  extend NodePattern::Macros
10
10
 
11
+ private
12
+
11
13
  def_node_matcher :empty_condition?, '(begin)'
12
14
  def_node_matcher :safe_assignment?,
13
15
  '(begin {equals_asgn? asgn_method_call?})'
@@ -14,9 +14,7 @@ module RuboCop
14
14
  end
15
15
  end
16
16
 
17
- def autocorrect(token)
18
- ->(corrector) { corrector.replace(token.pos, token.pos.source + ' ') }
19
- end
17
+ private
20
18
 
21
19
  def each_missing_space(tokens)
22
20
  tokens.each_cons(2) do |t1, t2|
@@ -14,9 +14,7 @@ module RuboCop
14
14
  end
15
15
  end
16
16
 
17
- def autocorrect(pos_before_punctuation)
18
- ->(corrector) { corrector.remove(pos_before_punctuation) }
19
- end
17
+ private
20
18
 
21
19
  def each_missing_space(tokens)
22
20
  tokens.each_cons(2) do |t1, t2|
@@ -4,6 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for modifier cops.
6
6
  module StatementModifier
7
+ private
8
+
7
9
  def single_line_as_modifier?(node)
8
10
  return false if non_eligible_node?(node) ||
9
11
  non_eligible_body?(node.body) ||
@@ -19,7 +21,7 @@ module RuboCop
19
21
 
20
22
  def non_eligible_body?(body)
21
23
  body.nil? ||
22
- body.empty? ||
24
+ body.empty_source? ||
23
25
  body.begin_type? ||
24
26
  commented?(body.source_range)
25
27
  end
@@ -30,7 +32,7 @@ module RuboCop
30
32
 
31
33
  def modifier_fits_on_single_line?(node)
32
34
  modifier_length = length_in_modifier_form(node, node.condition,
33
- node.body.length)
35
+ node.body.source_length)
34
36
 
35
37
  modifier_length <= max_line_length
36
38
  end
@@ -24,6 +24,8 @@ module RuboCop
24
24
  ignore_node(node)
25
25
  end
26
26
 
27
+ private
28
+
27
29
  def inside_interpolation?(node)
28
30
  # A :begin node inside a :dstr node is an interpolation.
29
31
  node.ancestors.drop_while { |a| !a.begin_type? }.any?(&:dstr_type?)
@@ -6,6 +6,8 @@ module RuboCop
6
6
  module StringLiteralsHelp
7
7
  include StringHelp
8
8
 
9
+ private
10
+
9
11
  def wrong_quotes?(node)
10
12
  src = node.source
11
13
  return false if src.start_with?('%', '?')
@@ -15,19 +17,6 @@ module RuboCop
15
17
  src !~ /" | \\[^'] | \#(@|\{)/x
16
18
  end
17
19
  end
18
-
19
- def autocorrect(node)
20
- return if node.dstr_type?
21
-
22
- lambda do |corrector|
23
- str = node.str_content
24
- if style == :single_quotes
25
- corrector.replace(node.source_range, to_string_literal(str))
26
- else
27
- corrector.replace(node.source_range, str.inspect)
28
- end
29
- end
30
- end
31
20
  end
32
21
  end
33
22
  end
@@ -7,6 +7,8 @@ module RuboCop
7
7
  NO_SPACE_COMMAND = 'Do not use'.freeze
8
8
  SPACE_COMMAND = 'Use'.freeze
9
9
 
10
+ private
11
+
10
12
  def side_space_range(range:, side:)
11
13
  buffer = @processed_source.buffer
12
14
  src = buffer.source
@@ -50,7 +52,8 @@ module RuboCop
50
52
  end
51
53
 
52
54
  def tokens(node)
53
- processed_source.tokens.select do |token|
55
+ @tokens ||= {}
56
+ @tokens[node.object_id] ||= processed_source.tokens.select do |token|
54
57
  token.end_pos <= node.source_range.end_pos &&
55
58
  token.begin_pos >= node.source_range.begin_pos
56
59
  end
@@ -69,16 +72,6 @@ module RuboCop
69
72
  space_offense(node, right_token, :left, message, NO_SPACE_COMMAND)
70
73
  end
71
74
 
72
- def no_space_corrector(corrector, left_token, right_token)
73
- if left_token.space_after?
74
- range = side_space_range(range: left_token.pos, side: :right)
75
- corrector.remove(range)
76
- end
77
- return unless right_token.space_before?
78
- range = side_space_range(range: right_token.pos, side: :left)
79
- corrector.remove(range)
80
- end
81
-
82
75
  def space_offenses(node, # rubocop:disable Metrics/ParameterLists
83
76
  left_token,
84
77
  right_token,
@@ -92,16 +85,6 @@ module RuboCop
92
85
  space_offense(node, right_token, :none, message, SPACE_COMMAND)
93
86
  end
94
87
 
95
- def space_corrector(corrector, left_token, right_token)
96
- unless left_token.space_after?
97
- corrector.insert_after(left_token.pos, ' ')
98
- end
99
- return if right_token.space_before?
100
- corrector.insert_before(right_token.pos, ' ')
101
- end
102
-
103
- private
104
-
105
88
  def extra_space?(token, side)
106
89
  return false unless token
107
90
  if side == :left
@@ -9,16 +9,7 @@ module RuboCop
9
9
 
10
10
  MSG = '%<command>s comma after the last %<unit>s.'.freeze
11
11
 
12
- def autocorrect(range)
13
- return unless range
14
-
15
- lambda do |corrector|
16
- case range.source
17
- when ',' then corrector.remove(range)
18
- else corrector.insert_after(range, ',')
19
- end
20
- end
21
- end
12
+ private
22
13
 
23
14
  def style_parameter_name
24
15
  'EnforcedStyleForMultiline'
@@ -17,6 +17,8 @@ module RuboCop
17
17
  end
18
18
  end
19
19
 
20
+ private
21
+
20
22
  def check_argument(variable)
21
23
  return if variable.should_be_unused?
22
24
  return if variable.referenced?
@@ -25,21 +27,6 @@ module RuboCop
25
27
  add_offense(variable.declaration_node, location: :name,
26
28
  message: message)
27
29
  end
28
-
29
- def autocorrect(node)
30
- return if %i[kwarg kwoptarg].include?(node.type)
31
-
32
- if node.blockarg_type?
33
- lambda do |corrector|
34
- range = range_with_surrounding_space(range: node.source_range,
35
- side: :left)
36
- range = range_with_surrounding_comma(range, :left)
37
- corrector.remove(range)
38
- end
39
- else
40
- ->(corrector) { corrector.insert_before(node.loc.name, '_') }
41
- end
42
- end
43
30
  end
44
31
  end
45
32
  end
@@ -51,7 +51,7 @@ module RuboCop
51
51
  # baz
52
52
  # end
53
53
  class CaseWhenSplat < Cop
54
- include AutocorrectAlignment
54
+ include Alignment
55
55
 
56
56
  MSG = 'Place `when` conditions with a splat ' \
57
57
  'at the end of the `when` branches.'.freeze
@@ -36,7 +36,7 @@ module RuboCop
36
36
  extend TargetRailsVersion
37
37
  include ConfigurableEnforcedStyle
38
38
 
39
- MSG = 'Prefer `%s` over `%s`.'.freeze
39
+ MSG = 'Prefer `%<prefer>s` over `%<current>s`.'.freeze
40
40
 
41
41
  FILTER_METHODS = %i[
42
42
  after_filter
@@ -96,7 +96,8 @@ module RuboCop
96
96
  end
97
97
 
98
98
  def message(node)
99
- format(MSG, preferred_method(node.method_name), node.method_name)
99
+ format(MSG, prefer: preferred_method(node.method_name),
100
+ current: node.method_name)
100
101
  end
101
102
 
102
103
  def bad_methods
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # [1, 2, 'a'].prepend('b')
21
21
  #
22
22
  class ActiveSupportAliases < Cop
23
- MSG = 'Use `%s` instead of `%s`.'.freeze
23
+ MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
24
24
 
25
25
  ALIASES = {
26
26
  starts_with?: {
@@ -58,7 +58,8 @@ module RuboCop
58
58
  def register_offense(node, method_name)
59
59
  add_offense(
60
60
  node,
61
- message: format(MSG, ALIASES[method_name][:original], method_name)
61
+ message: format(MSG, prefer: ALIASES[method_name][:original],
62
+ current: method_name)
62
63
  )
63
64
  end
64
65
  end
@@ -28,6 +28,12 @@ module RuboCop
28
28
  # rubocop:disable Layout/ClassStructure
29
29
  include RuboCop::Cop::EnforceSuperclass
30
30
  # rubocop:enable Layout/ClassStructure
31
+
32
+ def autocorrect(node)
33
+ lambda do |corrector|
34
+ corrector.replace(node.source_range, self.class::SUPERCLASS)
35
+ end
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -28,6 +28,12 @@ module RuboCop
28
28
  # rubocop:disable Layout/ClassStructure
29
29
  include RuboCop::Cop::EnforceSuperclass
30
30
  # rubocop:enable Layout/ClassStructure
31
+
32
+ def autocorrect(node)
33
+ lambda do |corrector|
34
+ corrector.replace(node.source_range, self.class::SUPERCLASS)
35
+ end
36
+ end
31
37
  end
32
38
  end
33
39
  end