Skip to content

Naming/PredicateMethod false positive when an "operation" returns true #14232

@tagliala

Description

@tagliala

The new Naming/PredicateMethod is returning a false positive for a method which is, maybe, not the best method ever but it is definitely not a predicate method

def set_admin!
  raise 'Nope' unless some_checks?

  admin_arel.first_or_create
  true
end

Actually, the true is just used to return a simpler object here. I'm not incline to remove it and return the internal admin object, but if you think it should work that way I would do the change


Expected behavior

No offenses, because the method returns a boolean, but is not a predicate. The boolean is the "result of the operation"

Actual behavior

test.rb:1:5: C: Naming/PredicateMethod: Predicate method names should end with ?.
def set_admin!

Steps to reproduce the problem

  1. Create a file test.rb
def set_admin!
  raise 'Nope' unless some_checks?

  admin_arel.first_or_create
  true
end
  1. bundle exec rubocop --only Naming/PredicateMethod test.rb

RuboCop version

$ be rubocop -V
1.76.0 (using Parser 3.3.8.0, rubocop-ast 1.45.0, analyzing as Ruby 2.7, running on ruby 3.4.3) [arm64-darwin24]

From main branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions