lib/vmdb/settings/hash_differ.rb
Method diff
has a Cognitive Complexity of 16 (exceeds 11 allowed). Consider refactoring. Open
Open
def self.diff(h1, h2)
keys = (h1.keys + h2.keys).uniq
keys.each_with_object({}) do |k, result|
v1 = h1.key?(k) ? h1[k] : MissingKey
v2 = h2.key?(k) ? h2[k] : MissingKey
- Read upRead up
- Create a ticketCreate a ticket
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
Empty class detected. Open
Open
class MissingKey; end
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for classes and metaclasses without a body. Such empty classes and metaclasses are typically an oversight or we should provide a comment to be clearer what we're aiming for.
Example:
# bad
class Foo
end
class Bar
class << self
end
end
class << obj
end
# good
class Foo
def do_something
# ... code
end
end
class Bar
class << self
attr_reader :bar
end
end
class << obj
attr_reader :bar
end
Example: AllowComments: false (default)
# bad
class Foo
# TODO: implement later
end
class Bar
class << self
# TODO: implement later
end
end
class << obj
# TODO: implement later
end
Example: AllowComments: true
# good
class Foo
# TODO: implement later
end
class Bar
class << self
# TODO: implement later
end
end
class << obj
# TODO: implement later
end