Assignment Branch Condition size for convert_dms_to_decimal_degree is too high. [26.38/15] Open
def convert_dms_to_decimal_degree(dms_string)
dms_raw_array = dms_string.is_a?(Array) ? dms_string : dms_string.split(',')
dms_parts =
dms_raw_array.collect do |dms|
sign = dms.scan(/[NE]/).size > 0 ? '+' : '-'
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method convert_dms_to_decimal_degree
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def convert_dms_to_decimal_degree(dms_string)
dms_raw_array = dms_string.is_a?(Array) ? dms_string : dms_string.split(',')
dms_parts =
dms_raw_array.collect do |dms|
sign = dms.scan(/[NE]/).size > 0 ? '+' : '-'
- 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
Use only ascii symbols in comments. Open
# S41°17'31.80", E174°46'46.20"
- Read upRead up
- Exclude checks
This cop checks for non-ascii (non-English) characters in comments. You could set an array of allowed non-ascii chars in AllowedChars attribute (empty by default).
Example:
# bad
# Translates from English to 日本語。
# good
# Translates from English to Japanese
Use dms.scan(/[NE]/).size.positive?
instead of dms.scan(/[NE]/).size > 0
. Open
sign = dms.scan(/[NE]/).size > 0 ? '+' : '-'
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Unnecessary utf-8 encoding comment. Open
# -*- coding: utf-8 -*-
- Exclude checks
Use !empty?
instead of size > 0
. Open
sign = dms.scan(/[NE]/).size > 0 ? '+' : '-'
- Read upRead up
- Exclude checks
This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.
Example:
# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0
# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?
Pass &:to_f
as an argument to collect
instead of a block. Open
parts = dms.gsub(/[^\d.]/, ' ').split(' ').collect { |part| part.to_f }
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)