rubocop 1.64.1 → 1.65.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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +11 -1
  4. data/lib/rubocop/config_loader.rb +1 -1
  5. data/lib/rubocop/config_loader_resolver.rb +9 -3
  6. data/lib/rubocop/cop/cop.rb +22 -4
  7. data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
  8. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  9. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
  10. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  11. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  13. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
  14. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
  15. data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
  16. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  17. data/lib/rubocop/cop/layout/line_length.rb +20 -20
  18. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -0
  19. data/lib/rubocop/cop/legacy/corrector.rb +12 -2
  20. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  21. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  22. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  23. data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
  24. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  25. data/lib/rubocop/cop/lint/debugger.rb +0 -4
  26. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  27. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
  28. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  29. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  30. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  31. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  32. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  33. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  34. data/lib/rubocop/cop/lint/empty_when.rb +1 -3
  35. data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
  36. data/lib/rubocop/cop/lint/float_comparison.rb +3 -1
  37. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  38. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  39. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +15 -12
  40. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  41. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  42. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  43. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  44. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
  45. data/lib/rubocop/cop/lint/loop.rb +6 -12
  46. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -7
  47. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  48. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  49. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  50. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  51. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  52. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  53. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  54. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  55. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  56. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  57. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  58. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
  59. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  60. data/lib/rubocop/cop/lint/to_enum_arguments.rb +2 -9
  61. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  62. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  63. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -5
  64. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -5
  65. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  66. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  67. data/lib/rubocop/cop/lint/void.rb +5 -0
  68. data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
  69. data/lib/rubocop/cop/mixin/alignment.rb +5 -1
  70. data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
  71. data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
  72. data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
  73. data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
  74. data/lib/rubocop/cop/naming/predicate_name.rb +52 -26
  75. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  76. data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -1
  77. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  78. data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
  79. data/lib/rubocop/cop/style/eval_with_location.rb +12 -11
  80. data/lib/rubocop/cop/style/file_read.rb +2 -5
  81. data/lib/rubocop/cop/style/file_write.rb +2 -5
  82. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  83. data/lib/rubocop/cop/style/hash_except.rb +8 -5
  84. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +0 -1
  85. data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
  86. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +77 -43
  87. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +5 -0
  88. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  89. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  90. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  91. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  92. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  93. data/lib/rubocop/cop/style/redundant_condition.rb +0 -1
  94. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
  95. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  96. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +15 -1
  97. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  98. data/lib/rubocop/cop/style/super_arguments.rb +28 -10
  99. data/lib/rubocop/cop/style/symbol_proc.rb +8 -1
  100. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  101. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  102. data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
  103. data/lib/rubocop/cop/team.rb +8 -0
  104. data/lib/rubocop/cop/util.rb +7 -1
  105. data/lib/rubocop/cop/variable_force.rb +13 -1
  106. data/lib/rubocop/cops_documentation_generator.rb +1 -1
  107. data/lib/rubocop/core_ext/string.rb +2 -6
  108. data/lib/rubocop/ext/regexp_node.rb +9 -31
  109. data/lib/rubocop/ext/regexp_parser.rb +4 -21
  110. data/lib/rubocop/formatter/html_formatter.rb +3 -1
  111. data/lib/rubocop/options.rb +3 -1
  112. data/lib/rubocop/rspec/shared_contexts.rb +20 -0
  113. data/lib/rubocop/rspec/support.rb +1 -0
  114. data/lib/rubocop/server/cache.rb +10 -0
  115. data/lib/rubocop/server/client_command/exec.rb +2 -2
  116. data/lib/rubocop/server/client_command/start.rb +1 -1
  117. data/lib/rubocop/server/core.rb +4 -0
  118. data/lib/rubocop/version.rb +1 -1
  119. data/lib/rubocop.rb +6 -0
  120. metadata +7 -6
@@ -3,40 +3,30 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # Checks for empty `ensure` blocks
6
+ # Checks for empty `ensure` blocks.
7
7
  #
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # def some_method
13
12
  # do_something
14
13
  # ensure
15
14
  # end
16
15
  #
17
- # @example
18
- #
19
16
  # # bad
20
- #
21
17
  # begin
22
18
  # do_something
23
19
  # ensure
24
20
  # end
25
21
  #
26
- # @example
27
- #
28
22
  # # good
29
- #
30
23
  # def some_method
31
24
  # do_something
32
25
  # ensure
33
26
  # do_something_else
34
27
  # end
35
28
  #
36
- # @example
37
- #
38
29
  # # good
39
- #
40
30
  # begin
41
31
  # do_something
42
32
  # ensure
@@ -8,13 +8,9 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # "result is #{}"
13
12
  #
14
- # @example
15
- #
16
13
  # # good
17
- #
18
14
  # "result is #{some_result}"
19
15
  class EmptyInterpolation < Base
20
16
  include Interpolation
@@ -14,8 +14,6 @@ module RuboCop
14
14
  # when baz
15
15
  # end
16
16
  #
17
- # @example
18
- #
19
17
  # # good
20
18
  # case condition
21
19
  # when foo
@@ -50,7 +48,7 @@ module RuboCop
50
48
  MSG = 'Avoid `when` branches without a body.'
51
49
 
52
50
  def on_case(node)
53
- node.each_when do |when_node|
51
+ node.when_branches.each do |when_node|
54
52
  next if when_node.body
55
53
  next if cop_config['AllowComments'] && contains_comments?(when_node)
56
54
 
@@ -13,7 +13,6 @@ module RuboCop
13
13
  # @example
14
14
  #
15
15
  # # bad
16
- #
17
16
  # def foo
18
17
  # do_something
19
18
  # ensure
@@ -21,10 +20,7 @@ module RuboCop
21
20
  # return self
22
21
  # end
23
22
  #
24
- # @example
25
- #
26
23
  # # good
27
- #
28
24
  # def foo
29
25
  # do_something
30
26
  # self
@@ -32,8 +28,7 @@ module RuboCop
32
28
  # cleanup
33
29
  # end
34
30
  #
35
- # # also good
36
- #
31
+ # # good
37
32
  # def foo
38
33
  # begin
39
34
  # do_something
@@ -66,7 +66,9 @@ module RuboCop
66
66
  end
67
67
 
68
68
  def literal_zero?(node)
69
- node&.numeric_type? && node.value.zero?
69
+ # TODO: https://github.com/rubocop/rubocop-ast/pull/304 is released,
70
+ # replace this condition with `node&.numeric_type? && node.value.zero?`.
71
+ node&.numeric_type? && node.node_parts[0].zero?
70
72
  end
71
73
 
72
74
  # rubocop:disable Metrics/PerceivedComplexity
@@ -10,13 +10,9 @@ module RuboCop
10
10
  # @example
11
11
  #
12
12
  # # bad
13
- #
14
13
  # float = 3.0e400
15
14
  #
16
- # @example
17
- #
18
15
  # # good
19
- #
20
16
  # float = 42.9
21
17
  class FloatOutOfRange < Base
22
18
  MSG = 'Float out of range.'
@@ -14,25 +14,15 @@ module RuboCop
14
14
  # @example
15
15
  #
16
16
  # # bad
17
- #
18
17
  # format('A value: %s and another: %i', a_value)
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # format('A value: %s and another: %i', a_value, another)
25
21
  #
26
- # @example
27
- #
28
22
  # # bad
29
- #
30
23
  # format('Unnumbered format: %s and numbered: %2$s', a_value, another)
31
24
  #
32
- # @example
33
- #
34
25
  # # good
35
- #
36
26
  # format('Numbered format: %1$s and numbered %2$s', a_value, another)
37
27
  class FormatParameterMismatch < Base
38
28
  # http://rubular.com/r/CvpbxkcTzy
@@ -9,13 +9,9 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # array = ['Item 1' 'Item 2']
14
13
  #
15
- # @example
16
- #
17
14
  # # good
18
- #
19
15
  # array = ['Item 1Item 2']
20
16
  # array = ['Item 1' + 'Item 2']
21
17
  # array = [
@@ -23,27 +19,34 @@ module RuboCop
23
19
  # 'Item 2'
24
20
  # ]
25
21
  class ImplicitStringConcatenation < Base
26
- MSG = 'Combine %<string1>s and %<string2>s into a single string ' \
22
+ extend AutoCorrector
23
+
24
+ MSG = 'Combine %<lhs>s and %<rhs>s into a single string ' \
27
25
  'literal, rather than using implicit string concatenation.'
28
26
  FOR_ARRAY = ' Or, if they were intended to be separate array ' \
29
27
  'elements, separate them with a comma.'
30
28
  FOR_METHOD = ' Or, if they were intended to be separate method ' \
31
29
  'arguments, separate them with a comma.'
32
30
 
31
+ # rubocop:disable Metrics/AbcSize
33
32
  def on_dstr(node)
34
- each_bad_cons(node) do |child_node1, child_node2|
35
- range = child_node1.source_range.join(child_node2.source_range)
36
- message = format(MSG,
37
- string1: display_str(child_node1),
38
- string2: display_str(child_node2))
33
+ each_bad_cons(node) do |lhs_node, rhs_node|
34
+ range = lhs_node.source_range.join(rhs_node.source_range)
35
+ message = format(MSG, lhs: display_str(lhs_node), rhs: display_str(rhs_node))
39
36
  if node.parent&.array_type?
40
37
  message << FOR_ARRAY
41
38
  elsif node.parent&.send_type?
42
39
  message << FOR_METHOD
43
40
  end
44
- add_offense(range, message: message)
41
+
42
+ add_offense(range, message: message) do |corrector|
43
+ preferred = "#{lhs_node.source} + #{rhs_node.source}"
44
+
45
+ corrector.replace(range, preferred)
46
+ end
45
47
  end
46
48
  end
49
+ # rubocop:enable Metrics/AbcSize
47
50
 
48
51
  private
49
52
 
@@ -73,7 +76,7 @@ module RuboCop
73
76
  end
74
77
 
75
78
  def string_literal?(node)
76
- node.str_type? || (node.dstr_type? && node.children.all? { |c| string_literal?(c) })
79
+ node.str_type? || node.dstr_type?
77
80
  end
78
81
 
79
82
  def string_literals?(node1, node2)
@@ -11,7 +11,6 @@ module RuboCop
11
11
  # @example
12
12
  #
13
13
  # # bad
14
- #
15
14
  # class C
16
15
  # private
17
16
  #
@@ -20,10 +19,7 @@ module RuboCop
20
19
  # end
21
20
  # end
22
21
  #
23
- # @example
24
- #
25
22
  # # good
26
- #
27
23
  # class C
28
24
  # def self.method
29
25
  # puts 'hi'
@@ -32,10 +28,7 @@ module RuboCop
32
28
  # private_class_method :method
33
29
  # end
34
30
  #
35
- # @example
36
- #
37
31
  # # good
38
- #
39
32
  # class C
40
33
  # class << self
41
34
  # private
@@ -14,13 +14,9 @@ module RuboCop
14
14
  # @example
15
15
  #
16
16
  # # bad
17
- #
18
17
  # foo = 'something with #{interpolation} inside'
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # foo = "something with #{interpolation} inside"
25
21
  class InterpolationCheck < Base
26
22
  extend AutoCorrector
@@ -59,7 +59,7 @@ module RuboCop
59
59
  if case_node.condition
60
60
  check_case(case_node)
61
61
  else
62
- case_node.each_when do |when_node|
62
+ case_node.when_branches.each do |when_node|
63
63
  next unless when_node.conditions.all?(&:literal?)
64
64
 
65
65
  range = when_conditions_range(when_node)
@@ -54,7 +54,7 @@ module RuboCop
54
54
  private
55
55
 
56
56
  def traverse_node(node, &block)
57
- yield node if AST::Node::EQUALS_ASSIGNMENTS.include?(node.type)
57
+ yield node if node.equals_asgn?
58
58
 
59
59
  node.each_child_node { |child| traverse_node(child, &block) }
60
60
  end
@@ -8,13 +8,9 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # "result is #{10}"
13
12
  #
14
- # @example
15
- #
16
13
  # # good
17
- #
18
14
  # "result is 10"
19
15
  class LiteralInInterpolation < Base
20
16
  include Interpolation
@@ -19,17 +19,6 @@ module RuboCop
19
19
  # do_something
20
20
  # end while some_condition
21
21
  #
22
- # @example
23
- #
24
- # # bad
25
- #
26
- # # using until
27
- # begin
28
- # do_something
29
- # end until some_condition
30
- #
31
- # @example
32
- #
33
22
  # # good
34
23
  #
35
24
  # # while replacement
@@ -38,7 +27,12 @@ module RuboCop
38
27
  # break unless some_condition
39
28
  # end
40
29
  #
41
- # @example
30
+ # # bad
31
+ #
32
+ # # using until
33
+ # begin
34
+ # do_something
35
+ # end until some_condition
42
36
  #
43
37
  # # good
44
38
  #
@@ -17,8 +17,6 @@ module RuboCop
17
17
  # end
18
18
  # end
19
19
  #
20
- # @example
21
- #
22
20
  # # good
23
21
  #
24
22
  # def foo
@@ -26,8 +24,6 @@ module RuboCop
26
24
  # bar.call
27
25
  # end
28
26
  #
29
- # @example
30
- #
31
27
  # # good
32
28
  #
33
29
  # # `class_eval`, `instance_eval`, `module_eval`, `class_exec`, `instance_exec`, and
@@ -47,8 +43,6 @@ module RuboCop
47
43
  # end
48
44
  # end
49
45
  #
50
- # @example
51
- #
52
46
  # # good
53
47
  #
54
48
  # def foo
@@ -102,7 +96,7 @@ module RuboCop
102
96
 
103
97
  def on_def(node)
104
98
  subject, = *node
105
- return if node.defs_type? && subject.lvar_type?
99
+ return if node.defs_type? && subject.variable?
106
100
 
107
101
  def_ancestor = node.each_ancestor(:def, :defs).first
108
102
  return unless def_ancestor
@@ -8,16 +8,12 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # result = (1..4).reduce(0) do |acc, i|
13
12
  # next if i.odd?
14
13
  # acc + i
15
14
  # end
16
15
  #
17
- # @example
18
- #
19
16
  # # good
20
- #
21
17
  # result = (1..4).reduce(0) do |acc, i|
22
18
  # next acc if i.odd?
23
19
  # acc + i
@@ -11,17 +11,13 @@ module RuboCop
11
11
  # @example
12
12
  #
13
13
  # # bad
14
- #
15
14
  # @some_variable ||= begin
16
15
  # return some_value if some_condition_is_met
17
16
  #
18
17
  # do_something
19
18
  # end
20
19
  #
21
- # @example
22
- #
23
20
  # # good
24
- #
25
21
  # @some_variable ||= begin
26
22
  # if some_condition_is_met
27
23
  # some_value
@@ -31,7 +27,6 @@ module RuboCop
31
27
  # end
32
28
  #
33
29
  # # good
34
- #
35
30
  # some_variable = if some_condition_is_met
36
31
  # return if another_condition_is_met
37
32
  #
@@ -22,13 +22,9 @@ module RuboCop
22
22
  # @example
23
23
  #
24
24
  # # bad
25
- #
26
25
  # %w('foo', "bar")
27
26
  #
28
- # @example
29
- #
30
27
  # # good
31
- #
32
28
  # %w(foo bar)
33
29
  class PercentStringArray < Base
34
30
  include PercentLiteral
@@ -12,13 +12,9 @@ module RuboCop
12
12
  # @example
13
13
  #
14
14
  # # bad
15
- #
16
15
  # %i(:foo, :bar)
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # %i(foo bar)
23
19
  class PercentSymbolArray < Base
24
20
  include PercentLiteral
@@ -9,16 +9,12 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # rand 1
14
13
  # Kernel.rand(-1)
15
14
  # rand 1.0
16
15
  # rand(-1.0)
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # 0 # just use 0 instead
23
19
  class RandOne < Base
24
20
  MSG = '`%<method>s` always returns `0`. Perhaps you meant `rand(2)` or `rand`?'
@@ -14,14 +14,16 @@ module RuboCop
14
14
  #
15
15
  # When comment enables all cops at once `rubocop:enable all`
16
16
  # that cop checks whether any cop was actually enabled.
17
+ #
17
18
  # @example
19
+ #
18
20
  # # bad
19
21
  # foo = 1
20
22
  # # rubocop:enable Layout/LineLength
21
23
  #
22
24
  # # good
23
25
  # foo = 1
24
- # @example
26
+ #
25
27
  # # bad
26
28
  # # rubocop:disable Style/StringLiterals
27
29
  # foo = "1"
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # Checks for unneeded usages of splat expansion
6
+ # Checks for unneeded usages of splat expansion.
7
7
  #
8
8
  # @example
9
9
  #
@@ -9,16 +9,12 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # "result is #{something.to_s}"
14
13
  # print something.to_s
15
14
  # puts something.to_s
16
15
  # warn something.to_s
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # "result is #{something}"
23
19
  # print something
24
20
  # puts something
@@ -15,15 +15,11 @@ module RuboCop
15
15
  # @example
16
16
  #
17
17
  # # bad
18
- #
19
18
  # if day.is? :tuesday && month == :jan
20
19
  # # ...
21
20
  # end
22
21
  #
23
- # @example
24
- #
25
22
  # # good
26
- #
27
23
  # if day.is?(:tuesday) && month == :jan
28
24
  # # ...
29
25
  # end
@@ -8,17 +8,13 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # begin
13
12
  # do_something
14
13
  # rescue Exception
15
14
  # handle_exception
16
15
  # end
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # begin
23
19
  # do_something
24
20
  # rescue ArgumentError
@@ -19,8 +19,6 @@ module RuboCop
19
19
  # return 42
20
20
  # end
21
21
  #
22
- # @example
23
- #
24
22
  # # good
25
23
  # def initialize
26
24
  # foo
@@ -12,15 +12,11 @@ module RuboCop
12
12
  # @example
13
13
  #
14
14
  # # bad
15
- #
16
15
  # x&.foo.bar
17
16
  # x&.foo + bar
18
17
  # x&.foo[bar]
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # x&.foo&.bar
25
21
  # x&.foo || bar
26
22
  class SafeNavigationChain < Base
@@ -12,17 +12,16 @@ module RuboCop
12
12
  # because `Ractor` should not access outer variables.
13
13
  # eg. following style is encouraged:
14
14
  #
15
- # [source,ruby]
16
- # ----
17
- # worker_id, pipe = env
18
- # Ractor.new(worker_id, pipe) do |worker_id, pipe|
19
- # end
20
- # ----
15
+ # [source,ruby]
16
+ # ----
17
+ # worker_id, pipe = env
18
+ # Ractor.new(worker_id, pipe) do |worker_id, pipe|
19
+ # end
20
+ # ----
21
21
  #
22
22
  # @example
23
23
  #
24
24
  # # bad
25
- #
26
25
  # def some_method
27
26
  # foo = 1
28
27
  #
@@ -31,10 +30,7 @@ module RuboCop
31
30
  # end
32
31
  # end
33
32
  #
34
- # @example
35
- #
36
33
  # # good
37
- #
38
34
  # def some_method
39
35
  # foo = 1
40
36
  #
@@ -49,15 +49,8 @@ module RuboCop
49
49
  return unless def_node
50
50
 
51
51
  enum_conversion_call?(node) do |method_node, arguments|
52
- next if method_node.call_type? &&
53
- !method_node.method?(:__method__) && !method_node.method?(:__callee__)
54
-
55
- valid = if method_name?(method_node, def_node.method_name)
56
- arguments_match?(arguments, def_node)
57
- else
58
- def_node.arguments.empty?
59
- end
60
- return if valid
52
+ next if !method_name?(method_node, def_node.method_name) ||
53
+ arguments_match?(arguments, def_node)
61
54
 
62
55
  add_offense(node)
63
56
  end
@@ -8,14 +8,10 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # 1.is_a?(Fixnum)
13
12
  # 1.is_a?(Bignum)
14
13
  #
15
- # @example
16
- #
17
14
  # # good
18
- #
19
15
  # 1.is_a?(Integer)
20
16
  class UnifiedInteger < Base
21
17
  extend AutoCorrector
@@ -113,6 +113,7 @@ module RuboCop
113
113
  PATTERN
114
114
 
115
115
  def on_block(node)
116
+ return unless node.body
116
117
  return unless reduce_with_block?(node)
117
118
  return unless node.argument_list.length >= 2
118
119
 
@@ -10,14 +10,12 @@ module RuboCop
10
10
  # @example
11
11
  #
12
12
  # # bad
13
- #
14
13
  # def some_method
15
14
  # return
16
15
  # do_something
17
16
  # end
18
17
  #
19
18
  # # bad
20
- #
21
19
  # def some_method
22
20
  # if cond
23
21
  # return
@@ -27,10 +25,7 @@ module RuboCop
27
25
  # do_something
28
26
  # end
29
27
  #
30
- # @example
31
- #
32
28
  # # good
33
- #
34
29
  # def some_method
35
30
  # do_something
36
31
  # end