Assignment Branch Condition size for peer_review_strategy is too high. [98.49/15] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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 peer_review_strategy
has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring. Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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 automatic_review_mapping is too high. [74.65/15] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
max_team_size = Integer(params[:max_team_size]) # Assignment.find(assignment_id).max_team_size
- 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
File review_mapping_controller.rb
has 418 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ReviewMappingController < ApplicationController
autocomplete :user, :name
# use_google_charts
require 'gchart'
# helper :dynamic_review_assignment
Assignment Branch Condition size for add_reviewer is too high. [44.25/15] Open
def add_reviewer
assignment = Assignment.find(params[:id])
topic_id = params[:topic_id]
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
- 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 assign_reviewer_dynamically is too high. [39.15/15] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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 add_calibration is too high. [32.5/15] Open
def add_calibration
participant = AssignmentParticipant.where(parent_id: params[:id], user_id: session[:user].id).first rescue nil
if participant.nil?
participant = AssignmentParticipant.create(parent_id: params[:id], user_id: session[:user].id, can_submit: 1, can_review: 1, can_take_quiz: 1, handle: 'handle')
end
- 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 assign_reviewers_for_team is too high. [32.26/15] Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where("created_at > :time",
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
- 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 assign_quiz_dynamically is too high. [32.42/15] Open
def assign_quiz_dynamically
begin
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first
- 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 save_grade_and_comment_for_reviewer is too high. [30.35/15] Open
def save_grade_and_comment_for_reviewer
review_grade = ReviewGrade.find_by(participant_id: params[:participant_id])
review_grade = ReviewGrade.create(participant_id: params[:participant_id]) if review_grade.nil?
review_grade.grade_for_reviewer = params[:grade_for_reviewer] if params[:grade_for_reviewer]
review_grade.comment_for_reviewer = params[:comment_for_reviewer] if params[:comment_for_reviewer]
- 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 add_metareviewer is too high. [29.9/15] Open
def add_metareviewer
mapping = ResponseMap.find(params[:id])
msg = ''
begin
user = User.from_params(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
Perceived complexity for peer_review_strategy is too high. [21/7] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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 delete_all_metareviewers is too high. [28.53/15] Open
def delete_all_metareviewers
mapping = ResponseMap.find(params[:id])
mmappings = MetareviewResponseMap.where(reviewed_object_id: mapping.map_id)
num_unsuccessful_deletes = 0
mmappings.each do |mmapping|
- 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 peer_review_strategy is too high. [18/6] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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.
Assignment Branch Condition size for start_self_review is too high. [27.37/15] Open
def start_self_review
user_id = params[:reviewer_userid]
assignment = Assignment.find(params[:assignment_id])
team = Team.find_team_for_assignment_and_user(assignment.id, user_id).first
begin
- 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 unsubmit_review is too high. [25.73/15] Open
def unsubmit_review
@response = Response.where(map_id: params[:id]).last
review_response_map = ReviewResponseMap.find_by(id: params[:id])
reviewer = review_response_map.reviewer.name
reviewee = review_response_map.reviewee.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
Assignment Branch Condition size for delete_metareviewer is too high. [24.35/15] Open
def delete_metareviewer
mapping = MetareviewResponseMap.find(params[:id])
assignment_id = mapping.assignment.id
flash[:note] = "The metareview mapping for " + mapping.reviewee.name + " and " + mapping.reviewer.name + " has been deleted."
- 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
Perceived complexity for assign_reviewer_dynamically is too high. [16/7] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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
Class ReviewMappingController
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class ReviewMappingController < ApplicationController
autocomplete :user, :name
# use_google_charts
require 'gchart'
# helper :dynamic_review_assignment
Block has too many lines. [53/25] Open
teams.each do |team|
selected_participants = []
if !team.equal? teams.last
# need to even out the # of reviews for teams
while selected_participants.size < review_strategy.reviews_per_team
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method assign_reviewer_dynamically
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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 delete_outstanding_reviewers is too high. [21.63/15] Open
def delete_outstanding_reviewers
assignment = Assignment.find(params[:id])
team = AssignmentTeam.find(params[:contributor_id])
review_response_maps = team.review_mappings
num_remain_review_response_maps = review_response_maps.size
- 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
Perceived complexity for automatic_review_mapping is too high. [13/7] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
max_team_size = Integer(params[:max_team_size]) # Assignment.find(assignment_id).max_team_size
- 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
Method peer_review_strategy
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
Cyclomatic complexity for automatic_review_mapping is too high. [11/6] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
max_team_size = Integer(params[:max_team_size]) # Assignment.find(assignment_id).max_team_size
- 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.
Cyclomatic complexity for assign_reviewer_dynamically is too high. [11/6] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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.
Assignment Branch Condition size for delete_reviewer is too high. [18.36/15] Open
def delete_reviewer
review_response_map = ReviewResponseMap.find_by(id: params[:id])
if review_response_map and !Response.exists?(map_id: review_response_map.id)
review_response_map.destroy
flash[:success] = "The review mapping for \"" + review_response_map.reviewee.name + "\" and \"" + review_response_map.reviewer.name + "\" has been deleted."
- 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 assign_reviewers_for_team
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where("created_at > :time",
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
- 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 automatic_review_mapping
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def automatic_review_mapping
assignment_id = params[:id].to_i
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
max_team_size = Integer(params[:max_team_size]) # Assignment.find(assignment_id).max_team_size
Method automatic_review_mapping
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def automatic_review_mapping
assignment_id = params[:id].to_i
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
max_team_size = Integer(params[:max_team_size]) # Assignment.find(assignment_id).max_team_size
- 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 assign_reviewers_for_team
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where("created_at > :time",
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
Method assign_reviewer_dynamically
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
Method automatic_review_mapping_strategy
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0)
Method add_reviewer
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_reviewer
assignment = Assignment.find(params[:id])
topic_id = params[:topic_id]
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
- 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 assign_quiz_dynamically
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def assign_quiz_dynamically
begin
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first
- 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
Avoid more than 3 levels of block nesting. Open
participants_with_min_assigned_reviews << participants.index(participant) if participants_hash[participant.id] == min_value
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. Open
assignment.candidate_topics_to_review(reviewer).to_a.sample rescue nil
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. Open
rand_num = if if_condition_1 or if_condition_2
# use original method to get random number
rand(0..num_participants - 1)
else
# rand_num should be the position of this participant in original array
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid using update_attribute
because it skips validations. Open
if @response.update_attribute('is_submitted', false)
- Read upRead up
- Exclude checks
This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations
Example:
# bad
Article.first.decrement!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active
product.touch
Billing.update_all("category = 'authorized', author = 'David'")
user.update_attribute(website: 'example.com')
user.update_columns(last_request_at: Time.current)
Post.update_counters 5, comment_count: -1, action_count: 1
# good
user.update_attributes(website: 'example.com')
FileUtils.touch('file')
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if ReviewResponseMap.where(reviewee_id: params[:contributor_id], reviewer_id: reviewer.id).first.nil?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Line is too long. [193/160] Open
if_condition_2 = (participants_with_min_assigned_reviews.size == 1 and TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))
- Exclude checks
Replace class var @@time_create_last_review_mapping_record with a class instance var. Open
@@time_create_last_review_mapping_record = nil
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Use student_review_num.zero?
instead of student_review_num == 0
. Open
if student_review_num == 0 and submission_review_num == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use student_review_num.zero?
instead of student_review_num == 0
. Open
elsif student_review_num == 0 and submission_review_num != 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Do not use Time.now
without zone. Use one of Time.zone.now
, Time.current
, Time.now.in_time_zone
, Time.now.utc
, Time.now.getlocal
, Time.now.iso8601
, Time.now.jisx0301
, Time.now.rfc3339
, Time.now.to_i
, Time.now.to_f
instead. Open
review_grade.review_graded_at = Time.now
- Read upRead up
- Exclude checks
This cop checks for the use of Time methods without zone.
Built on top of Ruby on Rails style guide (https://github.com/bbatsov/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/ .
Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.
When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.
Example:
# always offense
Time.now
Time.parse('2015-03-02 19:05:37')
# no offense
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
# no offense only if style is 'flexible'
Time.current
DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
Time.at(timestamp).in_time_zone
Line is too long. [163/160] Open
map = ReviewResponseMap.where(reviewed_object_id: params[:id], reviewer_id: participant.id, reviewee_id: params[:team_id], calibrate_to: true).first rescue nil
- Exclude checks
Line is too long. [162/160] Open
flash[:note] = "All metareview mappings for contributor \"" + mapping.reviewee.name + "\" and reviewer \"" + mapping.reviewer.name + "\" have been deleted."
- Exclude checks
Convert if
nested inside else
to elsif
. Open
if assignment.topics? # assignment with topics
- Read upRead up
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Line is too long. [166/160] Open
participant = AssignmentParticipant.create(parent_id: params[:id], user_id: session[:user].id, can_submit: 1, can_review: 1, can_take_quiz: 1, handle: 'handle')
- Exclude checks
Use normalcase for variable numbers. Open
if_condition_1 = (participants_hash[participants[rand_num].id] < review_strategy.reviews_per_student)
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Line is too long. [162/160] Open
selected_participants.each {|index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }
- Exclude checks
Use normalcase for variable numbers. Open
if_condition_2 = (!selected_participants.include? participants[rand_num].id)
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Use only ascii symbols in comments. Open
# it should be counted as “self-review” and we need to make /app/views/submitted_content/_selfreview.html.erb work.
- Read upRead up
- Exclude checks
This cop checks for non-ascii (non-English) characters in comments. You could set an array of allowed non-ascii chars in AllowedChars attribute (empty by default).
Example:
# bad
# Translates from English to 日本語。
# good
# Translates from English to Japanese
Useless assignment to variable - teams_with_uncalibrated_artifacts
. Did you mean teams_with_calibrated_artifacts
? Open
teams_with_uncalibrated_artifacts = []
- 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
Use normalcase for variable numbers. Open
if_condition_1 = participants_with_min_assigned_reviews.empty?
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Use submission_review_num.zero?
instead of submission_review_num == 0
. Open
if student_review_num != 0 and submission_review_num == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if SelfReviewResponseMap.where(reviewee_id: team.id, reviewer_id: params[:reviewer_id]).first.nil?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Use normalcase for variable numbers. Open
if_condition_2 = (participants_with_min_assigned_reviews.size == 1 and TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Line is too long. [162/160] Open
flash[:success] = "The review mapping for \"" + review_response_map.reviewee.name + "\" and \"" + review_response_map.reviewer.name + "\" has been deleted."
- Exclude checks
Line is too long. [176/160] Open
flash[:error] = "A delete action failed:<br/>" + $ERROR_INFO.to_s + "<a href='/review_mapping/delete_metareview/" + mapping.map_id.to_s + "'>Delete this mapping anyway>?"
- Exclude checks
Replace class var @@time_create_last_review_mapping_record with a class instance var. Open
@@time_create_last_review_mapping_record = ReviewResponseMap.
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Use submission_review_num.zero?
instead of submission_review_num == 0
. Open
if student_review_num == 0 and submission_review_num == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0