Skip to content

Naming/PredicateMethod should not be triggered by nonzero? #14318

@zverok

Description

@zverok

Expected behavior

def default_tax
  owner.tax.nonzero?
end

This code shouldn't suggest renaming the method to defalt_tax?. Despite its name, nonzero? is not a predicate; its protocol is "return a number if it isn't zero, or nil otherwise".

While many might consider it idiosyncratic, it is a Ruby core method, heavily used by some codebases 🤷

Actual behavior

Naming/PredicateMethod: Predicate method names should end with ?.
  def default_tax
      ^^^^^^^^^^^

RuboCop version

$ [bundle exec] rubocop -V
1.77.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.1, analyzing as Ruby 3.3, running on ruby 3.3.8) [x86_64-linux]
  - rubocop-rspec 3.6.0
  - rubocop-rails 2.32.0
  - rubocop-performance 1.25.0
  - rubocop-rake 0.7.1
  - rubocop-capybara 2.22.1
  - rubocop-rspec_rails 2.31.0
  - rubocop-factory_bot 2.27.1
  - rubocop-graphql 1.1.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions