Class has too many lines. [125/100] Open
class StudentTeamsController < ApplicationController
include AuthorizationHelper
autocomplete :user, :name
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for create is too high. [68.48/15] Open
def create
existing_teams = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id
# check if the team name is in use
if existing_teams.empty?
if params[:team][:name].blank?
- 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 update is too high. [41.24/15] Open
def update
# Update the team name only if the given team name is not used already
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id
if matching_teams.length.zero?
if team.update_attribute('name', params[:team][: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 remove_participant is too high. [35.36/15] Open
def remove_participant
# remove the record from teams_users table
team_user = TeamsUser.where(team_id: params[:team_id], user_id: student.user_id)
remove_team_user(team_user)
# if your old team does not have any members, delete the entry for the team
- 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. [25/10] Open
def create
existing_teams = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id
# check if the team name is in use
if existing_teams.empty?
if params[:team][:name].blank?
- 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 view is too high. [26.55/15] Open
def view
# View will check if send_invs and received_invs are set before showing
# only the owner should be able to see those.
return unless current_user_id? student.user_id
- 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. [15/10] Open
def action_allowed?
# note, this code replaces the following line that cannot be called before action allowed?
return false unless current_user_has_student_privileges?
case action_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 has too many lines. [14/10] Open
def update
# Update the team name only if the given team name is not used already
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id
if matching_teams.length.zero?
if team.update_attribute('name', params[:team][: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 has too many lines. [13/10] Open
def remove_participant
# remove the record from teams_users table
team_user = TeamsUser.where(team_id: params[:team_id], user_id: student.user_id)
remove_team_user(team_user)
# if your old team does not have any members, delete the entry for the team
- 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.
Cyclomatic complexity for action_allowed? is too high. [7/6] Open
def action_allowed?
# note, this code replaces the following line that cannot be called before action allowed?
return false unless current_user_has_student_privileges?
case action_name
- 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 action_allowed? is too high. [15.23/15] Open
def action_allowed?
# note, this code replaces the following line that cannot be called before action allowed?
return false unless current_user_has_student_privileges?
case action_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 action_allowed?
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def action_allowed?
# note, this code replaces the following line that cannot be called before action allowed?
return false unless current_user_has_student_privileges?
case action_name
- 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 create
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def create
existing_teams = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id
# check if the team name is in use
if existing_teams.empty?
if params[:team][:name].blank?
- 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 update
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update
# Update the team name only if the given team name is not used already
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id
if matching_teams.length.zero?
if team.update_attribute('name', params[:team][:name])
- 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 empty lines between method definitions. Open
def mentor
- Read upRead up
- Exclude checks
This cop checks whether method definitions are separated by one empty line.
NumberOfEmptyLines
can be and integer (e.g. 1 by default) or
an array (e.g. [1, 2]) to specificy a minimum and a maximum of
empty lines.
AllowAdjacentOneLineDefs
can be used to configure is adjacent
one line methods definitions are an offense
Example:
# bad
def a
end
def b
end
Example:
# good
def a
end
def b
end
Use 2 (not 3) spaces for indentation. Open
return unless current_user_id? student.user_id
- Read upRead up
- Exclude checks
This cops checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Incorrect indentation detected (column 1 instead of 2). Open
# not have been easily adapted to accommodate this.
- Read upRead up
- Exclude checks
This cops checks the indentation of comments.
Example:
# bad
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
# good
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
Incorrect indentation detected (column 5 instead of 4). Open
# Default return to views/student_team/mentor utilized
- Read upRead up
- Exclude checks
This cops checks the indentation of comments.
Example:
# bad
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
# good
# comment here
def method_name
end
# comment here
a = 'hello'
# yet another comment
if true
true
end
Use Team.size(params[:team_id]).zero?
instead of Team.size(params[:team_id]) == 0
. Open
if (old_team && Team.size(params[:team_id]) == 0 && !old_team.received_any_peer_review?)
- 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
Missing top-level class documentation comment. Open
class StudentTeamsController < 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
Move redirect_to view_student_teams_path student_id: student.id
out of the conditional. Open
redirect_to view_student_teams_path student_id: student.id
- Read upRead up
- Exclude checks
This cop checks for identical lines at the beginning or end of each branch of a conditional statement.
Example:
# bad
if condition
do_x
do_z
else
do_y
do_z
end
# good
if condition
do_x
else
do_y
end
do_z
# bad
if condition
do_z
do_x
else
do_z
do_y
end
# good
do_z
if condition
do_x
else
do_y
end
# bad
case foo
when 1
do_x
when 2
do_x
else
do_x
end
# good
case foo
when 1
do_x
do_y
when 2
# nothing
else
do_x
do_z
end
Don't use parentheses around the condition of an if
. Open
if (old_team && Team.size(params[:team_id]) == 0 && !old_team.received_any_peer_review?)
- Read upRead up
- Exclude checks
This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.
Example:
# bad
x += 1 while (x < 10)
foo unless (bar || baz)
if (x > 10)
elsif (x < 3)
end
# good
x += 1 while x < 10
foo unless bar || baz
if x > 10
elsif x < 3
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if are_needed_authorizations_present?(params[:student_id], 'reader', 'reviewer', 'submitter')
- 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
Prefer !expression.nil?
over expression != nil
. Open
if parent.assignment != nil && parent.assignment.auto_assign_mentor
- Read upRead up
- Exclude checks
This cop checks for non-nil checks, which are usually redundant.
Example:
# bad
if x != nil
end
# good (when not allowing semantic changes)
# bad (when allowing semantic changes)
if !x.nil?
end
# good (when allowing semantic changes)
if x
end
Non-nil checks are allowed if they are the final nodes of predicate.
# good
def signed_in?
!current_user.nil?
end
Move redirect_to view_student_teams_path student_id: student.id
out of the conditional. Open
redirect_to view_student_teams_path student_id: student.id
- Read upRead up
- Exclude checks
This cop checks for identical lines at the beginning or end of each branch of a conditional statement.
Example:
# bad
if condition
do_x
do_z
else
do_y
do_z
end
# good
if condition
do_x
else
do_y
end
do_z
# bad
if condition
do_z
do_x
else
do_z
do_y
end
# good
do_z
if condition
do_x
else
do_y
end
# bad
case foo
when 1
do_x
when 2
do_x
else
do_x
end
# good
case foo
when 1
do_x
do_y
when 2
# nothing
else
do_x
do_z
end