rubocop 0.84.0 → 0.85.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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -14
  3. data/config/default.yml +33 -15
  4. data/lib/rubocop.rb +6 -0
  5. data/lib/rubocop/cli.rb +2 -2
  6. data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
  7. data/lib/rubocop/comment_config.rb +1 -1
  8. data/lib/rubocop/config.rb +3 -1
  9. data/lib/rubocop/config_loader.rb +1 -1
  10. data/lib/rubocop/config_loader_resolver.rb +18 -2
  11. data/lib/rubocop/config_store.rb +12 -2
  12. data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
  13. data/lib/rubocop/cop/commissioner.rb +0 -21
  14. data/lib/rubocop/cop/cop.rb +36 -21
  15. data/lib/rubocop/cop/corrector.rb +3 -1
  16. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
  17. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +3 -1
  18. data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
  19. data/lib/rubocop/cop/layout/class_structure.rb +19 -16
  20. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -2
  21. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  22. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  23. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  24. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  25. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
  26. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  27. data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
  28. data/lib/rubocop/cop/layout/line_length.rb +17 -17
  29. data/lib/rubocop/cop/layout/multiline_block_layout.rb +3 -1
  30. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  31. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +3 -1
  32. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +3 -1
  33. data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -1
  34. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +8 -4
  35. data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
  36. data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -1
  37. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +33 -2
  38. data/lib/rubocop/cop/lint/loop.rb +1 -1
  39. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
  40. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  41. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  42. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -1
  43. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  44. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  45. data/lib/rubocop/cop/lint/suppressed_exception.rb +4 -2
  46. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  47. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
  48. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  49. data/lib/rubocop/cop/migration/department_name.rb +9 -5
  50. data/lib/rubocop/cop/mixin/array_min_size.rb +3 -1
  51. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -1
  52. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  53. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  54. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
  55. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
  56. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
  57. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -1
  58. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
  59. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  60. data/lib/rubocop/cop/naming/file_name.rb +26 -11
  61. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  62. data/lib/rubocop/cop/registry.rb +65 -8
  63. data/lib/rubocop/cop/style/array_join.rb +1 -1
  64. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  65. data/lib/rubocop/cop/style/copyright.rb +2 -2
  66. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  67. data/lib/rubocop/cop/style/exponential_notation.rb +3 -3
  68. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  69. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -2
  70. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
  71. data/lib/rubocop/cop/style/hash_syntax.rb +5 -3
  72. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  73. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  74. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  75. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  76. data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
  77. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
  78. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  79. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
  80. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
  81. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  82. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
  83. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
  84. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
  85. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
  86. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
  87. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  88. data/lib/rubocop/cop/style/when_then.rb +1 -1
  89. data/lib/rubocop/cop/team.rb +69 -25
  90. data/lib/rubocop/cop/util.rb +1 -1
  91. data/lib/rubocop/cop/utils/format_string.rb +18 -0
  92. data/lib/rubocop/cop/variable_force/branch.rb +3 -1
  93. data/lib/rubocop/formatter/junit_formatter.rb +14 -4
  94. data/lib/rubocop/magic_comment.rb +1 -1
  95. data/lib/rubocop/options.rb +17 -3
  96. data/lib/rubocop/result_cache.rb +4 -4
  97. data/lib/rubocop/rspec/cop_helper.rb +2 -23
  98. data/lib/rubocop/rspec/expect_offense.rb +45 -6
  99. data/lib/rubocop/rspec/shared_contexts.rb +2 -2
  100. data/lib/rubocop/runner.rb +14 -10
  101. data/lib/rubocop/target_finder.rb +3 -1
  102. data/lib/rubocop/target_ruby.rb +4 -1
  103. data/lib/rubocop/version.rb +1 -1
  104. metadata +23 -5
@@ -36,7 +36,6 @@ module RuboCop
36
36
 
37
37
  def investigate(processed_source)
38
38
  reset_errors
39
- remove_irrelevant_cops(processed_source.file_path)
40
39
  reset_callbacks
41
40
  prepare(processed_source)
42
41
  invoke_custom_processing(@cops, processed_source)
@@ -63,26 +62,6 @@ module RuboCop
63
62
  @errors = []
64
63
  end
65
64
 
66
- def remove_irrelevant_cops(filename)
67
- @cops.reject! do |cop|
68
- cop.excluded_file?(filename) ||
69
- !support_target_ruby_version?(cop) ||
70
- !support_target_rails_version?(cop)
71
- end
72
- end
73
-
74
- def support_target_ruby_version?(cop)
75
- return true unless cop.class.respond_to?(:support_target_ruby_version?)
76
-
77
- cop.class.support_target_ruby_version?(cop.target_ruby_version)
78
- end
79
-
80
- def support_target_rails_version?(cop)
81
- return true unless cop.class.respond_to?(:support_target_rails_version?)
82
-
83
- cop.class.support_target_rails_version?(cop.target_rails_version)
84
- end
85
-
86
65
  def reset_callbacks
87
66
  @callbacks.clear
88
67
  end
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # # Do custom processing
24
24
  # end
25
25
  # end
26
- class Cop
26
+ class Cop # rubocop:disable Metrics/ClassLength
27
27
  extend RuboCop::AST::Sexp
28
28
  extend NodePattern::Macros
29
29
  include RuboCop::AST::Sexp
@@ -44,22 +44,12 @@ module RuboCop
44
44
  attr_reader :config, :offenses, :corrections
45
45
  attr_accessor :processed_source # TODO: Bad design.
46
46
 
47
- @registry = Registry.new
48
-
49
- class << self
50
- attr_reader :registry
51
- end
52
-
53
- def self.all
54
- registry.without_department(:Test).cops
55
- end
56
-
57
- def self.qualified_cop_name(name, origin)
58
- registry.qualified_cop_name(name, origin)
47
+ def self.inherited(subclass)
48
+ Registry.global.enlist(subclass)
59
49
  end
60
50
 
61
- def self.inherited(subclass)
62
- registry.enlist(subclass)
51
+ def self.exclude_from_registry
52
+ Registry.global.dismiss(self)
63
53
  end
64
54
 
65
55
  def self.badge
@@ -146,17 +136,24 @@ module RuboCop
146
136
  @offenses.any? { |o| o.location == location }
147
137
  end
148
138
 
149
- def correct(node)
139
+ def correct(node) # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength
150
140
  reason = reason_to_not_correct(node)
151
141
  return reason if reason
152
142
 
153
143
  @corrected_nodes[node] = true
144
+
154
145
  if support_autocorrect?
155
146
  correction = autocorrect(node)
156
- return :uncorrected unless correction
157
147
 
158
- @corrections << Correction.new(correction, node, self)
159
- :corrected
148
+ if correction
149
+ @corrections << Correction.new(correction, node, self)
150
+ :corrected
151
+ elsif disable_uncorrectable?
152
+ disable_uncorrectable(node)
153
+ :corrected_with_todo
154
+ else
155
+ :uncorrected
156
+ end
160
157
  elsif disable_uncorrectable?
161
158
  disable_uncorrectable(node)
162
159
  :corrected_with_todo
@@ -211,8 +208,9 @@ module RuboCop
211
208
  alias name cop_name
212
209
 
213
210
  def relevant_file?(file)
214
- file_name_matches_any?(file, 'Include', true) &&
215
- !file_name_matches_any?(file, 'Exclude', false)
211
+ file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
212
+ file_name_matches_any?(file, 'Include', true) &&
213
+ !file_name_matches_any?(file, 'Exclude', false)
216
214
  end
217
215
 
218
216
  def excluded_file?(file)
@@ -238,6 +236,23 @@ module RuboCop
238
236
  nil
239
237
  end
240
238
 
239
+ ### Deprecated registry access
240
+
241
+ # @deprecated Use Registry.global
242
+ def self.registry
243
+ Registry.global
244
+ end
245
+
246
+ # @deprecated Use Registry.all
247
+ def self.all
248
+ Registry.all
249
+ end
250
+
251
+ # @deprecated Use Registry.qualified_cop_name
252
+ def self.qualified_cop_name(name, origin)
253
+ Registry.qualified_cop_name(name, origin)
254
+ end
255
+
241
256
  private
242
257
 
243
258
  def find_message(node, message)
@@ -85,7 +85,9 @@ module RuboCop
85
85
  def insert_before(node_or_range, content)
86
86
  range = to_range(node_or_range)
87
87
  # TODO: Fix Cops using bad ranges instead
88
- range = range.with(end_pos: @source_buffer.source.size) if range.end_pos > @source_buffer.source.size
88
+ if range.end_pos > @source_buffer.source.size
89
+ range = range.with(end_pos: @source_buffer.source.size)
90
+ end
89
91
 
90
92
  @source_rewriter.insert_before(range, content)
91
93
  end
@@ -129,7 +129,7 @@ module RuboCop
129
129
  end
130
130
 
131
131
  def separating_space?
132
- block_begin.source_buffer.source[block_begin.begin_pos + 2].match(/\s/)
132
+ block_begin.source_buffer.source[block_begin.begin_pos + 2].match?(/\s/)
133
133
  end
134
134
  end
135
135
  end
@@ -10,7 +10,9 @@ module RuboCop
10
10
  corrector.remove(node.loc.begin)
11
11
  corrector.remove(node.loc.end)
12
12
 
13
- corrector.insert_after(node.loc.end, ' ') if ternary_condition?(node) && next_char_is_question_mark?(node)
13
+ if ternary_condition?(node) && next_char_is_question_mark?(node)
14
+ corrector.insert_after(node.loc.end, ' ')
15
+ end
14
16
  end
15
17
  end
16
18
 
@@ -3,10 +3,10 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Layout
6
- # This cop checks how the *when*s of a *case* expression
7
- # are indented in relation to its *case* or *end* keyword.
6
+ # This cop checks how the ``when``s of a `case` expression
7
+ # are indented in relation to its `case` or `end` keyword.
8
8
  #
9
- # It will register a separate offense for each misaligned *when*.
9
+ # It will register a separate offense for each misaligned `when`.
10
10
  #
11
11
  # @example
12
12
  # # If Layout/EndAlignment is set to keyword style (default)
@@ -8,22 +8,24 @@ module RuboCop
8
8
  # `Categories` allows us to map macro names into a category.
9
9
  #
10
10
  # Consider an example of code style that covers the following order:
11
- # - Module inclusion (include, prepend, extend)
12
- # - Constants
13
- # - Associations (has_one, has_many)
14
- # - Public attribute macros (attr_accessor, attr_writer, attr_reader)
15
- # - Other macros (validates, validate)
16
- # - Public class methods
17
- # - Initializer
18
- # - Public instance methods
19
- # - Protected attribute macros (attr_accessor, attr_writer, attr_reader)
20
- # - Protected instance methods
21
- # - Private attribute macros (attr_accessor, attr_writer, attr_reader)
22
- # - Private instance methods
11
+ #
12
+ # * Module inclusion (include, prepend, extend)
13
+ # * Constants
14
+ # * Associations (has_one, has_many)
15
+ # * Public attribute macros (attr_accessor, attr_writer, attr_reader)
16
+ # * Other macros (validates, validate)
17
+ # * Public class methods
18
+ # * Initializer
19
+ # * Public instance methods
20
+ # * Protected attribute macros (attr_accessor, attr_writer, attr_reader)
21
+ # * Protected instance methods
22
+ # * Private attribute macros (attr_accessor, attr_writer, attr_reader)
23
+ # * Private instance methods
23
24
  #
24
25
  # You can configure the following order:
25
26
  #
26
- # ```yaml
27
+ # [source,yaml]
28
+ # ----
27
29
  # Layout/ClassStructure:
28
30
  # ExpectedOrder:
29
31
  # - module_inclusion
@@ -40,13 +42,14 @@ module RuboCop
40
42
  # - private_attribute_macros
41
43
  # - private_delegate
42
44
  # - private_methods
43
- # ```
45
+ # ----
44
46
  #
45
47
  # Instead of putting all literals in the expected order, is also
46
48
  # possible to group categories of macros. Visibility levels are handled
47
49
  # automatically.
48
50
  #
49
- # ```yaml
51
+ # [source,yaml]
52
+ # ----
50
53
  # Layout/ClassStructure:
51
54
  # Categories:
52
55
  # association:
@@ -63,7 +66,7 @@ module RuboCop
63
66
  # - include
64
67
  # - prepend
65
68
  # - extend
66
- # ```
69
+ # ----
67
70
  #
68
71
  # @example
69
72
  # # bad
@@ -4,8 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  # Checks for a newline after an attribute accessor or a group of them.
7
- # `alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are allowed by default.
8
- # These are customizable with `AllowAliasSyntax` and `AllowedMethods` options.
7
+ # `alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are allowed
8
+ # by default. These are customizable with `AllowAliasSyntax` and `AllowedMethods` options.
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -75,8 +75,8 @@ module RuboCop
75
75
  style
76
76
  end
77
77
  case effective_style
78
- when :lf then MSG_DETECTED if /\r$/.match?(line)
79
- else MSG_MISSING unless /\r$/.match?(line)
78
+ when :lf then MSG_DETECTED if line.end_with?("\r", "\r\n")
79
+ else MSG_MISSING unless line.end_with?("\r\n")
80
80
  end
81
81
  end
82
82
 
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # Arguments after the first one are checked by Layout/ArgumentAlignment,
8
8
  # not by this cop.
9
9
  #
10
- # For indenting the first parameter of method *definitions*, check out
10
+ # For indenting the first parameter of method _definitions_, check out
11
11
  # Layout/FirstParameterIndentation.
12
12
  #
13
13
  # @example
@@ -37,7 +37,7 @@ module RuboCop
37
37
 
38
38
  def assignment_on_same_line?(node)
39
39
  source = node.source_range.source_line[0...node.loc.column]
40
- source =~ /\s*\=\s*$/
40
+ source =~ /\s*=\s*$/
41
41
  end
42
42
  end
43
43
  end
@@ -7,9 +7,9 @@ module RuboCop
7
7
  # definition. Parameters after the first one are checked by
8
8
  # Layout/ParameterAlignment, not by this cop.
9
9
  #
10
- # For indenting the first argument of method *calls*, check out
10
+ # For indenting the first argument of method _calls_, check out
11
11
  # Layout/FirstArgumentIndentation, which supports options related to
12
- # nesting that are irrelevant for method *definitions*.
12
+ # nesting that are irrelevant for method _definitions_.
13
13
  #
14
14
  # @example
15
15
  #
@@ -7,16 +7,16 @@ module RuboCop
7
7
  # literal are aligned according to configuration. The configuration
8
8
  # options are:
9
9
  #
10
- # - key (left align keys, one space before hash rockets and values)
11
- # - separator (align hash rockets and colons, right align keys)
12
- # - table (left align keys, hash rockets, and values)
10
+ # * key (left align keys, one space before hash rockets and values)
11
+ # * separator (align hash rockets and colons, right align keys)
12
+ # * table (left align keys, hash rockets, and values)
13
13
  #
14
14
  # The treatment of hashes passed as the last argument to a method call
15
15
  # can also be configured. The options are:
16
16
  #
17
- # - always_inspect
18
- # - always_ignore
19
- # - ignore_implicit (without curly braces)
17
+ # * always_inspect
18
+ # * always_ignore
19
+ # * ignore_implicit (without curly braces)
20
20
  #
21
21
  # Alternatively you can specify multiple allowed styles. That's done by
22
22
  # passing a list of styles to EnforcedStyles.
@@ -190,7 +190,7 @@ module RuboCop
190
190
  def safe_to_remove_line_containing_closing_paren?(node)
191
191
  last_line = processed_source[node.loc.end.line - 1]
192
192
  # Safe to remove if last line only contains `)`, `,`, and whitespace.
193
- last_line.match(/^[ ]*\)[ ]{0,20},{0,1}[ ]*$/)
193
+ last_line.match?(/^ *\) {0,20},{0,1} *$/)
194
194
  end
195
195
 
196
196
  def incorrect_parenthesis_removal_end(node)
@@ -5,66 +5,29 @@ module RuboCop
5
5
  module Layout
6
6
  # This cop checks the indentation of the here document bodies. The bodies
7
7
  # are indented one step.
8
- # In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you
9
- # use the older rubies, you should introduce some library to your project
10
- # (e.g. ActiveSupport, Powerpack or Unindent).
11
- # Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default),
8
+ #
9
+ # Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
12
10
  # this cop does not add any offenses for long here documents to
13
11
  # avoid `Layout/LineLength`'s offenses.
14
12
  #
15
- # @example EnforcedStyle: squiggly (default)
13
+ # @example
16
14
  # # bad
17
15
  # <<-RUBY
18
16
  # something
19
17
  # RUBY
20
18
  #
21
19
  # # good
22
- # # When EnforcedStyle is squiggly, bad code is auto-corrected to the
23
- # # following code.
24
20
  # <<~RUBY
25
21
  # something
26
22
  # RUBY
27
23
  #
28
- # @example EnforcedStyle: active_support
29
- # # good
30
- # # When EnforcedStyle is active_support, bad code is auto-corrected to
31
- # # the following code.
32
- # <<-RUBY.strip_heredoc
33
- # something
34
- # RUBY
35
- #
36
- # @example EnforcedStyle: powerpack
37
- # # good
38
- # # When EnforcedStyle is powerpack, bad code is auto-corrected to
39
- # # the following code.
40
- # <<-RUBY.strip_indent
41
- # something
42
- # RUBY
43
- #
44
- # @example EnforcedStyle: unindent
45
- # # good
46
- # # When EnforcedStyle is unindent, bad code is auto-corrected to
47
- # # the following code.
48
- # <<-RUBY.unindent
49
- # something
50
- # RUBY
51
24
  #
52
25
  class HeredocIndentation < Cop
53
26
  include Heredoc
54
- include ConfigurableEnforcedStyle
55
27
 
56
- RUBY23_TYPE_MSG = 'Use %<indentation_width>d spaces for indentation ' \
57
- 'in a heredoc by using `<<~` instead of ' \
58
- '`%<current_indent_type>s`.'
59
- RUBY23_WIDTH_MSG = 'Use %<indentation_width>d spaces for '\
60
- 'indentation in a heredoc.'
61
- LIBRARY_MSG = 'Use %<indentation_width>d spaces for indentation in a ' \
62
- 'heredoc by using %<method>s.'
63
- STRIP_METHODS = {
64
- unindent: 'unindent',
65
- active_support: 'strip_heredoc',
66
- powerpack: 'strip_indent'
67
- }.freeze
28
+ TYPE_MSG = 'Use %<indentation_width>d spaces for indentation in a ' \
29
+ 'heredoc by using `<<~` instead of `%<current_indent_type>s`.'
30
+ WIDTH_MSG = 'Use %<indentation_width>d spaces for indentation in a heredoc.'
68
31
 
69
32
  def on_heredoc(node)
70
33
  body = heredoc_body(node)
@@ -85,59 +48,38 @@ module RuboCop
85
48
  end
86
49
 
87
50
  def autocorrect(node)
88
- check_style!
89
-
90
- case style
91
- when :squiggly
92
- correct_by_squiggly(node)
93
- else
94
- correct_by_library(node)
51
+ lambda do |corrector|
52
+ if heredoc_indent_type(node) == '~'
53
+ adjust_squiggly(corrector, node)
54
+ else
55
+ adjust_minus(corrector, node)
56
+ end
95
57
  end
96
58
  end
97
59
 
98
60
  private
99
61
 
100
62
  def message(node)
101
- case style
102
- when :squiggly
103
- current_indent_type = "<<#{heredoc_indent_type(node)}"
104
- ruby23_message(indentation_width, current_indent_type)
105
- when nil
106
- method = "some library(e.g. ActiveSupport's `String#strip_heredoc`)"
107
- library_message(indentation_width, method)
108
- else
109
- method = "`String##{STRIP_METHODS[style]}`"
110
- library_message(indentation_width, method)
111
- end
112
- end
113
-
114
- def library_message(indentation_width, method)
115
- format(
116
- LIBRARY_MSG,
117
- indentation_width: indentation_width,
118
- method: method
119
- )
120
- end
63
+ current_indent_type = "<<#{heredoc_indent_type(node)}"
121
64
 
122
- def ruby23_message(indentation_width, current_indent_type)
123
65
  if current_indent_type == '<<~'
124
- ruby23_width_message(indentation_width)
66
+ width_message(indentation_width)
125
67
  else
126
- ruby23_type_message(indentation_width, current_indent_type)
68
+ type_message(indentation_width, current_indent_type)
127
69
  end
128
70
  end
129
71
 
130
- def ruby23_type_message(indentation_width, current_indent_type)
72
+ def type_message(indentation_width, current_indent_type)
131
73
  format(
132
- RUBY23_TYPE_MSG,
74
+ TYPE_MSG,
133
75
  indentation_width: indentation_width,
134
76
  current_indent_type: current_indent_type
135
77
  )
136
78
  end
137
79
 
138
- def ruby23_width_message(indentation_width)
80
+ def width_message(indentation_width)
139
81
  format(
140
- RUBY23_WIDTH_MSG,
82
+ WIDTH_MSG,
141
83
  indentation_width: indentation_width
142
84
  )
143
85
  end
@@ -166,16 +108,6 @@ module RuboCop
166
108
  config.for_cop('Layout/LineLength')['Max']
167
109
  end
168
110
 
169
- def correct_by_squiggly(node)
170
- lambda do |corrector|
171
- if heredoc_indent_type(node) == '~'
172
- adjust_squiggly(corrector, node)
173
- else
174
- adjust_minus(corrector, node)
175
- end
176
- end
177
- end
178
-
179
111
  def adjust_squiggly(corrector, node)
180
112
  corrector.replace(node.loc.heredoc_body, indented_body(node))
181
113
  corrector.replace(node.loc.heredoc_end, indented_end(node))
@@ -187,21 +119,6 @@ module RuboCop
187
119
  corrector.replace(node, corrected)
188
120
  end
189
121
 
190
- def correct_by_library(node)
191
- lambda do |corrector|
192
- corrector.replace(node.loc.heredoc_body, indented_body(node))
193
- corrected = ".#{STRIP_METHODS[style]}"
194
- corrector.insert_after(node, corrected)
195
- end
196
- end
197
-
198
- def check_style!
199
- return if style
200
-
201
- raise Warning, "Auto-correction does not work for #{cop_name}. " \
202
- 'Please configure EnforcedStyle.'
203
- end
204
-
205
122
  def indented_body(node)
206
123
  body = heredoc_body(node)
207
124
  body_indent_level = indent_level(body)
@@ -230,7 +147,7 @@ module RuboCop
230
147
  def indent_level(str)
231
148
  indentations = str.lines
232
149
  .map { |line| line[/^\s*/] }
233
- .reject { |line| line == "\n" }
150
+ .reject { |line| line.end_with?("\n") }
234
151
  indentations.empty? ? 0 : indentations.min_by(&:size).size
235
152
  end
236
153