rbhint 0.85.1.rc2 → 0.87.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/bin/rubocop-profile +16 -0
  4. data/config/default.yml +118 -10
  5. data/lib/rbhint/version.rb +1 -1
  6. data/lib/rubocop.rb +15 -1
  7. data/lib/rubocop/cli.rb +0 -2
  8. data/lib/rubocop/cli/command/auto_genenerate_config.rb +40 -5
  9. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  10. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  11. data/lib/rubocop/config_loader.rb +24 -66
  12. data/lib/rubocop/config_obsoletion.rb +0 -1
  13. data/lib/rubocop/cop/autocorrect_logic.rb +14 -24
  14. data/lib/rubocop/cop/badge.rb +1 -1
  15. data/lib/rubocop/cop/base.rb +407 -0
  16. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
  17. data/lib/rubocop/cop/commissioner.rb +48 -50
  18. data/lib/rubocop/cop/cop.rb +85 -236
  19. data/lib/rubocop/cop/corrector.rb +38 -115
  20. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -0
  21. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +6 -1
  22. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  23. data/lib/rubocop/cop/generator.rb +1 -1
  24. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
  25. data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
  26. data/lib/rubocop/cop/layout/class_structure.rb +2 -37
  27. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
  28. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -8
  29. data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
  30. data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -0
  31. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -2
  32. data/lib/rubocop/cop/layout/multiline_block_layout.rb +17 -7
  33. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +22 -27
  34. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +27 -68
  35. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
  36. data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
  37. data/lib/rubocop/cop/legacy/corrector.rb +29 -0
  38. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -4
  39. data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
  40. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  41. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +3 -2
  42. data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
  43. data/lib/rubocop/cop/lint/literal_as_condition.rb +11 -1
  44. data/lib/rubocop/cop/lint/nested_method_definition.rb +14 -20
  45. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  46. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
  47. data/lib/rubocop/cop/lint/raise_exception.rb +8 -0
  48. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  49. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -23
  50. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
  51. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  52. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +8 -0
  53. data/lib/rubocop/cop/lint/syntax.rb +11 -26
  54. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  55. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
  56. data/lib/rubocop/cop/metrics/block_length.rb +24 -2
  57. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  58. data/lib/rubocop/cop/metrics/class_length.rb +26 -3
  59. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  60. data/lib/rubocop/cop/metrics/method_length.rb +24 -1
  61. data/lib/rubocop/cop/metrics/module_length.rb +26 -3
  62. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  63. data/lib/rubocop/cop/metrics/perceived_complexity.rb +3 -3
  64. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
  65. data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
  66. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  67. data/lib/rubocop/cop/mixin/code_length.rb +4 -0
  68. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  69. data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
  70. data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
  71. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
  72. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  73. data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -2
  74. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
  75. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -2
  76. data/lib/rubocop/cop/mixin/visibility_help.rb +50 -0
  77. data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
  78. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +2 -2
  79. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  80. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  81. data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
  82. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  83. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  84. data/lib/rubocop/cop/offense.rb +16 -2
  85. data/lib/rubocop/cop/style/accessor_grouping.rb +147 -0
  86. data/lib/rubocop/cop/style/array_coercion.rb +63 -0
  87. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -2
  88. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +146 -0
  89. data/lib/rubocop/cop/style/case_like_if.rb +217 -0
  90. data/lib/rubocop/cop/style/class_vars.rb +21 -0
  91. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  92. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  93. data/lib/rubocop/cop/style/date_time.rb +1 -1
  94. data/lib/rubocop/cop/style/dir.rb +2 -2
  95. data/lib/rubocop/cop/style/empty_literal.rb +5 -5
  96. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  97. data/lib/rubocop/cop/style/exponential_notation.rb +6 -8
  98. data/lib/rubocop/cop/style/float_division.rb +7 -10
  99. data/lib/rubocop/cop/style/format_string_token.rb +5 -5
  100. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +62 -0
  101. data/lib/rubocop/cop/style/hash_like_case.rb +76 -0
  102. data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -11
  103. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
  104. data/lib/rubocop/cop/style/missing_else.rb +1 -11
  105. data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
  106. data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
  107. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
  108. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -4
  109. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -3
  110. data/lib/rubocop/cop/style/proc.rb +1 -1
  111. data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
  112. data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
  113. data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
  114. data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
  115. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +50 -0
  116. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  117. data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
  118. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -1
  119. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +2 -2
  120. data/lib/rubocop/cop/style/redundant_sort.rb +3 -2
  121. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
  122. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  123. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +3 -2
  124. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  125. data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
  126. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  127. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +9 -32
  128. data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
  129. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  130. data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
  131. data/lib/rubocop/cop/team.rb +97 -81
  132. data/lib/rubocop/cop/utils/format_string.rb +1 -2
  133. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  134. data/lib/rubocop/file_finder.rb +4 -4
  135. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  136. data/lib/rubocop/name_similarity.rb +1 -3
  137. data/lib/rubocop/options.rb +15 -8
  138. data/lib/rubocop/path_util.rb +2 -17
  139. data/lib/rubocop/rake_task.rb +6 -9
  140. data/lib/rubocop/result_cache.rb +9 -5
  141. data/lib/rubocop/rspec/cop_helper.rb +4 -4
  142. data/lib/rubocop/rspec/expect_offense.rb +52 -22
  143. data/lib/rubocop/rspec/shared_contexts.rb +8 -8
  144. data/lib/rubocop/runner.rb +33 -32
  145. data/lib/rubocop/target_ruby.rb +1 -1
  146. data/lib/rubocop/version.rb +1 -1
  147. metadata +25 -8
  148. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
@@ -3,10 +3,32 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks if the length of a block exceeds some maximum value.
6
+ # This hint checks if the length of a block exceeds some maximum value.
7
7
  # Comment lines can optionally be ignored.
8
8
  # The maximum allowed length is configurable.
9
- # The cop can be configured to ignore blocks passed to certain methods.
9
+ # The hint can be configured to ignore blocks passed to certain methods.
10
+ #
11
+ # You can set literals you want to fold with `CountAsOne`.
12
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
13
+ # will be counted as one line regardless of its actual size.
14
+ #
15
+ # @example CountAsOne: ['array', 'heredoc']
16
+ #
17
+ # something do
18
+ # array = [ # +1
19
+ # 1,
20
+ # 2
21
+ # ]
22
+ #
23
+ # hash = { # +3
24
+ # key: 'value'
25
+ # }
26
+ #
27
+ # msg = <<~HEREDOC # +1
28
+ # Heredoc
29
+ # content.
30
+ # HEREDOC
31
+ # end # 5 points
10
32
  class BlockLength < Cop
11
33
  include TooManyLines
12
34
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks for excessive nesting of conditional and looping
6
+ # This hint checks for excessive nesting of conditional and looping
7
7
  # constructs.
8
8
  #
9
9
  # You can configure if blocks are considered using the `CountBlocks`
@@ -3,11 +3,34 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks if the length a class exceeds some maximum value.
6
+ # This hint checks if the length a class exceeds some maximum value.
7
7
  # Comment lines can optionally be ignored.
8
8
  # The maximum allowed length is configurable.
9
+ #
10
+ # You can set literals you want to fold with `CountAsOne`.
11
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
12
+ # will be counted as one line regardless of its actual size.
13
+ #
14
+ # @example CountAsOne: ['array', 'heredoc']
15
+ #
16
+ # class Foo
17
+ # ARRAY = [ # +1
18
+ # 1,
19
+ # 2
20
+ # ]
21
+ #
22
+ # HASH = { # +3
23
+ # key: 'value'
24
+ # }
25
+ #
26
+ # MSG = <<~HEREDOC # +1
27
+ # Heredoc
28
+ # content.
29
+ # HEREDOC
30
+ # end # 5 points
31
+ #
9
32
  class ClassLength < Cop
10
- include ClassishLength
33
+ include TooManyLines
11
34
 
12
35
  def on_class(node)
13
36
  check_code_length(node)
@@ -22,7 +45,7 @@ module RuboCop
22
45
  private
23
46
 
24
47
  def_node_matcher :class_definition?, <<~PATTERN
25
- (casgn nil? _ (block (send (const nil? :Class) :new) ...))
48
+ (casgn nil? _ (block (send (const {nil? cbase} :Class) :new) ...))
26
49
  PATTERN
27
50
 
28
51
  def message(length, max_length)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks that the cyclomatic complexity of methods is not higher
6
+ # This hint checks that the cyclomatic complexity of methods is not higher
7
7
  # than the configured maximum. The cyclomatic complexity is the number of
8
8
  # linearly independent paths through a method. The algorithm counts
9
9
  # decision points and adds one.
@@ -3,9 +3,32 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks if the length of a method exceeds some maximum value.
6
+ # This hint checks if the length of a method exceeds some maximum value.
7
7
  # Comment lines can optionally be ignored.
8
8
  # The maximum allowed length is configurable.
9
+ #
10
+ # You can set literals you want to fold with `CountAsOne`.
11
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
12
+ # will be counted as one line regardless of its actual size.
13
+ #
14
+ # @example CountAsOne: ['array', 'heredoc']
15
+ #
16
+ # def m
17
+ # array = [ # +1
18
+ # 1,
19
+ # 2
20
+ # ]
21
+ #
22
+ # hash = { # +3
23
+ # key: 'value'
24
+ # }
25
+ #
26
+ # <<~HEREDOC # +1
27
+ # Heredoc
28
+ # content.
29
+ # HEREDOC
30
+ # end # 5 points
31
+ #
9
32
  class MethodLength < Cop
10
33
  include TooManyLines
11
34
 
@@ -3,11 +3,34 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks if the length a module exceeds some maximum value.
6
+ # This hint checks if the length a module exceeds some maximum value.
7
7
  # Comment lines can optionally be ignored.
8
8
  # The maximum allowed length is configurable.
9
+ #
10
+ # You can set literals you want to fold with `CountAsOne`.
11
+ # Available are: 'array', 'hash', and 'heredoc'. Each literal
12
+ # will be counted as one line regardless of its actual size.
13
+ #
14
+ # @example CountAsOne: ['array', 'heredoc']
15
+ #
16
+ # module M
17
+ # ARRAY = [ # +1
18
+ # 1,
19
+ # 2
20
+ # ]
21
+ #
22
+ # HASH = { # +3
23
+ # key: 'value'
24
+ # }
25
+ #
26
+ # MSG = <<~HEREDOC # +1
27
+ # Heredoc
28
+ # content.
29
+ # HEREDOC
30
+ # end # 5 points
31
+ #
9
32
  class ModuleLength < Cop
10
- include ClassishLength
33
+ include TooManyLines
11
34
 
12
35
  def on_module(node)
13
36
  check_code_length(node)
@@ -22,7 +45,7 @@ module RuboCop
22
45
  private
23
46
 
24
47
  def_node_matcher :module_definition?, <<~PATTERN
25
- (casgn nil? _ (block (send (const nil? :Module) :new) ...))
48
+ (casgn nil? _ (block (send (const {nil? cbase} :Module) :new) ...))
26
49
  PATTERN
27
50
 
28
51
  def message(length, max_length)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop checks for methods with too many parameters.
6
+ # This hint checks for methods with too many parameters.
7
7
  # The maximum number of parameters is configurable.
8
8
  # Keyword arguments can optionally be excluded from the total count.
9
9
  class ParameterLists < Cop
@@ -3,13 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
- # This cop tries to produce a complexity score that's a measure of the
6
+ # This hint tries to produce a complexity score that's a measure of the
7
7
  # complexity the reader experiences when looking at a method. For that
8
8
  # reason it considers `when` nodes as something that doesn't add as much
9
9
  # complexity as an `if` or a `&&`. Except if it's one of those special
10
10
  # `case`/`when` constructs where there's no expression after `case`. Then
11
- # the cop treats it as an `if`/`elsif`/`elsif`... and lets all the `when`
12
- # nodes count. In contrast to the CyclomaticComplexity cop, this cop
11
+ # the hint treats it as an `if`/`elsif`/`elsif`... and lets all the `when`
12
+ # nodes count. In contrast to the CyclomaticComplexity hint, this hint
13
13
  # considers `else` nodes as adding complexity.
14
14
  #
15
15
  # @example
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Metrics
6
+ module Utils
7
+ # Helps to calculate code length for the provided node.
8
+ class CodeLengthCalculator
9
+ extend NodePattern::Macros
10
+ include Util
11
+
12
+ FOLDABLE_TYPES = %i[array hash heredoc].freeze
13
+ CLASSISH_TYPES = %i[class module].freeze
14
+
15
+ def initialize(node, count_comments: false, foldable_types: [])
16
+ @node = node
17
+ @count_comments = count_comments
18
+ @foldable_checks = build_foldable_checks(foldable_types)
19
+ @foldable_types = normalize_foldable_types(foldable_types)
20
+ end
21
+
22
+ def calculate
23
+ length = code_length(@node)
24
+
25
+ each_top_level_descendant(@node, *@foldable_types, *CLASSISH_TYPES) do |descendant|
26
+ descendant_length = code_length(descendant)
27
+
28
+ if classlike_node?(descendant)
29
+ length -= (descendant_length + 2)
30
+ elsif foldable_node?(descendant)
31
+ length = length - descendant_length + 1
32
+ end
33
+ end
34
+
35
+ length
36
+ end
37
+
38
+ private
39
+
40
+ def_node_matcher :class_definition?, <<~PATTERN
41
+ (casgn nil? _ (block (send (const nil? :Class) :new) ...))
42
+ PATTERN
43
+
44
+ def_node_matcher :module_definition?, <<~PATTERN
45
+ (casgn nil? _ (block (send (const nil? :Module) :new) ...))
46
+ PATTERN
47
+
48
+ def build_foldable_checks(types)
49
+ types.map do |type|
50
+ case type
51
+ when :array
52
+ ->(node) { node.array_type? }
53
+ when :hash
54
+ ->(node) { node.hash_type? }
55
+ when :heredoc
56
+ ->(node) { heredoc_node?(node) }
57
+ else
58
+ raise ArgumentError, "Unknown foldable type: #{type.inspect}. "\
59
+ "Valid foldable types are: #{FOLDABLE_TYPES.join(', ')}."
60
+ end
61
+ end
62
+ end
63
+
64
+ def normalize_foldable_types(types)
65
+ types.concat(%i[str dstr]) if types.delete(:heredoc)
66
+ types
67
+ end
68
+
69
+ def code_length(node)
70
+ return heredoc_length(node) if heredoc_node?(node)
71
+
72
+ body = extract_body(node)
73
+ lines = body&.source&.lines || []
74
+ lines.count { |line| !irrelevant_line?(line) }
75
+ end
76
+
77
+ def heredoc_node?(node)
78
+ node.respond_to?(:heredoc?) && node.heredoc?
79
+ end
80
+
81
+ def heredoc_length(node)
82
+ lines = node.loc.heredoc_body.source.lines
83
+ lines.count { |line| !irrelevant_line?(line) } + 2
84
+ end
85
+
86
+ def each_top_level_descendant(node, *types, &block)
87
+ node.each_child_node do |child|
88
+ if types.include?(child.type)
89
+ yield child
90
+ else
91
+ each_top_level_descendant(child, *types, &block)
92
+ end
93
+ end
94
+ end
95
+
96
+ def classlike_node?(node)
97
+ CLASSISH_TYPES.include?(node.type) ||
98
+ (node.casgn_type? && (class_definition?(node) || module_definition?(node)))
99
+ end
100
+
101
+ def foldable_node?(node)
102
+ @foldable_checks.any? { |check| check.call(node) }
103
+ end
104
+
105
+ def extract_body(node)
106
+ case node.type
107
+ when :class, :module, :block, :def, :defs
108
+ node.body
109
+ when :casgn
110
+ _scope, _name, value = *node
111
+ extract_body(value)
112
+ else
113
+ node
114
+ end
115
+ end
116
+
117
+ # Returns true for lines that shall not be included in the count.
118
+ def irrelevant_line?(source_line)
119
+ source_line.blank? || !count_comments? && comment_line?(source_line)
120
+ end
121
+
122
+ def count_comments?
123
+ @count_comments
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # This module encapsulates the ability to allow certain methods when
6
+ # parsing.
7
+ module AllowedMethods
8
+ private
9
+
10
+ def allowed_method?(name)
11
+ allowed_methods.include?(name.to_s)
12
+ end
13
+
14
+ def allowed_methods
15
+ cop_config.fetch('AllowedMethods', [])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # extend this module to signal autocorrection support
6
+ module AutoCorrector
7
+ def support_autocorrect?
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
@@ -16,6 +16,10 @@ module RuboCop
16
16
  cop_config['CountComments']
17
17
  end
18
18
 
19
+ def count_as_one
20
+ Array(cop_config['CountAsOne']).map(&:to_sym)
21
+ end
22
+
19
23
  def check_code_length(node)
20
24
  length = code_length(node)
21
25
 
@@ -10,7 +10,7 @@ module RuboCop
10
10
  if valid_name?(node, name)
11
11
  correct_style_detected
12
12
  else
13
- add_offense(node, location: name_range, message: message(style)) do
13
+ add_offense(name_range, message: message(style)) do
14
14
  report_opposing_styles(node, name)
15
15
  end
16
16
  end
@@ -10,7 +10,9 @@ module RuboCop
10
10
  PATTERN
11
11
 
12
12
  base.def_node_matcher :class_new_definition, <<~PATTERN
13
- [!^(casgn nil? :#{base::SUPERCLASS} ...) (send (const nil? :Class) :new #{base::BASE_PATTERN})]
13
+ [!^(casgn {nil? cbase} :#{base::SUPERCLASS} ...)
14
+ !^^(casgn {nil? cbase} :#{base::SUPERCLASS} (block ...))
15
+ (send (const {nil? cbase} :Class) :new #{base::BASE_PATTERN})]
14
16
  PATTERN
15
17
  end
16
18
 
@@ -7,19 +7,17 @@ module RuboCop
7
7
  # 2. Added to NilClass by explicitly requiring any standard libraries
8
8
  # 3. Cop's configuration parameter AllowedMethods.
9
9
  module NilMethods
10
+ include AllowedMethods
11
+
10
12
  private
11
13
 
12
14
  def nil_methods
13
- nil.methods + other_stdlib_methods + allowed_methods
15
+ nil.methods + other_stdlib_methods + allowed_methods.map(&:to_sym)
14
16
  end
15
17
 
16
18
  def other_stdlib_methods
17
19
  [:to_d]
18
20
  end
19
-
20
- def allowed_methods
21
- cop_config['AllowedMethods'].map(&:to_sym)
22
- end
23
21
  end
24
22
  end
25
23
  end
@@ -15,8 +15,13 @@ module RuboCop
15
15
  node.source_range
16
16
  end
17
17
 
18
+ def gem_canonical_name(name)
19
+ name = name.tr('-_', '') unless cop_config['ConsiderPunctuation']
20
+ name.downcase
21
+ end
22
+
18
23
  def case_insensitive_out_of_order?(string_a, string_b)
19
- string_a.downcase < string_b.downcase
24
+ gem_canonical_name(string_a) < gem_canonical_name(string_b)
20
25
  end
21
26
 
22
27
  def consecutive_lines(previous, current)
@@ -17,9 +17,9 @@ module RuboCop
17
17
  end
18
18
 
19
19
  def non_eligible_node?(node)
20
- node.nonempty_line_count > 3 ||
21
- !node.modifier_form? &&
22
- processed_source.commented?(node.loc.end)
20
+ node.modifier_form? ||
21
+ node.nonempty_line_count > 3 ||
22
+ processed_source.commented?(node.loc.end)
23
23
  end
24
24
 
25
25
  def non_eligible_body?(body)