rubocop 0.83.0 → 0.84.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +20 -3
  4. data/lib/rubocop.rb +6 -59
  5. data/lib/rubocop/ast_aliases.rb +8 -0
  6. data/lib/rubocop/cli/command/show_cops.rb +2 -6
  7. data/lib/rubocop/config.rb +1 -3
  8. data/lib/rubocop/config_loader.rb +3 -9
  9. data/lib/rubocop/config_loader_resolver.rb +2 -6
  10. data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
  11. data/lib/rubocop/cop/corrector.rb +1 -3
  12. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
  13. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -3
  14. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
  15. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
  16. data/lib/rubocop/cop/generator.rb +1 -1
  17. data/lib/rubocop/cop/ignored_node.rb +1 -3
  18. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
  19. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +62 -4
  20. data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
  21. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
  22. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
  23. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -6
  24. data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
  25. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -3
  26. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
  27. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -6
  28. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
  29. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
  30. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
  31. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -2
  32. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
  33. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -6
  34. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +11 -3
  35. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -3
  36. data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -1
  37. data/lib/rubocop/cop/lint/syntax.rb +1 -3
  38. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -3
  39. data/lib/rubocop/cop/migration/department_name.rb +5 -9
  40. data/lib/rubocop/cop/mixin/alignment.rb +1 -3
  41. data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
  42. data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
  43. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
  44. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
  45. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -3
  46. data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -3
  47. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -3
  48. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  49. data/lib/rubocop/cop/registry.rb +2 -6
  50. data/lib/rubocop/cop/severity.rb +1 -3
  51. data/lib/rubocop/cop/style/and_or.rb +2 -2
  52. data/lib/rubocop/cop/style/attr.rb +1 -3
  53. data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -3
  55. data/lib/rubocop/cop/style/double_negation.rb +41 -4
  56. data/lib/rubocop/cop/style/empty_literal.rb +1 -3
  57. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -4
  58. data/lib/rubocop/cop/style/hash_syntax.rb +12 -5
  59. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
  60. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
  61. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
  62. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
  63. data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
  64. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  65. data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
  66. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -3
  67. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -6
  68. data/lib/rubocop/cop/variable_force.rb +3 -9
  69. data/lib/rubocop/cop/variable_force/branch.rb +2 -6
  70. data/lib/rubocop/cop/variable_force/variable.rb +2 -6
  71. data/lib/rubocop/ext/processed_source.rb +18 -0
  72. data/lib/rubocop/formatter/base_formatter.rb +0 -4
  73. data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
  74. data/lib/rubocop/formatter/formatter_set.rb +1 -3
  75. data/lib/rubocop/options.rb +2 -8
  76. data/lib/rubocop/remote_config.rb +1 -3
  77. data/lib/rubocop/result_cache.rb +1 -3
  78. data/lib/rubocop/rspec/cop_helper.rb +1 -3
  79. data/lib/rubocop/rspec/expect_offense.rb +3 -9
  80. data/lib/rubocop/rspec/shared_contexts.rb +54 -16
  81. data/lib/rubocop/runner.rb +8 -10
  82. data/lib/rubocop/target_finder.rb +2 -6
  83. data/lib/rubocop/version.rb +5 -3
  84. metadata +19 -56
  85. data/lib/rubocop/ast/builder.rb +0 -85
  86. data/lib/rubocop/ast/node.rb +0 -637
  87. data/lib/rubocop/ast/node/alias_node.rb +0 -24
  88. data/lib/rubocop/ast/node/and_node.rb +0 -29
  89. data/lib/rubocop/ast/node/args_node.rb +0 -29
  90. data/lib/rubocop/ast/node/array_node.rb +0 -70
  91. data/lib/rubocop/ast/node/block_node.rb +0 -121
  92. data/lib/rubocop/ast/node/break_node.rb +0 -17
  93. data/lib/rubocop/ast/node/case_match_node.rb +0 -56
  94. data/lib/rubocop/ast/node/case_node.rb +0 -56
  95. data/lib/rubocop/ast/node/class_node.rb +0 -31
  96. data/lib/rubocop/ast/node/def_node.rb +0 -82
  97. data/lib/rubocop/ast/node/defined_node.rb +0 -17
  98. data/lib/rubocop/ast/node/ensure_node.rb +0 -17
  99. data/lib/rubocop/ast/node/float_node.rb +0 -12
  100. data/lib/rubocop/ast/node/for_node.rb +0 -53
  101. data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
  102. data/lib/rubocop/ast/node/hash_node.rb +0 -109
  103. data/lib/rubocop/ast/node/if_node.rb +0 -175
  104. data/lib/rubocop/ast/node/int_node.rb +0 -12
  105. data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
  106. data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
  107. data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
  108. data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
  109. data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
  110. data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
  111. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -269
  112. data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
  113. data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
  114. data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
  115. data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
  116. data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
  117. data/lib/rubocop/ast/node/module_node.rb +0 -24
  118. data/lib/rubocop/ast/node/or_node.rb +0 -29
  119. data/lib/rubocop/ast/node/pair_node.rb +0 -63
  120. data/lib/rubocop/ast/node/range_node.rb +0 -18
  121. data/lib/rubocop/ast/node/regexp_node.rb +0 -33
  122. data/lib/rubocop/ast/node/resbody_node.rb +0 -24
  123. data/lib/rubocop/ast/node/retry_node.rb +0 -17
  124. data/lib/rubocop/ast/node/return_node.rb +0 -24
  125. data/lib/rubocop/ast/node/self_class_node.rb +0 -24
  126. data/lib/rubocop/ast/node/send_node.rb +0 -17
  127. data/lib/rubocop/ast/node/str_node.rb +0 -16
  128. data/lib/rubocop/ast/node/super_node.rb +0 -21
  129. data/lib/rubocop/ast/node/symbol_node.rb +0 -12
  130. data/lib/rubocop/ast/node/until_node.rb +0 -35
  131. data/lib/rubocop/ast/node/when_node.rb +0 -53
  132. data/lib/rubocop/ast/node/while_node.rb +0 -35
  133. data/lib/rubocop/ast/node/yield_node.rb +0 -21
  134. data/lib/rubocop/ast/sexp.rb +0 -16
  135. data/lib/rubocop/ast/traversal.rb +0 -202
  136. data/lib/rubocop/node_pattern.rb +0 -887
  137. data/lib/rubocop/processed_source.rb +0 -213
  138. data/lib/rubocop/token.rb +0 -114
@@ -2,7 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Cop
5
- # rubocop:disable Layout/LineLength
6
5
  module Layout
7
6
  # This cop checks the indentation of the first argument in a method call.
8
7
  # Arguments after the first one are checked by Layout/ArgumentAlignment,
@@ -143,7 +142,6 @@ module RuboCop
143
142
  # second_param
144
143
  #
145
144
  class FirstArgumentIndentation < Cop
146
- # rubocop:enable Layout/LineLength
147
145
  include Alignment
148
146
  include ConfigurableEnforcedStyle
149
147
  include RangeHelp
@@ -125,9 +125,7 @@ module RuboCop
125
125
 
126
126
  def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
127
127
  # if the right bracket is on the same line as the last value, accept
128
- if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
129
- return
130
- end
128
+ return if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
131
129
 
132
130
  expected_column = base_column(left_bracket, left_parenthesis)
133
131
  @column_delta = expected_column - right_bracket.column
@@ -36,9 +36,7 @@ module RuboCop
36
36
  # ...then each key/value pair is treated as a method 'argument'
37
37
  # when determining where line breaks should appear.
38
38
  if (last_arg = args.last)
39
- if last_arg.hash_type? && !last_arg.braces?
40
- args = args.concat(args.pop.children)
41
- end
39
+ args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
42
40
  end
43
41
 
44
42
  check_method_line_break(node, args)
@@ -98,13 +98,9 @@ module RuboCop
98
98
  lambda do |corrector|
99
99
  fix_closing_parenthesis(node, corrector)
100
100
 
101
- if internal_trailing_comma?(node)
102
- remove_internal_trailing_comma(node, corrector)
103
- end
101
+ remove_internal_trailing_comma(node, corrector) if internal_trailing_comma?(node)
104
102
 
105
- if external_trailing_comma?(node)
106
- fix_external_trailing_comma(node, corrector)
107
- end
103
+ fix_external_trailing_comma(node, corrector) if external_trailing_comma?(node)
108
104
  end
109
105
  end
110
106
 
@@ -263,9 +263,7 @@ module RuboCop
263
263
  def offense(body_node, indentation, style)
264
264
  # This cop only auto-corrects the first statement in a def body, for
265
265
  # example.
266
- if body_node.begin_type? && !parentheses?(body_node)
267
- body_node = body_node.children.first
268
- end
266
+ body_node = body_node.children.first if body_node.begin_type? && !parentheses?(body_node)
269
267
 
270
268
  # Since autocorrect changes a number of lines, and not only the line
271
269
  # where the reported offending range is, we avoid auto-correction if
@@ -81,9 +81,7 @@ module RuboCop
81
81
 
82
82
  expr_before_body ||= node.loc.begin
83
83
 
84
- if expr_before_body.line == node.body.first_line
85
- autocorrect_body(corrector, node, node.body)
86
- end
84
+ autocorrect_body(corrector, node, node.body) if expr_before_body.line == node.body.first_line
87
85
  end
88
86
  end
89
87
 
@@ -37,9 +37,7 @@ module RuboCop
37
37
  # ...then each key/value pair is treated as a method 'argument'
38
38
  # when determining where line breaks should appear.
39
39
  if (last_arg = args.last)
40
- if last_arg.hash_type? && !last_arg.braces?
41
- args = args.concat(args.pop.children)
42
- end
40
+ args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
43
41
  end
44
42
 
45
43
  check_line_breaks(node, args)
@@ -72,9 +72,7 @@ module RuboCop
72
72
  left = previous_token(operator)
73
73
  right = next_token(operator)
74
74
 
75
- if !right.comment? && valid_right_token?(right, operator)
76
- no_space_offenses(node, operator, right, MSG)
77
- end
75
+ no_space_offenses(node, operator, right, MSG) if !right.comment? && valid_right_token?(right, operator)
78
76
  return unless valid_left_token?(left, operator)
79
77
 
80
78
  no_space_offenses(node, left, operator, MSG) if add_left_offense
@@ -121,9 +119,7 @@ module RuboCop
121
119
 
122
120
  def right_token_for_auto_correction(operator)
123
121
  right_token = next_token(operator)
124
- if !right_token.comment? && valid_right_token?(right_token, operator)
125
- return right_token
126
- end
122
+ return right_token if !right_token.comment? && valid_right_token?(right_token, operator)
127
123
 
128
124
  operator
129
125
  end
@@ -20,9 +20,7 @@ module RuboCop
20
20
  next unless token2.comment?
21
21
  next unless token1.line == token2.line
22
22
 
23
- if token1.pos.end == token2.pos.begin
24
- add_offense(token2.pos, location: token2.pos)
25
- end
23
+ add_offense(token2.pos, location: token2.pos) if token1.pos.end == token2.pos.begin
26
24
  end
27
25
  end
28
26
 
@@ -78,9 +78,7 @@ module RuboCop
78
78
  return unless node.square_brackets?
79
79
 
80
80
  left, right = array_brackets(node)
81
- if empty_brackets?(left, right)
82
- return empty_offenses(node, left, right, EMPTY_MSG)
83
- end
81
+ return empty_offenses(node, left, right, EMPTY_MSG) if empty_brackets?(left, right)
84
82
 
85
83
  start_ok = next_to_newline?(node, left)
86
84
  end_ok = node.single_line? ? false : end_has_own_line?(right)
@@ -72,9 +72,7 @@ module RuboCop
72
72
 
73
73
  right_token = closing_bracket(tokens, left_token)
74
74
 
75
- if empty_brackets?(left_token, right_token)
76
- return empty_offenses(node, left_token, right_token, EMPTY_MSG)
77
- end
75
+ return empty_offenses(node, left_token, right_token, EMPTY_MSG) if empty_brackets?(left_token, right_token)
78
76
 
79
77
  if style == :no_space
80
78
  no_space_offenses(node, left_token, right_token, MSG)
@@ -130,9 +128,7 @@ module RuboCop
130
128
  tokens[i..-1].each do |token|
131
129
  inner_left_brackets_needing_closure += 1 if token.left_bracket?
132
130
  inner_left_brackets_needing_closure -= 1 if token.right_bracket?
133
- if inner_left_brackets_needing_closure.zero? && token.right_bracket?
134
- return token
135
- end
131
+ return token if inner_left_brackets_needing_closure.zero? && token.right_bracket?
136
132
  end
137
133
  end
138
134
 
@@ -60,8 +60,10 @@ module RuboCop
60
60
  end
61
61
 
62
62
  ast.each_node(:send).find do |send_node|
63
- offense_position?(send_node.first_argument, diagnostic) &&
64
- unary_operator?(send_node.first_argument, diagnostic)
63
+ first_argument = send_node.first_argument
64
+
65
+ first_argument &&
66
+ offense_position?(first_argument, diagnostic) && unary_operator?(first_argument, diagnostic)
65
67
  end
66
68
  end
67
69
 
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # Algorithmic constants for `OpenSSL::Cipher` and `OpenSSL::Digest`
7
+ # deprecated since OpenSSL version 2.2.0. Prefer passing a string
8
+ # instead.
9
+ #
10
+ # @example
11
+ #
12
+ # # Example for OpenSSL::Cipher instantiation.
13
+ #
14
+ # # bad
15
+ # OpenSSL::Cipher::AES.new(128, :GCM)
16
+ #
17
+ # # good
18
+ # OpenSSL::Cipher.new('AES-128-GCM')
19
+ #
20
+ # @example
21
+ #
22
+ # # Example for OpenSSL::Digest instantiation.
23
+ #
24
+ # # bad
25
+ # OpenSSL::Digest::SHA256.new
26
+ #
27
+ # # good
28
+ # OpenSSL::Digest.new('SHA256')
29
+ #
30
+ # @example
31
+ #
32
+ # # Example for ::Digest inherited class methods.
33
+ #
34
+ # # bad
35
+ # OpenSSL::Digest::SHA256.digest('foo')
36
+ #
37
+ # # good
38
+ # OpenSSL::Digest.digest('SHA256', 'foo')
39
+ #
40
+ class DeprecatedOpenSSLConstant < Cop
41
+ include RangeHelp
42
+
43
+ MSG = 'Use `%<constant>s.%<method>s(%<replacement_args>s)`' \
44
+ ' instead of `%<original>s`.'
45
+
46
+ def_node_matcher :algorithm_const, <<~PATTERN
47
+ (send
48
+ $(const
49
+ (const
50
+ (const {nil? cbase} :OpenSSL) {:Cipher :Digest})
51
+ _)
52
+ ...)
53
+ PATTERN
54
+
55
+ def on_send(node)
56
+ add_offense(node) if algorithm_const(node)
57
+ end
58
+
59
+ def autocorrect(node)
60
+ algorithm_constant, = algorithm_const(node)
61
+
62
+ lambda do |corrector|
63
+ corrector.remove(algorithm_constant.loc.double_colon)
64
+ corrector.remove(algorithm_constant.loc.name)
65
+
66
+ corrector.replace(
67
+ correction_range(node),
68
+ "#{node.loc.selector.source}(#{replacement_args(node)})"
69
+ )
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def message(node)
76
+ algorithm_constant, = algorithm_const(node)
77
+ parent_constant = openssl_class(algorithm_constant)
78
+ replacement_args = replacement_args(node)
79
+ method = node.loc.selector.source
80
+
81
+ format(
82
+ MSG,
83
+ constant: parent_constant,
84
+ method: method,
85
+ replacement_args: replacement_args,
86
+ original: node.source
87
+ )
88
+ end
89
+
90
+ def correction_range(node)
91
+ begin_pos = node.loc.selector.column
92
+ end_pos = node.loc.expression.last_column
93
+ range_between(begin_pos, end_pos)
94
+ end
95
+
96
+ def openssl_class(node)
97
+ node.children.first.source
98
+ end
99
+
100
+ def algorithm_name(node)
101
+ name = node.loc.name.source
102
+
103
+ if openssl_class(node) == 'OpenSSL::Cipher'
104
+ name.scan(/.{3}/).join('-')
105
+ else
106
+ name
107
+ end
108
+ end
109
+
110
+ def sanitize_arguments(arguments)
111
+ arguments.flat_map { |arg| arg.source.tr(":'", '').split('-') }
112
+ end
113
+
114
+ def replacement_args(node)
115
+ algorithm_constant, = algorithm_const(node)
116
+ algorithm_name = algorithm_name(algorithm_constant)
117
+
118
+ if openssl_class(algorithm_constant) == 'OpenSSL::Cipher'
119
+ build_cipher_arguments(node, algorithm_name)
120
+ else
121
+ (["'#{algorithm_name}'"] + node.arguments.map(&:source)).join(', ')
122
+ end
123
+ end
124
+
125
+ def build_cipher_arguments(node, algorithm_name)
126
+ algorithm_parts = algorithm_name.split('-')
127
+ size_and_mode = sanitize_arguments(node.arguments)
128
+ "'#{(algorithm_parts + size_and_mode + ['CBC']).take(3).join('-')}'"
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -141,13 +141,9 @@ module RuboCop
141
141
  arguments = node.arguments
142
142
  overridden_kwargs = kwargs.dup
143
143
 
144
- if arguments[2]
145
- overridden_kwargs[0] = "trim_mode: #{arguments[2].source}"
146
- end
144
+ overridden_kwargs[0] = "trim_mode: #{arguments[2].source}" if arguments[2]
147
145
 
148
- if arguments[3] && !arguments[3].hash_type?
149
- overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
150
- end
146
+ overridden_kwargs[1] = "eoutvar: #{arguments[3].source}" if arguments[3] && !arguments[3].hash_type?
151
147
 
152
148
  overridden_kwargs
153
149
  end
@@ -21,9 +21,7 @@ module RuboCop
21
21
  MSG = '`(...)` interpreted as grouped expression.'
22
22
 
23
23
  def on_send(node)
24
- return unless node.arguments.one?
25
- return if node.operator_method? || node.setter_method?
26
- return if grouped_parentheses?(node)
24
+ return if valid_context?(node)
27
25
 
28
26
  space_length = spaces_before_left_parenthesis(node)
29
27
  return unless space_length.positive?
@@ -45,6 +43,16 @@ module RuboCop
45
43
 
46
44
  private
47
45
 
46
+ def valid_context?(node)
47
+ return true unless node.arguments.one? && first_argument_starts_with_left_parenthesis?(node)
48
+
49
+ node.operator_method? || node.setter_method? || grouped_parentheses?(node)
50
+ end
51
+
52
+ def first_argument_starts_with_left_parenthesis?(node)
53
+ node.first_argument.source.start_with?('(')
54
+ end
55
+
48
56
  def grouped_parentheses?(node)
49
57
  first_argument = node.first_argument
50
58
 
@@ -48,9 +48,7 @@ module RuboCop
48
48
  match = range.source.match(TRAILING_QUOTE)
49
49
  corrector.remove_trailing(range, match[0].length) if match
50
50
 
51
- if LEADING_QUOTE.match?(range.source)
52
- corrector.remove_leading(range, 1)
53
- end
51
+ corrector.remove_leading(range, 1) if LEADING_QUOTE.match?(range.source)
54
52
  end
55
53
  end
56
54
  end
@@ -69,10 +69,21 @@ module RuboCop
69
69
 
70
70
  def on_resbody(node)
71
71
  return if node.body
72
- return if cop_config['AllowComments'] && comment_lines?(node)
72
+ return if cop_config['AllowComments'] && comment_between_rescue_and_end?(node)
73
73
 
74
74
  add_offense(node)
75
75
  end
76
+
77
+ private
78
+
79
+ def comment_between_rescue_and_end?(node)
80
+ end_line = nil
81
+ node.each_ancestor(:kwbegin) do |ancestor|
82
+ end_line = ancestor.loc.end.line
83
+ break
84
+ end
85
+ processed_source[node.first_line...end_line].any? { |line| comment_line?(line) }
86
+ end
76
87
  end
77
88
  end
78
89
  end
@@ -16,9 +16,7 @@ module RuboCop
16
16
  config, options)
17
17
  cop = new(config, options)
18
18
 
19
- if processed_source.parser_error
20
- cop.add_offense_from_error(processed_source.parser_error)
21
- end
19
+ cop.add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
22
20
 
23
21
  processed_source.diagnostics.each do |diagnostic|
24
22
  cop.add_offense_from_diagnostic(diagnostic,
@@ -227,9 +227,7 @@ module RuboCop
227
227
  add_offense(node, message: format(MSG, current: cur_vis))
228
228
  else
229
229
  # was the previous modifier never applied to any defs?
230
- if unused
231
- add_offense(unused, message: format(MSG, current: cur_vis))
232
- end
230
+ add_offense(unused, message: format(MSG, current: cur_vis)) if unused
233
231
  # once we have already warned about a certain modifier, don't
234
232
  # warn again even if it is never applied to any method defs
235
233
  unused = node
@@ -27,11 +27,9 @@ module RuboCop
27
27
  Regexp.last_match(4).scan(/[^,]+|[\W]+/) do |name|
28
28
  trimmed_name = name.strip
29
29
 
30
- break if contain_plain_comment?(trimmed_name)
30
+ check_cop_name(trimmed_name, comment, offset) unless valid_content_token?(trimmed_name)
31
31
 
32
- unless valid_content_token?(trimmed_name)
33
- check_cop_name(trimmed_name, comment, offset)
34
- end
32
+ break if contain_unexpected_character_for_department_name?(name)
35
33
 
36
34
  offset += name.length
37
35
  end
@@ -43,9 +41,7 @@ module RuboCop
43
41
  cop_name = range.source
44
42
  qualified_cop_name = Cop.registry.qualified_cop_name(cop_name,
45
43
  nil, shall_warn)
46
- unless qualified_cop_name.include?('/')
47
- qualified_cop_name = qualified_legacy_cop_name(cop_name)
48
- end
44
+ qualified_cop_name = qualified_legacy_cop_name(cop_name) unless qualified_cop_name.include?('/')
49
45
 
50
46
  ->(corrector) { corrector.replace(range, qualified_cop_name) }
51
47
  end
@@ -68,8 +64,8 @@ module RuboCop
68
64
  !DISABLING_COPS_CONTENT_TOKEN.match(content_token).nil?
69
65
  end
70
66
 
71
- def contain_plain_comment?(name)
72
- name == '#'
67
+ def contain_unexpected_character_for_department_name?(name)
68
+ name.match?(%r{[^A-z/, ]})
73
69
  end
74
70
 
75
71
  def qualified_legacy_cop_name(cop_name)