Showing 23 of 23 total issues
Assignment Branch Condition size for print is too high. [76.72/20] Open
def print(output)
output.puts "---- MEMORY THRESHOLD ----"
output.puts "THRESHOLD: #{@threshold/1024} MB\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
- 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
Assignment Branch Condition size for print is too high. [58.19/20] Open
def print(output)
output.puts "---- OINK FOR ACTIVERECORD ----"
output.puts "THRESHOLD: #{@threshold} Active Record objects per request\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
- 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 print
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
def print(output)
output.puts "---- MEMORY THRESHOLD ----"
output.puts "THRESHOLD: #{@threshold/1024} MB\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
- 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 print_summary is too high. [52.12/20] Open
def print_summary(output)
output.puts "\n-- SUMMARY --\n"
output.puts "Worst Requests:"
@bad_requests.each_with_index do |offender, index|
output.puts "#{index + 1}. #{offender.datetime}, #{offender.display_oink_number}, #{offender.action}"
- 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 print
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def print(output)
output.puts "---- OINK FOR ACTIVERECORD ----"
output.puts "THRESHOLD: #{@threshold} Active Record objects per request\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
- 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 process is too high. [41.82/20] Open
def process
options = { :format => :short_summary, :type => :memory }
op = OptionParser.new do |opts|
opts.banner = "Usage: oink [options] files"
- 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
Assignment Branch Condition size for included is too high. [30.1/20] Open
def self.included(klass)
klass.class_eval do
def self.reset_instance_type_count
self.instantiated_hash = {}
- 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 process
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def process
options = { :format => :short_summary, :type => :memory }
op = OptionParser.new do |opts|
opts.banner = "Usage: oink [options] files"
Method print
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def print(output)
output.puts "---- MEMORY THRESHOLD ----"
output.puts "THRESHOLD: #{@threshold/1024} MB\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
Method print
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def print(output)
output.puts "---- OINK FOR ACTIVERECORD ----"
output.puts "THRESHOLD: #{@threshold} Active Record objects per request\n"
output.puts "\n-- REQUESTS --\n" if @format == :verbose
Method included
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.included(klass)
klass.class_eval do
def self.reset_instance_type_count
self.instantiated_hash = {}
Method print_summary
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def print_summary(output)
output.puts "\n-- SUMMARY --\n"
output.puts "Worst Requests:"
@bad_requests.each_with_index do |offender, index|
output.puts "#{index + 1}. #{offender.datetime}, #{offender.display_oink_number}, #{offender.action}"
Avoid deeply nested control flow statements. Open
if @format == :verbose
@pids[pid][:buffer].each { |b| output.puts b }
output.puts "---------------------------------------------------------------------"
end
Method process
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def process
options = { :format => :short_summary, :type => :memory }
op = OptionParser.new do |opts|
opts.banner = "Usage: oink [options] files"
- 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 get_file_listing
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_file_listing(args)
listing = []
args.each do |file|
unless File.exist?(file)
raise "Could not find \"#{file}\""
- 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
Do not suppress exceptions. Open
rescue LoadError
- Read upRead up
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end
Unused block argument - v
. You can omit the argument if you don't care about it. Open
opts.on("-r", "--active-record", "Check for Active Record Threshold") do |v|
- Read upRead up
- Exclude checks
This cop 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
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Variable value
used in void context. Open
value
- Read upRead up
- Exclude checks
This cop checks for operators, variables and literals used in void context.
Example:
# bad
def some_method
some_num * 10
do_something
end
Example:
# bad
def some_method(some_var)
some_var
do_something
end
Example:
# good
def some_method
do_something
some_num * 10
end
Example:
# good
def some_method(some_var)
do_something
some_var
end
Useless assignment to variable - e
. Open
rescue Oink::Instrumentation::MemoryDataUnavailableError => e
- 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
Unused block argument - v
. You can omit the argument if you don't care about it. Open
opts.on("-m", "--memory", "Check for Memory Threshold (default)") do |v|
- Read upRead up
- Exclude checks
This cop 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
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end