app/models/metric/common.rb
Method v_calc_pct_of_cpu_time
has a Cognitive Complexity of 12 (exceeds 11 allowed). Consider refactoring. Open
Open
def v_calc_pct_of_cpu_time(vcol)
col = vcol.to_s.split("_")[2..-1].join("_")
return nil if send(col).nil?
int, default_intervals_in_rollup = CHILD_ROLLUP_INTERVAL[capture_interval_name]
- 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
Unused block argument - t
. You can omit the argument if you don't care about it. Open
Open
where(args.map { |t| "tag_names like ?" }.join(" OR "), *(args.map { |t| "%" + t.join("/") + "%" }))
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
# good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Example: IgnoreEmptyBlocks: true (default)
# good
do_something { |unused| }
Example: IgnoreEmptyBlocks: false
# bad
do_something { |unused| }
Example: AllowUnusedKeywordArguments: false (default)
# bad
do_something do |unused: 42|
foo
end
Example: AllowUnusedKeywordArguments: true
# good
do_something do |unused: 42|
foo
end