Showing 1,937 of 1,937 total issues
Assignment Branch Condition size for debug is too high. [26.98/15] Open
def debug(colored: true)
format_subject = ->(s) { s.is_a?(User) ? s.first_name : s.is_a?(Project) ? s.slug : "" }
includes(:subject).reorder("taken_at ASC, subject_type ASC, subject_id ASC, name ASC").map { |m|
line = [ m.taken_on.strftime("%-m/%-d").rjust(5),
m.taken_at.strftime("%H:%M:%S"),
- 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 has too many lines. [21/10] Open
def mail(options={})
options[:from] = format_email_addresses(options[:from]) if options.key?(:from)
options[:to] = format_email_addresses(options[:to]).uniq if options.key?(:to)
options[:cc] = format_email_addresses(options[:cc]).uniq if options.key?(:cc)
options[:bcc] = format_email_addresses(options[:bcc]).uniq if options.key?(:bcc)
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for pack is too high. [26.17/15] Open
def pack(object)
case object
when Array
object.map { |item| pack(item) }
when 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
Assignment Branch Condition size for trigger is too high. [25.26/15] Open
def trigger
project = Project.find_by_slug(params[:project_id])
unless project
render plain: "A project with the slug '#{params[:project_id]}' could not be found", status: 404
return
- 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 has too many lines. [19/10] Open
def self.try(options, *rescue_from)
options = { max_tries: options } if options.is_a?(Fixnum)
options = {} unless options.is_a?(Hash)
max_tries = options.fetch :max_tries, 3
base = options.fetch :base, 2
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [18/10] Open
def initialize(user)
if user
# Owners can do everything
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [18/10] Open
def index
authorize! :read, Action
actions_by_name = Houston.actions.to_a.each_with_object({}) { |action, map|
map[action.name] = { name: action.name, required_params: action.required_params } }
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for _format_time_ago is too high. [23.49/15] Open
def _format_time_ago(time)
duration = (Time.now - time).to_i
return "#{duration} seconds ago" if duration < 90.seconds
return "#{duration / 60} minutes ago" if duration < 90.minutes
return "%.1f hours ago" % (duration / 3600.0) if duration < 20.hours
- 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 has too many lines. [18/10] Open
def trigger
project = Project.find_by_slug(params[:project_id])
unless project
render plain: "A project with the slug '#{params[:project_id]}' could not be found", status: 404
return
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for define_adapter_namespace is too high. [23.22/15] Open
def define_adapter_namespace(name)
namespace = ::Module.new
const_set name, namespace
pathname = name_to_path(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 pack
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def pack(object)
case object
when Array
object.map { |item| pack(item) }
when Hash
- 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 has too many lines. [17/10] Open
def define_adapter_namespace(name)
namespace = ::Module.new
const_set name, namespace
pathname = name_to_path(name)
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method daemonize
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def self.daemonize(name)
unless Houston.running_as_web_server? or ENV["HOUSTON_DAEMONS"].to_s.split(",").member?(name)
puts "\e[94m[daemon:#{name}] Skipping daemon since we're not running as a server\e[0m" if Rails.env.development?
Rails.logger.info "\e[94m[daemon:#{name}] Skipping daemon since we're not running as a server\e[0m"
return
- 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
Cyclomatic complexity for score is too high. [12/6] Open
def score(label, value, options={})
score_count_class = Array(options.delete(:score_count_class)) << "score-count"
precision = options.delete(:precision)
css = Array(options.fetch(:class, []))
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Perceived complexity for score is too high. [13/7] Open
def score(label, value, options={})
score_count_class = Array(options.delete(:score_count_class)) << "score-count"
precision = options.delete(:precision)
css = Array(options.fetch(:class, []))
- 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
Assignment Branch Condition size for format_time is too high. [21.19/15] Open
def format_time(time, options={})
if time.nil?
date, time = ["", "Never"]
elsif time.to_date == Date.today
date, time = [options[:today] ? "Today" : "", time.strftime("%l:%M %p")]
- 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 run! is too high. [20.32/15] Open
def run!
exception = nil
Houston.reconnect do
touch :started_at
- 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 index is too high. [20.88/15] Open
def index
authorize! :read, Action
actions_by_name = Houston.actions.to_a.each_with_object({}) { |action, map|
map[action.name] = { name: action.name, required_params: action.required_params } }
- 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
Cyclomatic complexity for mail is too high. [11/6] Open
def mail(options={})
options[:from] = format_email_addresses(options[:from]) if options.key?(:from)
options[:to] = format_email_addresses(options[:to]).uniq if options.key?(:to)
options[:cc] = format_email_addresses(options[:cc]).uniq if options.key?(:cc)
options[:bcc] = format_email_addresses(options[:bcc]).uniq if options.key?(:bcc)
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Perceived complexity for mail is too high. [12/7] Open
def mail(options={})
options[:from] = format_email_addresses(options[:from]) if options.key?(:from)
options[:to] = format_email_addresses(options[:to]).uniq if options.key?(:to)
options[:cc] = format_email_addresses(options[:cc]).uniq if options.key?(:cc)
options[:bcc] = format_email_addresses(options[:bcc]).uniq if options.key?(:bcc)
- 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