Class BaseModel
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class BaseModel
# Initially inherit the exclusion list from parent class or create an empty Set.
def self.excl_list
@excl_list ||= superclass.respond_to?(:excl_list, true) ? superclass.send(:excl_list) : Set.new
end
Method __setobj__
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def __setobj__
excl_list = self.class.send(:excl_list)
@hashobj.each do |key, value|
snake = key.to_s.gsub(/\W/, '_').underscore
- 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
Method initialize
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def initialize(json, skip_accessors_definition = false)
# Find the exclusion list for the model of next level (@embed_model)
# '#' is the separator between levels. Remove attributes
# before the first separator.
@child_excl_list = self.class.send(:excl_list).map do |e|
- 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
Remove unnecessary require
statement. Open
require 'pp'
- Read upRead up
- Exclude checks
Checks for unnecessary require
statement.
The following features are unnecessary require
statement because
they are already loaded. e.g. Ruby 2.2:
ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
["enumerator.so", "rational.so", "complex.so", "thread.rb"]
Below are the features that each TargetRubyVersion
targets.
* 2.0+ ... `enumerator`
* 2.1+ ... `thread`
* 2.2+ ... Add `rational` and `complex` above
* 2.5+ ... Add `pp` above
* 2.7+ ... Add `ruby2_keywords` above
* 3.1+ ... Add `fiber` above
* 3.2+ ... `set`
This cop target those features.
Example:
# bad
require 'unloaded_feature'
require 'thread'
# good
require 'unloaded_feature'