rubocop 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -12
  3. data/assets/output.html.erb +1 -1
  4. data/config/default.yml +13 -0
  5. data/lib/rubocop.rb +1 -0
  6. data/lib/rubocop/cli/command/execute_runner.rb +1 -1
  7. data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
  8. data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
  9. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
  10. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
  11. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
  12. data/lib/rubocop/cop/gemspec/date_assignment.rb +1 -0
  13. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
  14. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
  15. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
  16. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
  17. data/lib/rubocop/cop/generator.rb +2 -2
  18. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  19. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
  20. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
  21. data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
  22. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
  23. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
  24. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
  25. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
  26. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
  27. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
  28. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
  29. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
  30. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
  31. data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
  32. data/lib/rubocop/cop/layout/class_structure.rb +1 -0
  33. data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
  34. data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
  35. data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
  36. data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
  37. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  38. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
  39. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
  40. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
  41. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
  42. data/lib/rubocop/cop/lint/debugger.rb +3 -1
  43. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -0
  44. data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
  45. data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
  46. data/lib/rubocop/cop/lint/duplicate_require.rb +1 -0
  47. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
  48. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
  49. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
  50. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
  51. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
  52. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
  53. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -0
  54. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
  55. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
  56. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
  57. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
  58. data/lib/rubocop/cop/lint/number_conversion.rb +2 -0
  59. data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
  60. data/lib/rubocop/cop/lint/rand_one.rb +1 -0
  61. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
  62. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
  63. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -0
  64. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
  65. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
  66. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
  67. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
  68. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
  69. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
  70. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
  71. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
  72. data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
  73. data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
  74. data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
  75. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
  76. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
  77. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
  78. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
  79. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
  80. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
  81. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
  82. data/lib/rubocop/cop/lint/useless_times.rb +3 -0
  83. data/lib/rubocop/cop/metrics/module_length.rb +1 -0
  84. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -0
  85. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
  86. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
  87. data/lib/rubocop/cop/mixin/def_node.rb +1 -0
  88. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
  89. data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
  90. data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
  91. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
  92. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
  93. data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
  94. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
  95. data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
  96. data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
  97. data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
  98. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
  99. data/lib/rubocop/cop/naming/constant_name.rb +2 -0
  100. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -0
  101. data/lib/rubocop/cop/naming/method_name.rb +3 -0
  102. data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
  103. data/lib/rubocop/cop/security/eval.rb +1 -0
  104. data/lib/rubocop/cop/security/json_load.rb +1 -0
  105. data/lib/rubocop/cop/security/marshal_load.rb +1 -0
  106. data/lib/rubocop/cop/security/open.rb +1 -0
  107. data/lib/rubocop/cop/security/yaml_load.rb +1 -0
  108. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
  109. data/lib/rubocop/cop/style/alias.rb +1 -0
  110. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
  111. data/lib/rubocop/cop/style/array_coercion.rb +2 -0
  112. data/lib/rubocop/cop/style/array_join.rb +1 -0
  113. data/lib/rubocop/cop/style/attr.rb +1 -0
  114. data/lib/rubocop/cop/style/case_equality.rb +2 -1
  115. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -0
  116. data/lib/rubocop/cop/style/collection_compact.rb +2 -0
  117. data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
  118. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  119. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
  120. data/lib/rubocop/cop/style/constant_visibility.rb +1 -0
  121. data/lib/rubocop/cop/style/date_time.rb +3 -0
  122. data/lib/rubocop/cop/style/dir.rb +1 -0
  123. data/lib/rubocop/cop/style/documentation.rb +5 -0
  124. data/lib/rubocop/cop/style/documentation_method.rb +1 -0
  125. data/lib/rubocop/cop/style/double_negation.rb +1 -0
  126. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
  127. data/lib/rubocop/cop/style/each_with_object.rb +1 -0
  128. data/lib/rubocop/cop/style/empty_literal.rb +9 -0
  129. data/lib/rubocop/cop/style/endless_method.rb +1 -0
  130. data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
  131. data/lib/rubocop/cop/style/even_odd.rb +1 -0
  132. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
  133. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -0
  134. data/lib/rubocop/cop/style/float_division.rb +4 -0
  135. data/lib/rubocop/cop/style/format_string.rb +2 -0
  136. data/lib/rubocop/cop/style/format_string_token.rb +1 -0
  137. data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
  138. data/lib/rubocop/cop/style/hash_conversion.rb +26 -2
  139. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
  140. data/lib/rubocop/cop/style/hash_except.rb +1 -0
  141. data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
  142. data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
  143. data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
  144. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
  145. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
  146. data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
  147. data/lib/rubocop/cop/style/min_max.rb +1 -0
  148. data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
  149. data/lib/rubocop/cop/style/module_function.rb +5 -0
  150. data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
  151. data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
  152. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -0
  153. data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
  154. data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
  155. data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
  156. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -0
  157. data/lib/rubocop/cop/style/option_hash.rb +1 -0
  158. data/lib/rubocop/cop/style/or_assignment.rb +2 -0
  159. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
  160. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
  161. data/lib/rubocop/cop/style/proc.rb +1 -0
  162. data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
  163. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
  164. data/lib/rubocop/cop/style/redundant_begin.rb +7 -1
  165. data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
  166. data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
  167. data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
  168. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
  169. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
  170. data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
  171. data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
  172. data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
  173. data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
  174. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  175. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
  176. data/lib/rubocop/cop/style/return_nil.rb +6 -0
  177. data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
  178. data/lib/rubocop/cop/style/sample.rb +1 -0
  179. data/lib/rubocop/cop/style/signal_exception.rb +3 -0
  180. data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
  181. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
  182. data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
  183. data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
  184. data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
  185. data/lib/rubocop/cop/style/strip.rb +1 -0
  186. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -0
  187. data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
  188. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
  189. data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -0
  190. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
  191. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
  192. data/lib/rubocop/cop/style/unless_logical_operators.rb +99 -0
  193. data/lib/rubocop/cop/style/unpack_first.rb +1 -0
  194. data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
  195. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
  196. data/lib/rubocop/name_similarity.rb +1 -1
  197. data/lib/rubocop/target_ruby.rb +21 -13
  198. data/lib/rubocop/version.rb +1 -1
  199. metadata +9 -7
@@ -37,6 +37,7 @@ module RuboCop
37
37
  end
38
38
  end
39
39
 
40
+ # @!method struct_constructor?(node)
40
41
  def_node_matcher :struct_constructor?, <<~PATTERN
41
42
  {(send (const {nil? cbase} :Struct) :new ...)
42
43
  (block (send (const {nil? cbase} :Struct) :new ...) ...)}
@@ -5,6 +5,9 @@ module RuboCop
5
5
  module Style
6
6
  # Use symbols as procs when possible.
7
7
  #
8
+ # If you prefer a style that allows block for method with arguments,
9
+ # please set `true` to `AllowMethodsWithArguments`.
10
+ #
8
11
  # @example
9
12
  # # bad
10
13
  # something.map { |s| s.upcase }
@@ -12,6 +15,17 @@ module RuboCop
12
15
  #
13
16
  # # good
14
17
  # something.map(&:upcase)
18
+ #
19
+ # @example AllowMethodsWithArguments: false (default)
20
+ # # bad
21
+ # something.do_something(foo) { |o| o.bar }
22
+ #
23
+ # # good
24
+ # something.do_something(foo, &:bar)
25
+ #
26
+ # @example AllowMethodsWithArguments: true
27
+ # # good
28
+ # something.do_something(foo) { |o| o.bar }
15
29
  class SymbolProc < Base
16
30
  include RangeHelp
17
31
  include IgnoredMethods
@@ -21,8 +35,13 @@ module RuboCop
21
35
  'instead of a block.'
22
36
  SUPER_TYPES = %i[super zsuper].freeze
23
37
 
38
+ # @!method proc_node?(node)
24
39
  def_node_matcher :proc_node?, '(send (const {nil? cbase} :Proc) :new)'
40
+
41
+ # @!method symbol_proc_receiver?(node)
25
42
  def_node_matcher :symbol_proc_receiver?, '{(send ...) (super ...) zsuper}'
43
+
44
+ # @!method symbol_proc?(node)
26
45
  def_node_matcher :symbol_proc?, <<~PATTERN
27
46
  {
28
47
  (block $#symbol_proc_receiver? $(args (arg _var)) (send (lvar _var) $_))
@@ -37,11 +56,12 @@ module RuboCop
37
56
  def on_block(node)
38
57
  symbol_proc?(node) do |dispatch_node, arguments_node, method_name|
39
58
  # TODO: Rails-specific handling that we should probably make
40
- # configurable - https://github.com/rubocop-hq/rubocop/issues/1485
59
+ # configurable - https://github.com/rubocop/rubocop/issues/1485
41
60
  # we should ignore lambdas & procs
42
61
  return if proc_node?(dispatch_node)
43
62
  return if %i[lambda proc].include?(dispatch_node.method_name)
44
63
  return if ignored_method?(dispatch_node.method_name)
64
+ return if allow_if_method_has_argument?(node)
45
65
  return if node.block_type? && destructuring_block_argument?(arguments_node)
46
66
 
47
67
  register_offense(node, method_name, dispatch_node.method_name)
@@ -103,6 +123,10 @@ module RuboCop
103
123
  node.loc.begin.begin_pos
104
124
  end
105
125
  end
126
+
127
+ def allow_if_method_has_argument?(node)
128
+ !!cop_config.fetch('AllowMethodsWithArguments', false) && !node.arguments.count.zero?
129
+ end
106
130
  end
107
131
  end
108
132
  end
@@ -191,6 +191,7 @@ module RuboCop
191
191
  (child.send_type? && child.prefix_not?)
192
192
  end
193
193
 
194
+ # @!method method_name(node)
194
195
  def_node_matcher :method_name, <<~PATTERN
195
196
  {($:defined? _ ...)
196
197
  (send {_ nil?} $_ _ ...)}
@@ -34,6 +34,7 @@ module RuboCop
34
34
 
35
35
  def on_def(node)
36
36
  return unless trailing_body?(node)
37
+ return if node.endless? && node.body.parenthesized_call?
37
38
 
38
39
  add_offense(first_part_of(node.body)) do |corrector|
39
40
  LineBreakCorrector.correct_trailing_body(
@@ -40,7 +40,7 @@ module RuboCop
40
40
  'its own line.'
41
41
 
42
42
  def on_def(node)
43
- return unless trailing_end?(node)
43
+ return if node.endless? || !trailing_end?(node)
44
44
 
45
45
  add_offense(node.loc.end) do |corrector|
46
46
  corrector.insert_before(
@@ -120,6 +120,7 @@ module RuboCop
120
120
  !allowed_method_name?(node) && !allowed_writer?(node.method_name)
121
121
  end
122
122
 
123
+ # @!method looks_like_trivial_writer?(node)
123
124
  def_node_matcher :looks_like_trivial_writer?, <<~PATTERN
124
125
  {(def _ (args (arg ...)) (ivasgn _ (lvar _)))
125
126
  (defs _ _ (args (arg ...)) (ivasgn _ (lvar _)))}
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop checks for the use of logical operators in an `unless` condition.
7
+ # It discourages such code, as the condition becomes more difficult
8
+ # to read and understand.
9
+ #
10
+ # This cop supports two styles:
11
+ # - `forbid_mixed_logical_operators` (default)
12
+ # - `forbid_logical_operators`
13
+ #
14
+ # `forbid_mixed_logical_operators` style forbids the use of more than one type
15
+ # of logical operators. This makes the `unless` condition easier to read
16
+ # because either all conditions need to be met or any condition need to be met
17
+ # in order for the expression to be truthy or falsey.
18
+ #
19
+ # `forbid_logical_operators` style forbids any use of logical operator.
20
+ # This makes it even more easy to read the `unless` condition as
21
+ # there is only one condition in the expression.
22
+ #
23
+ # @example EnforcedStyle: forbid_mixed_logical_operators (default)
24
+ # # bad
25
+ # return unless a || b && c
26
+ # return unless a && b || c
27
+ # return unless a && b and c
28
+ # return unless a || b or c
29
+ # return unless a && b or c
30
+ # return unless a || b and c
31
+ #
32
+ # # good
33
+ # return unless a && b && c
34
+ # return unless a || b || c
35
+ # return unless a and b and c
36
+ # return unless a or b or c
37
+ # return unless a?
38
+ #
39
+ # @example EnforcedStyle: forbid_logical_operators
40
+ # # bad
41
+ # return unless a || b
42
+ # return unless a && b
43
+ # return unless a or b
44
+ # return unless a and b
45
+ #
46
+ # # good
47
+ # return unless a
48
+ # return unless a?
49
+ class UnlessLogicalOperators < Base
50
+ include ConfigurableEnforcedStyle
51
+
52
+ FORBID_MIXED_LOGICAL_OPERATORS = 'Do not use mixed logical operators in an `unless`.'
53
+ FORBID_LOGICAL_OPERATORS = 'Do not use any logical operator in an `unless`.'
54
+
55
+ # @!method or_with_and?(node)
56
+ def_node_matcher :or_with_and?, <<~PATTERN
57
+ (if (or <`and ...> ) ...)
58
+ PATTERN
59
+
60
+ # @!method and_with_or?(node)
61
+ def_node_matcher :and_with_or?, <<~PATTERN
62
+ (if (and <`or ...> ) ...)
63
+ PATTERN
64
+
65
+ # @!method logical_operator?(node)
66
+ def_node_matcher :logical_operator?, <<~PATTERN
67
+ (if ({and or} ... ) ...)
68
+ PATTERN
69
+
70
+ def on_if(node)
71
+ return unless node.unless?
72
+
73
+ if style == :forbid_mixed_logical_operators && mixed_logical_operator?(node)
74
+ add_offense(node, message: FORBID_MIXED_LOGICAL_OPERATORS)
75
+ elsif style == :forbid_logical_operators && logical_operator?(node)
76
+ add_offense(node, message: FORBID_LOGICAL_OPERATORS)
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def mixed_logical_operator?(node)
83
+ or_with_and?(node) ||
84
+ and_with_or?(node) ||
85
+ mixed_precedence_and?(node) ||
86
+ mixed_precedence_or?(node)
87
+ end
88
+
89
+ def mixed_precedence_and?(node)
90
+ node.source.include?('&&') && node.source.include?('and')
91
+ end
92
+
93
+ def mixed_precedence_or?(node)
94
+ node.source.include?('||') && node.source.include?('or')
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -24,6 +24,7 @@ module RuboCop
24
24
  '`%<receiver>s.unpack(%<format>s)%<method>s`.'
25
25
  RESTRICT_ON_SEND = %i[first [] slice at].freeze
26
26
 
27
+ # @!method unpack_and_first_element?(node)
27
28
  def_node_matcher :unpack_and_first_element?, <<~PATTERN
28
29
  {
29
30
  (send $(send (...) :unpack $(...)) :first)
@@ -72,6 +72,7 @@ module RuboCop
72
72
 
73
73
  PROGRAM_NAMES = %i[$0 $PROGRAM_NAME].freeze
74
74
 
75
+ # @!method file_constant_equal_program_name?(node)
75
76
  def_node_matcher :file_constant_equal_program_name?, <<~PATTERN
76
77
  (send #source_file_path_constant? {:== :!=} (gvar #program_name?))
77
78
  PATTERN
@@ -71,6 +71,7 @@ module RuboCop
71
71
  end
72
72
  end
73
73
 
74
+ # @!method zero_length_predicate(node)
74
75
  def_node_matcher :zero_length_predicate, <<~PATTERN
75
76
  {(send (send (...) ${:length :size}) $:== (int $0))
76
77
  (send (int $0) $:== (send (...) ${:length :size}))
@@ -78,6 +79,7 @@ module RuboCop
78
79
  (send (int $1) $:> (send (...) ${:length :size}))}
79
80
  PATTERN
80
81
 
82
+ # @!method nonzero_length_predicate(node)
81
83
  def_node_matcher :nonzero_length_predicate, <<~PATTERN
82
84
  {(send (send (...) ${:length :size}) ${:> :!=} (int $0))
83
85
  (send (int $0) ${:< :!=} (send (...) ${:length :size}))}
@@ -90,6 +92,7 @@ module RuboCop
90
92
  "!#{other_receiver(node).source}.empty?"
91
93
  end
92
94
 
95
+ # @!method zero_length_receiver(node)
93
96
  def_node_matcher :zero_length_receiver, <<~PATTERN
94
97
  {(send (send $_ _) :== (int 0))
95
98
  (send (int 0) :== (send $_ _))
@@ -97,6 +100,7 @@ module RuboCop
97
100
  (send (int 1) :> (send $_ _))}
98
101
  PATTERN
99
102
 
103
+ # @!method other_receiver(node)
100
104
  def_node_matcher :other_receiver, <<~PATTERN
101
105
  {(send (send $_ _) _ _)
102
106
  (send _ _ (send $_ _))}
@@ -105,6 +109,7 @@ module RuboCop
105
109
  # Some collection like objects in the Ruby standard library
106
110
  # implement `#size`, but not `#empty`. We ignore those to
107
111
  # reduce false positives.
112
+ # @!method non_polymorphic_collection?(node)
108
113
  def_node_matcher :non_polymorphic_collection?, <<~PATTERN
109
114
  {(send (send (send (const {nil? cbase} :File) :stat _) ...) ...)
110
115
  (send (send (send (const {nil? cbase} {:Tempfile :StringIO}) {:new :open} ...) ...) ...)}
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # DidYouMean::SpellChecker is not available in all versions of Ruby, and
17
17
  # even on versions where it *is* available (>= 2.3), it is not always
18
18
  # required correctly. So we do a feature check first.
19
- # See: https://github.com/rubocop-hq/rubocop/issues/7979
19
+ # See: https://github.com/rubocop/rubocop/issues/7979
20
20
  return [] unless defined?(DidYouMean::SpellChecker)
21
21
 
22
22
  names = names.dup
@@ -147,10 +147,12 @@ module RuboCop
147
147
 
148
148
  GEMSPEC_EXTENSION = '.gemspec'
149
149
 
150
+ # @!method required_ruby_version(node)
150
151
  def_node_search :required_ruby_version, <<~PATTERN
151
152
  (send _ :required_ruby_version= $_)
152
153
  PATTERN
153
154
 
155
+ # @!method gem_requirement?(node)
154
156
  def_node_matcher :gem_requirement?, <<~PATTERN
155
157
  (send (const(const _ :Gem):Requirement) :new $str)
156
158
  PATTERN
@@ -165,14 +167,10 @@ module RuboCop
165
167
  file = gemspec_filepath
166
168
  return unless file && File.file?(file)
167
169
 
168
- version = version_from_gemspec_file(file)
169
- return if version.nil?
170
+ right_hand_side = version_from_gemspec_file(file)
171
+ return if right_hand_side.nil?
170
172
 
171
- requirement = version.children.last
172
- return version_from_array(version) if version.array_type?
173
- return version_from_array(requirement) if gem_requirement? version
174
-
175
- version_from_str(version.str_content)
173
+ find_minimal_known_ruby(right_hand_side)
176
174
  end
177
175
 
178
176
  def gemspec_filename
@@ -192,15 +190,25 @@ module RuboCop
192
190
  required_ruby_version(processed_source.ast).first
193
191
  end
194
192
 
193
+ def version_from_right_hand_side(right_hand_side)
194
+ if right_hand_side.array_type?
195
+ version_from_array(right_hand_side)
196
+ elsif gem_requirement?(right_hand_side)
197
+ right_hand_side.children.last.value
198
+ else
199
+ right_hand_side.value
200
+ end
201
+ end
202
+
195
203
  def version_from_array(array)
196
- versions = array.children.map { |v| version_from_str(v.is_a?(String) ? v : v.str_content) }
197
- versions.compact.min
204
+ array.children.map(&:value)
198
205
  end
199
206
 
200
- def version_from_str(str)
201
- str.match(/^(?:>=|<=)?\s*(?<version>\d+(?:\.\d+)*)/) do |md|
202
- md[:version].to_f
203
- end
207
+ def find_minimal_known_ruby(right_hand_side)
208
+ version = version_from_right_hand_side(right_hand_side)
209
+ requirement = Gem::Requirement.new(version)
210
+
211
+ KNOWN_RUBIES.detect { |v| requirement.satisfied_by?(Gem::Version.new("#{v}.99")) }
204
212
  end
205
213
  end
206
214
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.10.0'
6
+ STRING = '1.11.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-02-15 00:00:00.000000000 Z
13
+ date: 2021-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -258,6 +258,7 @@ files:
258
258
  - lib/rubocop/cop/internal_affairs/example_description.rb
259
259
  - lib/rubocop/cop/internal_affairs/method_name_equal.rb
260
260
  - lib/rubocop/cop/internal_affairs/node_destructuring.rb
261
+ - lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
261
262
  - lib/rubocop/cop/internal_affairs/node_type_predicate.rb
262
263
  - lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
263
264
  - lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
@@ -790,6 +791,7 @@ files:
790
791
  - lib/rubocop/cop/style/trailing_underscore_variable.rb
791
792
  - lib/rubocop/cop/style/trivial_accessors.rb
792
793
  - lib/rubocop/cop/style/unless_else.rb
794
+ - lib/rubocop/cop/style/unless_logical_operators.rb
793
795
  - lib/rubocop/cop/style/unpack_first.rb
794
796
  - lib/rubocop/cop/style/variable_interpolation.rb
795
797
  - lib/rubocop/cop/style/when_then.rb
@@ -861,15 +863,15 @@ files:
861
863
  - lib/rubocop/version.rb
862
864
  - lib/rubocop/warning.rb
863
865
  - lib/rubocop/yaml_duplication_checker.rb
864
- homepage: https://github.com/rubocop-hq/rubocop
866
+ homepage: https://github.com/rubocop/rubocop
865
867
  licenses:
866
868
  - MIT
867
869
  metadata:
868
870
  homepage_uri: https://rubocop.org/
869
- changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
870
- source_code_uri: https://github.com/rubocop-hq/rubocop/
871
- documentation_uri: https://docs.rubocop.org/rubocop/1.10/
872
- bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
871
+ changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
872
+ source_code_uri: https://github.com/rubocop/rubocop/
873
+ documentation_uri: https://docs.rubocop.org/rubocop/1.11/
874
+ bug_tracker_uri: https://github.com/rubocop/rubocop/issues
873
875
  post_install_message:
874
876
  rdoc_options: []
875
877
  require_paths: