Closed marcandre closed 2 weeks ago
@marcandre would it be helpful if I gave you the other ones I detected?
Offenses:
lib/rubocop/ast/node/array_node.rb:37:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('[')
^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/array_node.rb:55:11: C: Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.source&.start_with?('%')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/block_node.rb:93:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.end&.is?('}')
^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/block_node.rb:100:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.end&.is?('end')
^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/for_node.rb:20:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('do')
^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/hash_node.rb:118:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.end&.is?('}')
^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/in_pattern_node.rb:27:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('then')
^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/method_dispatch_node.rb:144:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
receiver&.self_type?
^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/method_dispatch_node.rb:153:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
receiver&.const_type?
^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/method_identifier_predicates.rb:187:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
receiver&.self_type?
^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/method_identifier_predicates.rb:194:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
receiver&.const_type?
^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/parameterized_node.rb:16:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.end&.is?(')')
^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/until_node.rb:31:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('do')
^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/when_node.rb:36:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('then')
^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/while_node.rb:31:9: C: [Correctable] Style/ReturnNilInPredicateMethodDefinition: Predicate method may return nil due to &. operator.
loc.begin&.is?('do')
^^^^^^^^^^^^^^^^^^^^
165 files inspected, 15 offenses detected, 14 offenses autocorrectable
Yes!
I'm now realizing that we have spec like expect(...).not_to be_foo
, and these don't flag nil
. Is there a cop for those?
I don't think there is. I opened https://github.com/rubocop/rubocop-rspec/issues/1966
Merging this, the rest is moved to https://github.com/rubocop/rubocop-ast/issues/319
See https://github.com/rubocop/rubocop/issues/13114