rubocop 0.84.0 → 0.85.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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)
@@ -72,7 +72,9 @@ module RuboCop
72
72
  left = previous_token(operator)
73
73
  right = next_token(operator)
74
74
 
75
- no_space_offenses(node, operator, right, MSG) if !right.comment? && valid_right_token?(right, operator)
75
+ if !right.comment? && valid_right_token?(right, operator)
76
+ no_space_offenses(node, operator, right, MSG)
77
+ end
76
78
  return unless valid_left_token?(left, operator)
77
79
 
78
80
  no_space_offenses(node, left, operator, MSG) if add_left_offense
@@ -72,7 +72,9 @@ module RuboCop
72
72
 
73
73
  right_token = closing_bracket(tokens, left_token)
74
74
 
75
- return empty_offenses(node, left_token, right_token, EMPTY_MSG) if empty_brackets?(left_token, right_token)
75
+ if empty_brackets?(left_token, right_token)
76
+ return empty_offenses(node, left_token, right_token, EMPTY_MSG)
77
+ end
76
78
 
77
79
  if style == :no_space
78
80
  no_space_offenses(node, left_token, right_token, MSG)
@@ -63,7 +63,8 @@ module RuboCop
63
63
  first_argument = send_node.first_argument
64
64
 
65
65
  first_argument &&
66
- offense_position?(first_argument, diagnostic) && unary_operator?(first_argument, diagnostic)
66
+ offense_position?(first_argument, diagnostic) &&
67
+ unary_operator?(first_argument, diagnostic)
67
68
  end
68
69
  end
69
70
 
@@ -53,6 +53,8 @@ module RuboCop
53
53
  PATTERN
54
54
 
55
55
  def on_send(node)
56
+ return if node.arguments.any? { |arg| arg.variable? || arg.send_type? || arg.const_type? }
57
+
56
58
  add_offense(node) if algorithm_const(node)
57
59
  end
58
60
 
@@ -88,9 +90,7 @@ module RuboCop
88
90
  end
89
91
 
90
92
  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)
93
+ range_between(node.loc.dot.end_pos, node.loc.expression.end_pos)
94
94
  end
95
95
 
96
96
  def openssl_class(node)
@@ -108,7 +108,11 @@ module RuboCop
108
108
  end
109
109
 
110
110
  def sanitize_arguments(arguments)
111
- arguments.flat_map { |arg| arg.source.tr(":'", '').split('-') }
111
+ arguments.flat_map do |arg|
112
+ argument = arg.str_type? ? arg.value : arg.source
113
+
114
+ argument.tr(":'", '').split('-')
115
+ end
112
116
  end
113
117
 
114
118
  def replacement_args(node)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This cop checks for *return* from an *ensure* block.
6
+ # This cop checks for `return` from an `ensure` block.
7
7
  # Explicit return from an ensure block alters the control flow
8
8
  # as the return will take precedence over any exception being raised,
9
9
  # and the exception will be silently thrown away as if it were rescued.
@@ -143,7 +143,9 @@ module RuboCop
143
143
 
144
144
  overridden_kwargs[0] = "trim_mode: #{arguments[2].source}" if arguments[2]
145
145
 
146
- overridden_kwargs[1] = "eoutvar: #{arguments[3].source}" if arguments[3] && !arguments[3].hash_type?
146
+ if arguments[3] && !arguments[3].hash_type?
147
+ overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
148
+ end
147
149
 
148
150
  overridden_kwargs
149
151
  end
@@ -7,6 +7,10 @@ module RuboCop
7
7
  # expected fields for format/sprintf/#% and what is actually
8
8
  # passed as arguments.
9
9
  #
10
+ # In addition it checks whether different formats are used in the same
11
+ # format string. Do not mix numbered, unnumbered, and named formats in
12
+ # the same format string.
13
+ #
10
14
  # @example
11
15
  #
12
16
  # # bad
@@ -18,16 +22,37 @@ module RuboCop
18
22
  # # good
19
23
  #
20
24
  # format('A value: %s and another: %i', a_value, another)
25
+ #
26
+ # @example
27
+ #
28
+ # # bad
29
+ #
30
+ # format('Unnumbered format: %s and numbered: %2$s', a_value, another)
31
+ #
32
+ # @example
33
+ #
34
+ # # good
35
+ #
36
+ # format('Numbered format: %1$s and numbered %2$s', a_value, another)
21
37
  class FormatParameterMismatch < Cop
22
38
  # http://rubular.com/r/CvpbxkcTzy
23
39
  MSG = "Number of arguments (%<arg_num>i) to `%<method>s` doesn't " \
24
40
  'match the number of fields (%<field_num>i).'
41
+ MSG_INVALID = 'Format string is invalid because formatting sequence types ' \
42
+ '(numbered, named or unnumbered) are mixed.'
25
43
 
26
44
  KERNEL = 'Kernel'
27
45
  SHOVEL = '<<'
28
46
  STRING_TYPES = %i[str dstr].freeze
29
47
 
30
48
  def on_send(node)
49
+ return unless format_string?(node)
50
+
51
+ if invalid_format_string?(node)
52
+ add_offense(node, location: :selector, message: MSG_INVALID)
53
+ return
54
+ end
55
+
31
56
  return unless offending_node?(node)
32
57
 
33
58
  add_offense(node, location: :selector)
@@ -35,9 +60,15 @@ module RuboCop
35
60
 
36
61
  private
37
62
 
63
+ def format_string?(node)
64
+ called_on_string?(node) && method_with_format_args?(node)
65
+ end
66
+
67
+ def invalid_format_string?(node)
68
+ !RuboCop::Cop::Utils::FormatString.new(node.source).valid?
69
+ end
70
+
38
71
  def offending_node?(node)
39
- return false unless called_on_string?(node)
40
- return false unless method_with_format_args?(node)
41
72
  return false if splat_args?(node)
42
73
 
43
74
  num_of_format_args, num_of_expected_fields = count_matches(node)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This cop checks for uses of *begin...end while/until something*.
6
+ # This cop checks for uses of `begin...end while/until something`.
7
7
  #
8
8
  # @example
9
9
  #
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # Do not mix named captures and numbered captures in a Regexp literal
7
+ # because numbered capture is ignored if they're mixed.
8
+ # Replace numbered captures with non-capturing groupings or
9
+ # named captures.
10
+ #
11
+ # # bad
12
+ # /(?<foo>FOO)(BAR)/
13
+ #
14
+ # # good
15
+ # /(?<foo>FOO)(?<bar>BAR)/
16
+ #
17
+ # # good
18
+ # /(?<foo>FOO)(?:BAR)/
19
+ #
20
+ # # good
21
+ # /(FOO)(BAR)/
22
+ #
23
+ class MixedRegexpCaptureTypes < Cop
24
+ MSG = 'Do not mix named captures and numbered captures ' \
25
+ 'in a Regexp literal.'
26
+
27
+ def on_regexp(node)
28
+ return if contain_non_literal?(node)
29
+
30
+ begin
31
+ tree = Regexp::Parser.parse(node.content)
32
+ # Returns if a regular expression that cannot be processed by regexp_parser gem.
33
+ # https://github.com/rubocop-hq/rubocop/issues/8083
34
+ rescue Regexp::Scanner::ScannerError
35
+ return
36
+ end
37
+
38
+ return unless named_capture?(tree)
39
+ return unless numbered_capture?(tree)
40
+
41
+ add_offense(node)
42
+ end
43
+
44
+ private
45
+
46
+ def contain_non_literal?(node)
47
+ if node.respond_to?(:type) && (node.variable? || node.send_type? || node.const_type?)
48
+ return true
49
+ end
50
+ return false unless node.respond_to?(:children)
51
+
52
+ node.children.any? { |child| contain_non_literal?(child) }
53
+ end
54
+
55
+ def named_capture?(tree)
56
+ tree.each_expression.any? do |e|
57
+ e.instance_of?(Regexp::Expression::Group::Capture)
58
+ end
59
+ end
60
+
61
+ def numbered_capture?(tree)
62
+ tree.each_expression.any? do |e|
63
+ e.instance_of?(Regexp::Expression::Group::Named)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -42,7 +42,7 @@ module RuboCop
42
42
  def contains_percent_literals?(node)
43
43
  node.each_child_node.any? do |child|
44
44
  literal = child.children.first.to_s.scrub
45
- REGEXES.any? { |regex| literal.match(regex) }
45
+ REGEXES.any? { |regex| literal.match?(regex) }
46
46
  end
47
47
  end
48
48
  end
@@ -6,13 +6,13 @@ module RuboCop
6
6
  # This cop checks for non-local exits from iterators without a return
7
7
  # value. It registers an offense under these conditions:
8
8
  #
9
- # - No value is returned,
10
- # - the block is preceded by a method chain,
11
- # - the block has arguments,
12
- # - the method which receives the block is not `define_method`
13
- # or `define_singleton_method`,
14
- # - the return is not contained in an inner scope, e.g. a lambda or a
15
- # method definition.
9
+ # * No value is returned,
10
+ # * the block is preceded by a method chain,
11
+ # * the block has arguments,
12
+ # * the method which receives the block is not `define_method`
13
+ # or `define_singleton_method`,
14
+ # * the return is not contained in an inner scope, e.g. a lambda or a
15
+ # method definition.
16
16
  #
17
17
  # @example
18
18
  #
@@ -44,7 +44,9 @@ module RuboCop
44
44
  private
45
45
 
46
46
  def valid_context?(node)
47
- return true unless node.arguments.one? && first_argument_starts_with_left_parenthesis?(node)
47
+ unless node.arguments.one? && first_argument_starts_with_left_parenthesis?(node)
48
+ return true
49
+ end
48
50
 
49
51
  node.operator_method? || node.setter_method? || grouped_parentheses?(node)
50
52
  end
@@ -8,9 +8,9 @@ module RuboCop
8
8
  # The following features are unnecessary `require` statement because
9
9
  # they are already loaded.
10
10
  #
11
- # ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
12
- # ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
13
- # ["enumerator.so", "rational.so", "complex.so", "thread.rb"]
11
+ # ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
12
+ # ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
13
+ # ["enumerator.so", "rational.so", "complex.so", "thread.rb"]
14
14
  #
15
15
  # This cop targets Ruby 2.2 or higher containing these 4 features.
16
16
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This cop checks for *rescue* blocks targeting the Exception class.
6
+ # This cop checks for `rescue` blocks targeting the Exception class.
7
7
  #
8
8
  # @example
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This cop checks for *rescue* blocks with no body.
6
+ # This cop checks for `rescue` blocks with no body.
7
7
  #
8
8
  # @example
9
9
  #
@@ -78,10 +78,12 @@ module RuboCop
78
78
 
79
79
  def comment_between_rescue_and_end?(node)
80
80
  end_line = nil
81
- node.each_ancestor(:kwbegin) do |ancestor|
81
+ node.each_ancestor(:kwbegin, :def, :defs, :block) do |ancestor|
82
82
  end_line = ancestor.loc.end.line
83
83
  break
84
84
  end
85
+ return false unless end_line
86
+
85
87
  processed_source[node.first_line...end_line].any? { |line| comment_line?(line) }
86
88
  end
87
89
  end
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Lint
6
6
  # This cop checks for unreachable code.
7
7
  # The check are based on the presence of flow of control
8
- # statement in non-final position in *begin*(implicit) blocks.
8
+ # statement in non-final position in `begin` (implicit) blocks.
9
9
  #
10
10
  # @example
11
11
  #
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Lint
6
6
  # This cop checks for useless `else` in `begin..end` without `rescue`.
7
7
  #
8
- # Note: This syntax is no longer valid on Ruby 2.6 or higher and
8
+ # NOTE: This syntax is no longer valid on Ruby 2.6 or higher and
9
9
  # this cop is going to be removed at some point the future.
10
10
  #
11
11
  # @example
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # This cop checks for setter call to local variable as the final
7
7
  # expression of a function definition.
8
8
  #
9
- # Note: There are edge cases in which the local variable references a
9
+ # NOTE: There are edge cases in which the local variable references a
10
10
  # value that is also accessible outside the local scope. This is not
11
11
  # detected by the cop, and it can yield a false positive.
12
12
  #
@@ -24,10 +24,12 @@ module RuboCop
24
24
 
25
25
  offset = Regexp.last_match(1).length
26
26
 
27
- Regexp.last_match(4).scan(/[^,]+|[\W]+/) do |name|
27
+ Regexp.last_match(4).scan(/[^,]+|\W+/) do |name|
28
28
  trimmed_name = name.strip
29
29
 
30
- check_cop_name(trimmed_name, comment, offset) unless valid_content_token?(trimmed_name)
30
+ unless valid_content_token?(trimmed_name)
31
+ check_cop_name(trimmed_name, comment, offset)
32
+ end
31
33
 
32
34
  break if contain_unexpected_character_for_department_name?(name)
33
35
 
@@ -41,7 +43,9 @@ module RuboCop
41
43
  cop_name = range.source
42
44
  qualified_cop_name = Cop.registry.qualified_cop_name(cop_name,
43
45
  nil, shall_warn)
44
- qualified_cop_name = qualified_legacy_cop_name(cop_name) unless qualified_cop_name.include?('/')
46
+ unless qualified_cop_name.include?('/')
47
+ qualified_cop_name = qualified_legacy_cop_name(cop_name)
48
+ end
45
49
 
46
50
  ->(corrector) { corrector.replace(range, qualified_cop_name) }
47
51
  end
@@ -60,8 +64,8 @@ module RuboCop
60
64
  end
61
65
 
62
66
  def valid_content_token?(content_token)
63
- !/\W+/.match(content_token).nil? ||
64
- !DISABLING_COPS_CONTENT_TOKEN.match(content_token).nil?
67
+ /\W+/.match?(content_token) ||
68
+ DISABLING_COPS_CONTENT_TOKEN.match?(content_token)
65
69
  end
66
70
 
67
71
  def contain_unexpected_character_for_department_name?(name)