rubocop 0.84.0 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  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 +14 -6
  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 +19 -102
  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/loop.rb +1 -1
  38. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +62 -0
  39. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  40. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
  41. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -1
  42. data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
  43. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  44. data/lib/rubocop/cop/lint/suppressed_exception.rb +4 -2
  45. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  46. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
  47. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  48. data/lib/rubocop/cop/migration/department_name.rb +9 -5
  49. data/lib/rubocop/cop/mixin/array_min_size.rb +3 -1
  50. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -1
  51. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  52. data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
  53. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
  54. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
  55. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
  56. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -1
  57. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
  58. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
  59. data/lib/rubocop/cop/naming/file_name.rb +26 -11
  60. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  61. data/lib/rubocop/cop/registry.rb +3 -1
  62. data/lib/rubocop/cop/style/array_join.rb +1 -1
  63. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  64. data/lib/rubocop/cop/style/copyright.rb +2 -2
  65. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  66. data/lib/rubocop/cop/style/exponential_notation.rb +3 -3
  67. data/lib/rubocop/cop/style/format_string_token.rb +2 -3
  68. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -2
  69. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -1
  70. data/lib/rubocop/cop/style/hash_syntax.rb +5 -3
  71. data/lib/rubocop/cop/style/inline_comment.rb +1 -1
  72. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  73. data/lib/rubocop/cop/style/negated_if.rb +3 -3
  74. data/lib/rubocop/cop/style/negated_unless.rb +3 -3
  75. data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
  76. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  77. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
  78. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
  79. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  80. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
  81. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
  82. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
  83. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
  84. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +3 -1
  85. data/lib/rubocop/cop/style/unless_else.rb +1 -1
  86. data/lib/rubocop/cop/style/when_then.rb +1 -1
  87. data/lib/rubocop/cop/team.rb +61 -25
  88. data/lib/rubocop/cop/util.rb +1 -1
  89. data/lib/rubocop/cop/variable_force/branch.rb +3 -1
  90. data/lib/rubocop/formatter/junit_formatter.rb +14 -4
  91. data/lib/rubocop/magic_comment.rb +1 -1
  92. data/lib/rubocop/options.rb +17 -3
  93. data/lib/rubocop/result_cache.rb +4 -4
  94. data/lib/rubocop/rspec/cop_helper.rb +2 -23
  95. data/lib/rubocop/rspec/expect_offense.rb +42 -6
  96. data/lib/rubocop/rspec/shared_contexts.rb +2 -2
  97. data/lib/rubocop/runner.rb +14 -10
  98. data/lib/rubocop/target_finder.rb +3 -1
  99. data/lib/rubocop/target_ruby.rb +4 -1
  100. data/lib/rubocop/version.rb +1 -1
  101. metadata +21 -3
@@ -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)
@@ -21,23 +21,23 @@ module RuboCop
21
21
  # are recommended to further format the broken lines.
22
22
  # (Many of these are enabled by default.)
23
23
  #
24
- # - ArgumentAlignment
25
- # - BlockAlignment
26
- # - BlockDelimiters
27
- # - BlockEndNewline
28
- # - ClosingParenthesisIndentation
29
- # - FirstArgumentIndentation
30
- # - FirstArrayElementIndentation
31
- # - FirstHashElementIndentation
32
- # - FirstParameterIndentation
33
- # - HashAlignment
34
- # - IndentationWidth
35
- # - MultilineArrayLineBreaks
36
- # - MultilineBlockLayout
37
- # - MultilineHashBraceLayout
38
- # - MultilineHashKeyLineBreaks
39
- # - MultilineMethodArgumentLineBreaks
40
- # - ParameterAlignment
24
+ # * ArgumentAlignment
25
+ # * BlockAlignment
26
+ # * BlockDelimiters
27
+ # * BlockEndNewline
28
+ # * ClosingParenthesisIndentation
29
+ # * FirstArgumentIndentation
30
+ # * FirstArrayElementIndentation
31
+ # * FirstHashElementIndentation
32
+ # * FirstParameterIndentation
33
+ # * HashAlignment
34
+ # * IndentationWidth
35
+ # * MultilineArrayLineBreaks
36
+ # * MultilineBlockLayout
37
+ # * MultilineHashBraceLayout
38
+ # * MultilineHashKeyLineBreaks
39
+ # * MultilineMethodArgumentLineBreaks
40
+ # * ParameterAlignment
41
41
  #
42
42
  # Together, these cops will pretty print hashes, arrays,
43
43
  # method calls, etc. For example, let's say the max columns
@@ -81,7 +81,9 @@ module RuboCop
81
81
 
82
82
  expr_before_body ||= node.loc.begin
83
83
 
84
- autocorrect_body(corrector, node, node.body) if expr_before_body.line == node.body.first_line
84
+ if expr_before_body.line == node.body.first_line
85
+ autocorrect_body(corrector, node, node.body)
86
+ end
85
87
  end
86
88
  end
87
89
 
@@ -186,7 +186,7 @@ module RuboCop
186
186
  pos = range.begin_pos - 1
187
187
  return false if pos.negative?
188
188
 
189
- range.source_buffer.source[pos] !~ /[\s\(\|\{\[;,\*\=]/
189
+ range.source_buffer.source[pos] !~ /[\s(|{\[;,*=]/
190
190
  end
191
191
 
192
192
  def space_after_missing?(range)
@@ -198,7 +198,7 @@ module RuboCop
198
198
  return false if accept_namespace_operator?(range) &&
199
199
  namespace_operator?(range, pos)
200
200
 
201
- char !~ /[\s;,#\\\)\}\]\.]/
201
+ char !~ /[\s;,#\\)}\].]/
202
202
  end
203
203
 
204
204
  def accepted_opening_delimiter?(range, char)