rubocop 0.52.0 → 0.52.1

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 (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
@@ -23,6 +23,12 @@ module RuboCop
23
23
  class UnusedMethodArgument < Cop
24
24
  include UnusedArgument
25
25
 
26
+ def autocorrect(node)
27
+ UnusedArgCorrector.correct(processed_source, node)
28
+ end
29
+
30
+ private
31
+
26
32
  def check_argument(variable)
27
33
  return unless variable.method_argument?
28
34
  return if variable.keyword_argument? &&
@@ -17,7 +17,8 @@ module RuboCop
17
17
  #
18
18
  # # good
19
19
  # CGI.escape('http://example.com')
20
- # URI.encode_www_form('http://example.com')
20
+ # URI.encode_www_form([['example', 'param'], ['lang', 'en']])
21
+ # URI.encode_www_form(page: 10, locale: 'en')
21
22
  # URI.encode_www_form_component('http://example.com')
22
23
  #
23
24
  # # bad
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # This module checks for nodes that should be aligned to the left or right.
6
+ # This amount is determined by the instance variable @column_delta.
7
+ module Alignment
8
+ private
9
+
10
+ SPACE = ' '.freeze
11
+
12
+ attr_reader :column_delta
13
+
14
+ def configured_indentation_width
15
+ cop_config['IndentationWidth'] ||
16
+ config.for_cop('IndentationWidth')['Width']
17
+ end
18
+
19
+ def indentation(node)
20
+ offset(node) + (SPACE * configured_indentation_width)
21
+ end
22
+
23
+ def offset(node)
24
+ SPACE * node.loc.column
25
+ end
26
+
27
+ def check_alignment(items, base_column = nil)
28
+ unless items.empty?
29
+ base_column ||= display_column(items.first.source_range)
30
+ end
31
+
32
+ each_bad_alignment(items, base_column) do |current|
33
+ expr = current.source_range
34
+ if offenses.any? { |o| within?(expr, o.location) }
35
+ # If this offense is within a line range that is already being
36
+ # realigned by autocorrect, we report the offense without
37
+ # autocorrecting it. Two rewrites in the same area by the same
38
+ # cop can not be handled. The next iteration will find the
39
+ # offense again and correct it.
40
+ add_offense(nil, location: expr)
41
+ else
42
+ add_offense(current)
43
+ end
44
+ end
45
+ end
46
+
47
+ def each_bad_alignment(items, base_column)
48
+ prev_line = -1
49
+ items.each do |current|
50
+ if current.loc.line > prev_line &&
51
+ begins_its_line?(current.source_range)
52
+ @column_delta = base_column - display_column(current.source_range)
53
+
54
+ yield current if @column_delta.nonzero?
55
+ end
56
+ prev_line = current.loc.line
57
+ end
58
+ end
59
+
60
+ def display_column(range)
61
+ line = processed_source.lines[range.line - 1]
62
+ Unicode::DisplayWidth.of(line[0, range.column])
63
+ end
64
+
65
+ def within?(inner, outer)
66
+ inner.begin_pos >= outer.begin_pos && inner.end_pos <= outer.end_pos
67
+ end
68
+ end
69
+ end
70
+ end
@@ -4,6 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  # Common code for indenting literal arrays and hashes.
6
6
  module ArrayHashIndentation
7
+ private
8
+
7
9
  def each_argument_node(node, type)
8
10
  left_parenthesis = node.loc.begin
9
11
 
@@ -5,6 +5,8 @@ module RuboCop
5
5
  # Common code for ordinary arrays with [] that can be written with %
6
6
  # syntax.
7
7
  module ArraySyntax
8
+ private
9
+
8
10
  def bracketed_array_of?(element_type, node)
9
11
  return false unless node.square_brackets? && node.values.size > 1
10
12
 
@@ -6,6 +6,8 @@ module RuboCop
6
6
  module CodeLength
7
7
  include ConfigurableMax
8
8
 
9
+ private
10
+
9
11
  def max_length
10
12
  cop_config['Max']
11
13
  end
@@ -5,6 +5,8 @@ module RuboCop
5
5
  # Handles `Max` configuration parameters, especially setting them to an
6
6
  # appropriate value with --auto-gen-config.
7
7
  module ConfigurableMax
8
+ private
9
+
8
10
  def max=(value)
9
11
  cfg = config_to_allow_offenses
10
12
  value = [cfg[max_parameter_name], value].max if cfg[max_parameter_name]
@@ -8,13 +8,15 @@ module RuboCop
8
8
 
9
9
  NON_PUBLIC_MODIFIERS = %w[private protected].freeze
10
10
 
11
+ private
12
+
11
13
  def non_public?(node)
12
14
  non_public_modifier?(node.parent) ||
13
15
  preceding_non_public_modifier?(node)
14
16
  end
15
17
 
16
18
  def preceding_non_public_modifier?(node)
17
- stripped_source_upto(node.loc.line).any? do |line|
19
+ stripped_source_upto(node.first_line).any? do |line|
18
20
  NON_PUBLIC_MODIFIERS.include?(line)
19
21
  end
20
22
  end
@@ -7,10 +7,10 @@ module RuboCop
7
7
  extend NodePattern::Macros
8
8
  include Style::AnnotationComment
9
9
 
10
- def_node_matcher :constant_definition?, '{class module casgn}'
11
-
12
10
  private
13
11
 
12
+ def_node_matcher :constant_definition?, '{class module casgn}'
13
+
14
14
  def documentation_comment?(node)
15
15
  preceding_lines = preceding_lines(node)
16
16
 
@@ -15,23 +15,11 @@ module RuboCop
15
15
  MSG_DEFERRED = 'Empty line missing before first %<type>s ' \
16
16
  'definition'.freeze
17
17
 
18
+ private
19
+
18
20
  def_node_matcher :constant_definition?, '{class module}'
19
21
  def_node_matcher :empty_line_required?, '{def defs class module}'
20
22
 
21
- def autocorrect(args)
22
- offense_style, range = args
23
- lambda do |corrector|
24
- case offense_style
25
- when :no_empty_lines then
26
- corrector.remove(range)
27
- when :empty_lines then
28
- corrector.insert_before(range, "\n")
29
- end
30
- end
31
- end
32
-
33
- private
34
-
35
23
  def check(node, body)
36
24
  # When style is `empty_lines`, if the body is empty, we don't enforce
37
25
  # the presence OR absence of an empty line
@@ -111,7 +99,7 @@ module RuboCop
111
99
  node = first_empty_line_required_child(body)
112
100
  return unless node
113
101
 
114
- line = previous_line_ignoring_comments(node.loc.first_line)
102
+ line = previous_line_ignoring_comments(node.first_line)
115
103
  return if processed_source[line].empty?
116
104
 
117
105
  range = source_range(processed_source.buffer, line + 2, 0)
@@ -58,31 +58,7 @@ module RuboCop
58
58
  end
59
59
 
60
60
  def line_break_before_keyword?(whole_expression, rhs)
61
- rhs.loc.line > whole_expression.line
62
- end
63
-
64
- def align(node, align_to)
65
- whitespace = whitespace_range(node)
66
- return false unless whitespace.source.strip.empty?
67
-
68
- column = alignment_column(align_to)
69
- ->(corrector) { corrector.replace(whitespace, ' ' * column) }
70
- end
71
-
72
- def whitespace_range(node)
73
- begin_pos = node.loc.end.begin_pos
74
-
75
- range_between(begin_pos - node.loc.end.column, begin_pos)
76
- end
77
-
78
- def alignment_column(align_to)
79
- if !align_to
80
- 0
81
- elsif align_to.respond_to?(:loc)
82
- align_to.source_range.column
83
- else
84
- align_to.column
85
- end
61
+ rhs.first_line > whole_expression.line
86
62
  end
87
63
  end
88
64
  end
@@ -25,12 +25,6 @@ module RuboCop
25
25
  add_offense(node.children.last)
26
26
  end
27
27
  end
28
-
29
- def autocorrect(node)
30
- lambda do |corrector|
31
- corrector.replace(node.source_range, self.class::SUPERCLASS)
32
- end
33
- end
34
28
  end
35
29
  end
36
30
  end
@@ -5,10 +5,6 @@ module RuboCop
5
5
  # Common functionality for checking for a line break before the first
6
6
  # element in a multi-line collection.
7
7
  module FirstElementLineBreak
8
- def autocorrect(node)
9
- ->(corrector) { corrector.insert_before(node.source_range, "\n") }
10
- end
11
-
12
8
  private
13
9
 
14
10
  def check_method_line_break(node, children)
@@ -27,23 +23,23 @@ module RuboCop
27
23
  def check_children_line_break(node, children, start = node)
28
24
  return if children.size < 2
29
25
 
30
- line = start.loc.line
26
+ line = start.first_line
31
27
 
32
28
  min = first_by_line(children)
33
- return if line != min.loc.first_line
29
+ return if line != min.first_line
34
30
 
35
31
  max = last_by_line(children)
36
- return if line == max.loc.last_line
32
+ return if line == max.last_line
37
33
 
38
34
  add_offense(min)
39
35
  end
40
36
 
41
37
  def first_by_line(nodes)
42
- nodes.min_by { |n| n.loc.first_line }
38
+ nodes.min_by(&:first_line)
43
39
  end
44
40
 
45
41
  def last_by_line(nodes)
46
- nodes.max_by { |n| n.loc.last_line }
42
+ nodes.max_by(&:last_line)
47
43
  end
48
44
  end
49
45
  end
@@ -16,6 +16,8 @@ module RuboCop
16
16
  end
17
17
  end
18
18
 
19
+ private
20
+
19
21
  def frozen_string_literals_enabled?
20
22
  ruby_version = processed_source.ruby_version
21
23
  return false unless ruby_version
@@ -27,8 +29,6 @@ module RuboCop
27
29
  end
28
30
  end
29
31
 
30
- private
31
-
32
32
  def leading_comment_lines
33
33
  processed_source[0..2].compact
34
34
  end
@@ -5,6 +5,8 @@ module RuboCop
5
5
  # This module encapsulates the ability to ignore certain lines when
6
6
  # parsing.
7
7
  module IgnoredPattern
8
+ private
9
+
8
10
  def ignored_line?(line)
9
11
  line = if line.respond_to?(:source_line)
10
12
  line.source_line
@@ -4,6 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for checking integer nodes.
6
6
  module IntegerNode
7
+ private
8
+
7
9
  def integer_part(node)
8
10
  node.source.sub(/^[+-]/, '').split('.').first
9
11
  end
@@ -4,6 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for obtaining source ranges from regexp matches
6
6
  module MatchRange
7
+ private
8
+
7
9
  # Return a new `Range` covering the first matching group number for each
8
10
  # match of `regex` inside `range`
9
11
  def each_match_range(range, regex)
@@ -4,6 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  # Common functionality for checking minimum body length.
6
6
  module MinBodyLength
7
+ private
8
+
7
9
  def min_body_length?(node)
8
10
  (node.loc.end.line - node.loc.keyword.line) > min_body_length
9
11
  end
@@ -24,6 +24,8 @@ module RuboCop
24
24
  check(range, node, lhs, rhs)
25
25
  end
26
26
 
27
+ private
28
+
27
29
  # In a chain of method calls, we regard the top send node as the base
28
30
  # for indentation of all lines following the first. For example:
29
31
  # a.
@@ -7,6 +7,8 @@ module RuboCop
7
7
  module MultilineLiteralBraceLayout
8
8
  include ConfigurableEnforcedStyle
9
9
 
10
+ private
11
+
10
12
  def check_brace_layout(node)
11
13
  return if ignored_literal?(node)
12
14
 
@@ -17,30 +19,6 @@ module RuboCop
17
19
  check(node)
18
20
  end
19
21
 
20
- def autocorrect(node)
21
- if closing_brace_on_same_line?(node)
22
- lambda do |corrector|
23
- corrector.insert_before(node.loc.end, "\n".freeze)
24
- end
25
- else
26
- # When a comment immediately before the closing brace gets in the way
27
- # of an easy correction, the offense is reported but not auto-
28
- # corrected. The user must handle the delicate decision of where to
29
- # put the comment.
30
- return if new_line_needed_before_closing_brace?(node)
31
-
32
- lambda do |corrector|
33
- corrector.remove(range_with_surrounding_space(range: node.loc.end,
34
- side: :left))
35
-
36
- corrector.insert_after(last_element_range_with_trailing_comma(node),
37
- node.loc.end.source)
38
- end
39
- end
40
- end
41
-
42
- private
43
-
44
22
  # Returns true for the case
45
23
  # [a,
46
24
  # b # comment
@@ -91,33 +69,16 @@ module RuboCop
91
69
  end
92
70
  end
93
71
 
94
- def ignored_literal?(node)
95
- implicit_literal?(node) || empty_literal?(node) || node.single_line?
96
- end
97
-
98
- def implicit_literal?(node)
99
- !node.loc.begin
100
- end
101
-
102
72
  def empty_literal?(node)
103
73
  children(node).empty?
104
74
  end
105
75
 
106
- def last_element_range_with_trailing_comma(node)
107
- trailing_comma_range = last_element_trailing_comma_range(node)
108
- if trailing_comma_range
109
- children(node).last.source_range.join(trailing_comma_range)
110
- else
111
- children(node).last.source_range
112
- end
76
+ def implicit_literal?(node)
77
+ !node.loc.begin
113
78
  end
114
79
 
115
- def last_element_trailing_comma_range(node)
116
- range = range_with_surrounding_space(
117
- range: children(node).last.source_range,
118
- side: :right
119
- ).end.resize(1)
120
- range.source == ',' ? range : nil
80
+ def ignored_literal?(node)
81
+ implicit_literal?(node) || empty_literal?(node) || node.single_line?
121
82
  end
122
83
 
123
84
  def children(node)
@@ -127,13 +88,13 @@ module RuboCop
127
88
  # This method depends on the fact that we have guarded
128
89
  # against implicit and empty literals.
129
90
  def opening_brace_on_same_line?(node)
130
- node.loc.begin.line == children(node).first.loc.first_line
91
+ node.loc.begin.line == children(node).first.first_line
131
92
  end
132
93
 
133
94
  # This method depends on the fact that we have guarded
134
95
  # against implicit and empty literals.
135
96
  def closing_brace_on_same_line?(node)
136
- node.loc.end.line == children(node).last.loc.last_line
97
+ node.loc.end.line == children(node).last.last_line
137
98
  end
138
99
 
139
100
  # Starting with the parent node and recursively for the parent node's
@@ -165,7 +126,7 @@ module RuboCop
165
126
 
166
127
  if node.respond_to?(:loc) &&
167
128
  node.loc.respond_to?(:heredoc_end) &&
168
- node.loc.heredoc_end.last_line >= parent.loc.last_line
129
+ node.loc.heredoc_end.last_line >= parent.last_line
169
130
  return true
170
131
  end
171
132