KEMBAR78
The `Naming/PredicateMethod` cop ignores implicit nil return. · Issue #14333 · rubocop/rubocop · GitHub
Skip to content

The Naming/PredicateMethod cop ignores implicit nil return. #14333

@piotrmurach

Description

@piotrmurach

A method that returns true, false and implicit nil is flagged as a predicate method.

def foo
  case @foo
  when "bar" then true
  when "baz" then false
  end
end

Changing the method body to an explicit nil return fixes the offence.

def foo
  case @foo
  when "bar" then true
  when "baz" then false
  else nil
  end
end

But raises the Style/EmptyElse offence.

Expected behavior

My expectation is there for the foo not to cause the Naming/PredicateMethod offence. This is a conversion method that, for certain values, returns a boolean value.

Actual behavior

The foo method causes the Naming/PredicateMethod offence despite not being a predicate method.

Steps to reproduce the problem

Please see the description.

RuboCop version

$ [bundle exec] rubocop -V
1.77.0 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.4, running on ruby 3.4.2)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions