A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/issues/14232 below:

`Naming/PredicateMethod` false positive when an "operation" returns `true` · Issue #14232 · rubocop/rubocop · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4