Method initialize_upload_vars
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def initialize_upload_vars(*upload_args)
upload_args.pop if (@byte_count = parse_byte_value(upload_args.last))
@remote_file_path = upload_args.pop
unless upload_args.empty?
- 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
Check block argument explicitly instead of using block_given?
. Open
if block_given?
- Create a ticketCreate a ticket
- Exclude checks
Variable MiqGlusterfsSession
used in void context. Open
::MiqGlusterfsSession
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.
Example: CheckForMethodsWithNoSideEffects: false (default)
# bad
def some_method
some_num * 10
do_something
end
def some_method(some_var)
some_var
do_something
end
Example: CheckForMethodsWithNoSideEffects: true
# bad
def some_method(some_array)
some_array.sort
do_something(some_array)
end
# good
def some_method
do_something
some_num * 10
end
def some_method(some_var)
do_something
some_var
end
def some_method(some_array)
some_array.sort!
do_something(some_array)
end
Wrap expressions with varying precedence with parentheses to avoid ambiguity. Open
"#{remote_file_path}.#{'%05d' % (@position / byte_count + 1)}"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Looks for expressions containing multiple binary operators
where precedence is ambiguous due to lack of parentheses. For example,
in 1 + 2 * 3
, the multiplication will happen before the addition, but
lexically it appears that the addition will happen first.
The cop does not consider unary operators (ie. !a
or -b
) or comparison
operators (ie. a =~ b
) because those are not ambiguous.
NOTE: Ranges are handled by Lint/AmbiguousRange
.
Example:
# bad
a + b * c
a || b && c
a ** b + c
# good (different precedence)
a + (b * c)
a || (b && c)
(a ** b) + c
# good (same precedence)
a + b + c
a * b / c % d
Variable MiqSmbSession
used in void context. Open
::MiqSmbSession
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.
Example: CheckForMethodsWithNoSideEffects: false (default)
# bad
def some_method
some_num * 10
do_something
end
def some_method(some_var)
some_var
do_something
end
Example: CheckForMethodsWithNoSideEffects: true
# bad
def some_method(some_array)
some_array.sort
do_something(some_array)
end
# good
def some_method
do_something
some_num * 10
end
def some_method(some_var)
do_something
some_var
end
def some_method(some_array)
some_array.sort!
do_something(some_array)
end
Variable MiqNfsSession
used in void context. Open
::MiqNfsSession
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.
Example: CheckForMethodsWithNoSideEffects: false (default)
# bad
def some_method
some_num * 10
do_something
end
def some_method(some_var)
some_var
do_something
end
Example: CheckForMethodsWithNoSideEffects: true
# bad
def some_method(some_array)
some_array.sort
do_something(some_array)
end
# good
def some_method
do_something
some_num * 10
end
def some_method(some_var)
do_something
some_var
end
def some_method(some_array)
some_array.sort!
do_something(some_array)
end
Do not mix named captures and numbered captures in a Regexp literal. Open
BYTE_HASH_MATCH = /^(?<BYTE_NUM>\d+(\.\d+)?)\s*(?<BYTE_QUALIFIER>K|M|G)?$/i
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Do not mix named captures and numbered captures in a Regexp literal because numbered capture is ignored if they're mixed. Replace numbered captures with non-capturing groupings or named captures.
Example:
# bad
/(?<foo>FOO)(BAR)/
# good
/(?<foo>FOO)(?<bar>BAR)/
# good
/(?<foo>FOO)(?:BAR)/
# good
/(FOO)(BAR)/</foo></bar></foo></foo>
Variable MiqLocalMountSession
used in void context. Open
::MiqLocalMountSession
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for operators, variables, literals, lambda, proc and nonmutating methods used in void context.
Example: CheckForMethodsWithNoSideEffects: false (default)
# bad
def some_method
some_num * 10
do_something
end
def some_method(some_var)
some_var
do_something
end
Example: CheckForMethodsWithNoSideEffects: true
# bad
def some_method(some_array)
some_array.sort
do_something(some_array)
end
# good
def some_method
do_something
some_num * 10
end
def some_method(some_var)
do_something
some_var
end
def some_method(some_array)
some_array.sort!
do_something(some_array)
end
Empty block detected. Open
fifo_path = Pathname.new(Dir::Tmpname.create("") {})
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for blocks without a body. Such empty blocks are typically an oversight or we should provide a comment be clearer what we're aiming for.
Empty lambdas and procs are ignored by default.
NOTE: For backwards compatibility, the configuration that allows/disallows
empty lambdas and procs is called AllowEmptyLambdas
, even though it also
applies to procs.
Example:
# bad
items.each { |item| }
# good
items.each { |item| puts item }
Example: AllowComments: true (default)
# good
items.each do |item|
# TODO: implement later (inner comment)
end
items.each { |item| } # TODO: implement later (inline comment)
Example: AllowComments: false
# bad
items.each do |item|
# TODO: implement later (inner comment)
end
items.each { |item| } # TODO: implement later (inline comment)
Example: AllowEmptyLambdas: true (default)
# good
allow(subject).to receive(:callable).and_return(-> {})
placeholder = lambda do
end
(callable || placeholder).call
proc { }
Proc.new { }
Example: AllowEmptyLambdas: false
# bad
allow(subject).to receive(:callable).and_return(-> {})
placeholder = lambda do
end
(callable || placeholder).call
proc { }
Proc.new { }