Method perform_load
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
def perform_load( options = {} )
allow_empty_rows = DataShift::Loaders::Configuration.call.allow_empty_rows
logger.info "Starting bulk load from Excel : #{file_name}"
- 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
Assignment Branch Condition size for perform_load is too high. [72.37/60] Open
def perform_load( options = {} )
allow_empty_rows = DataShift::Loaders::Configuration.call.allow_empty_rows
logger.info "Starting bulk load from Excel : #{file_name}"
- 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 perform_load
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
def perform_load( options = {} )
allow_empty_rows = DataShift::Loaders::Configuration.call.allow_empty_rows
logger.info "Starting bulk load from Excel : #{file_name}"
Perceived complexity for perform_load is too high. [17/15] Open
def perform_load( options = {} )
allow_empty_rows = DataShift::Loaders::Configuration.call.allow_empty_rows
logger.info "Starting bulk load from Excel : #{file_name}"
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Block has too many lines. [35/25] Open
load_object_class.transaction do
sheet.each_with_index do |row, current_row_idx|
next if current_row_idx == headers.idx
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Block has too many lines. [29/25] Open
sheet.each_with_index do |row, current_row_idx|
next if current_row_idx == headers.idx
# Excel num_rows seems to return all 'visible' rows, which appears to be greater than the actual data rows
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
TODO found Open
# TODO: - how does this get inserted - bind headers ?? ignore if no index
- Exclude checks
TODO found Open
# (TODO - write spec to process .xls with a huge number of rows)
- Exclude checks
Useless assignment to variable - x
. Open
rescue StandardError => x
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Use &&
instead of and
. Open
doc_context.reset and next if doc_context.errors?
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Do not place comments on the same line as the end
keyword. Open
end # TRANSACTION N.B ActiveRecord::Rollback does not propagate outside of the containing transaction block
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end
Do not place comments on the same line as the end
keyword. Open
end # all rows processed
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end