Assignment Branch Condition size for summarize_reviews_by_reviewees is too high. [89.93/15] Open
def summarize_reviews_by_reviewees(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @reviewers[team][reviewer]
# @avg_scores_by_reviewee[team]
# @avg_score_round[reviewee][round]
- 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 summarize_reviews_by_reviewee is too high. [44.61/15] Open
def summarize_reviews_by_reviewee(questions, assignment, r_id, summary_ws_url)
self.summary = ({})
self.avg_scores_by_round = ({})
self.avg_scores_by_criterion = ({})
- 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 summarize_reviews_by_criterion is too high. [42.34/15] Open
def summarize_reviews_by_criterion(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @avg_score_round[reviewee][round]
# @avg_scores_by_criterion[reviewee][round][criterion]
nround = assignment.rounds_of_reviews
- 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 summarize_reviews_by_reviewees
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def summarize_reviews_by_reviewees(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @reviewers[team][reviewer]
# @avg_scores_by_reviewee[team]
# @avg_score_round[reviewee][round]
- 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 summarize_reviews_by_criterion
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def summarize_reviews_by_criterion(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @avg_score_round[reviewee][round]
# @avg_scores_by_criterion[reviewee][round][criterion]
nround = assignment.rounds_of_reviews
- 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 calculate_avg_score_by_round is too high. [18.57/15] Open
def calculate_avg_score_by_round(avg_scores_by_criterion, criteria)
round_score = 0.0
sum_weight = 0
criteria.each do |q|
- 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 get_questions_by_assignment is too high. [16.43/15] Open
def get_questions_by_assignment(assignment)
rubric = []
(0..assignment.rounds_of_reviews - 1).each do |round|
rubric[round] = nil
if assignment.varying_rubrics_by_round?
- 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 summarize_reviews_by_reviewees
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def summarize_reviews_by_reviewees(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @reviewers[team][reviewer]
# @avg_scores_by_reviewee[team]
# @avg_score_round[reviewee][round]
Method get_questions_by_assignment
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_questions_by_assignment(assignment)
rubric = []
(0..assignment.rounds_of_reviews - 1).each do |round|
rubric[round] = nil
if assignment.varying_rubrics_by_round?
- 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 summarize_reviews_by_criterion
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def summarize_reviews_by_criterion(assignment, summary_ws_url)
# @summary[reviewee][round][question]
# @avg_score_round[reviewee][round]
# @avg_scores_by_criterion[reviewee][round][criterion]
nround = assignment.rounds_of_reviews
Method break_up_comments_to_sentences
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def break_up_comments_to_sentences(question_answers)
# strore answers of each question in an array to be converted into json
comments = []
question_answers.each do |ans|
unless ans.comments.nil?
- 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
Use each_key
instead of keys.each
. Open
questions.keys.each do |round|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Useless assignment to variable - summary
. Open
summary = ""
- 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
Useless module_function
access modifier. Open
module_function
- Read upRead up
- Exclude checks
This cop checks for redundant access modifiers, including those with no
code, those which are repeated, and leading public
modifiers in a
class or module body. Conditionally-defined methods are considered as
always being defined, and thus access modifiers guarding such methods
are not redundant.
Example:
class Foo
public # this is redundant (default access is public)
def method
end
private # this is not redundant (a method is defined)
def method2
end
private # this is redundant (no following methods are defined)
end
Example:
class Foo
# The following is not redundant (conditionally defined methods are
# considered as always defining a method)
private
if condition?
def method
end
end
protected # this is not redundant (method is defined)
define_method(:method2) do
end
protected # this is redundant (repeated from previous modifier)
[1,2,3].each do |i|
define_method("foo#{i}") do
end
end
# The following is redundant (methods defined on the class'
# singleton class are not affected by the public modifier)
public
def self.method3
end
end
Example:
# Lint/UselessAccessModifier:
# ContextCreatingMethods:
# - concerning
require 'active_support/concern'
class Foo
concerning :Bar do
def some_public_method
end
private
def some_private_method
end
end
# this is not redundant because `concerning` created its own context
private
def some_other_private_method
end
end
Example:
# Lint/UselessAccessModifier:
# MethodCreatingMethods:
# - delegate
require 'active_support/core_ext/module/delegation'
class Foo
# this is not redundant because `delegate` creates methods
private
delegate :method_a, to: :method_b
end
Useless assignment to variable - summary
. Open
summary = [err.message]
- 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
Line is too long. [162/160] Open
self.avg_scores_by_round[reviewee.name][round] = calculate_avg_score_by_round(self.avg_scores_by_criterion[reviewee.name][round], rubric_questions_used)
- Exclude checks
Useless assignment to variable - included_question_counter
. Open
included_question_counter = 0
- 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