Skip to content

Naming/PredicateMethod: consider predicates in method body #14255

@zverok

Description

@zverok

Is your feature request related to a problem? Please describe.

A new Naming/PredicateMethod cop seems quite useful 😻

I noticed one case that it potentially could catch, but didn't, at the time: the return value is calculated by a predicate. For example:

class File
  def ruby_file
    name.end_with?('.rb')
  end
end

This code doesn't trigger the cop.

Describe the solution you'd like

  • the method should probably be named ruby_file?
  • in the assumption that every predicate returns booleans, the cop can fairly confidently guess that the statement in the body returns a boolean (if it is not -- it is bad code anyway).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions