Assignment Branch Condition size for save_advice is too high. [23.17/15] Open
def save_advice
# Stores the questionnaire with given id in URL
@questionnaire = Questionnaire.find(params[:id])
begin
# checks if advice is present or not
- 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. [12/10] Open
def save_advice
# Stores the questionnaire with given id in URL
@questionnaire = Questionnaire.find(params[:id])
begin
# checks if advice is present or not
- 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. [12/10] Open
def edit_advice
# Stores the questionnaire with given id in URL
@questionnaire = Questionnaire.find(params[:id])
# For each question in a quentionnaire, this method adjusts the advice size if the advice size is <,> number of advices or
- 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 edit_advice is too high. [16.4/15] Open
def edit_advice
# Stores the questionnaire with given id in URL
@questionnaire = Questionnaire.find(params[:id])
# For each question in a quentionnaire, this method adjusts the advice size if the advice size is <,> number of advices or
- 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
Use each_key
instead of keys.each
. Open
params[:advice].keys.each do |advice_key|
- 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 }
Pass &:score
as an argument to sort_by
instead of a block. Open
sorted_advice = question.question_advices.sort_by { |x| x.score }.reverse
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Redundant return
detected. Open
return ((question.question_advices.length != num_advices) ||
- Read upRead up
- Exclude checks
This cop checks for redundant return
expressions.
Example:
def test
return something
end
def test
one
two
three
return something
end
It should be extended to handle methods whose body is if/else or a case expression with a default branch.
Missing top-level class documentation comment. Open
class AdviceController < ApplicationController
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end