lib/geminabox/gem_version.rb
Method <=>
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Confirmed
Confirmed
def <=>(other)
sort = other.name <=> name
sort = version <=> other.version if sort.zero?
sort = (other.ruby? && !ruby?) ? 1 : -1 if sort.zero? && ruby? != other.ruby?
sort = other.platform <=> platform if sort.zero?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid the use of double negation (!!
). Open
Open
!!(platform =~ /ruby/i)
- Read upRead up
- Exclude checks
This cop checks for uses of double negation (!!) to convert something to a boolean value. As this is both cryptic and usually redundant, it should be avoided.
Example:
# bad
!!something
# good
!something.nil?
Please, note that when something is a boolean value !!something and !something.nil? are not the same thing. As you're unlikely to write code that can accept values of any type this is rarely a problem in practice.