Class has too many lines. [130/100] Open
class PiecesController < ApplicationController
before_action :require_game_player, only: [:update, :create, :destroy]
def show
render json: current_piece
- 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 move_if_possible is too high. [32.77/15] Open
def move_if_possible
piece = current_piece
if !@game.game_full?
redirect_to game_path(piece.game)
elsif piece.valid_move?(@new_x_pos, @new_y_pos)
- 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. [26/10] Open
def move_if_possible
piece = current_piece
if !@game.game_full?
redirect_to game_path(piece.game)
elsif piece.valid_move?(@new_x_pos, @new_y_pos)
- 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.
Class PiecesController
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class PiecesController < ApplicationController
before_action :require_game_player, only: [:update, :create, :destroy]
def show
render json: current_piece
Assignment Branch Condition size for update is too high. [27.22/15] Open
def update
piece = current_piece
@new_x_pos = params[:x_pos].to_i
@new_y_pos = params[:y_pos].to_i
@starting_x = current_piece.x_pos
- 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. [13/10] Open
def update
piece = current_piece
@new_x_pos = params[:x_pos].to_i
@new_y_pos = params[:y_pos].to_i
@starting_x = current_piece.x_pos
- 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.
Perceived complexity for move_if_possible is too high. [9/7] Open
def move_if_possible
piece = current_piece
if !@game.game_full?
redirect_to game_path(piece.game)
elsif piece.valid_move?(@new_x_pos, @new_y_pos)
- 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 move_if_possible
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def move_if_possible
piece = current_piece
if !@game.game_full?
redirect_to game_path(piece.game)
elsif piece.valid_move?(@new_x_pos, @new_y_pos)
- 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 move_if_possible
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def move_if_possible
piece = current_piece
if !@game.game_full?
redirect_to game_path(piece.game)
elsif piece.valid_move?(@new_x_pos, @new_y_pos)
Trailing whitespace detected. Open
end
- Exclude checks
Rename is_pawn?
to pawn?
. Open
def is_pawn?
- Read upRead up
- Exclude checks
This cop makes sure that predicates are named properly.
Example:
# bad
def is_even?(value)
end
# good
def even?(value)
end
# bad
def has_value?
end
# good
def value?
end
Line is too long. [87/80] Open
Pusher.trigger('channel', 'trigger_refresh', { message: 'Piece Moved!' })
- Exclude checks
Trailing whitespace detected. Open
- Exclude checks
Trailing whitespace detected. Open
end
- Exclude checks
Missing top-level class documentation comment. Open
class PiecesController < 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
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
current_piece.color == "Black"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Trailing whitespace detected. Open
redirect_to game_path(piece.game)
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if !current_game_player?
- 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 single-quoted strings when you don't need string interpolation or special symbols. Open
flash[:alert] = "Sorry, that move would leave your King in check."
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Trailing whitespace detected. Open
- Exclude checks
Trailing whitespace detected. Open
white_piece_turn? && white_player? && white_piece?
- Exclude checks
Line is too long. [83/80] Open
logger.info "valid_move? results: #{piece.valid_move?(@new_x_pos, @new_y_pos)}"
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if pawn_can_promote?
- 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 single-quoted strings when you don't need string interpolation or special symbols. Open
flash[:notice] = "Your Pawn has been promoted to Queen. Long may she reign."
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
current_piece.color == "White"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Trailing whitespace detected. Open
if move_would_leave_your_king_in_check?
- Exclude checks
Line is too long. [88/80] Open
logger.info "is_obstructed? result: #{piece.is_obstructed?(@new_x_pos, @new_y_pos)}"
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
pawn.update_attributes(name: "Queen", icon: '♛')
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Trailing whitespace detected. Open
- Exclude checks
Favor unless
over if
for negative conditions. Open
if !current_game_player?
flash[:alert] = "Sorry, you are not part of this game."
redirect_to game_path(current_piece.game)
end
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
current_piece.name == "Pawn"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Redundant curly braces around a hash parameter. Open
Pusher.trigger('channel', 'trigger_refresh', { message: 'Piece Moved!' })
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Line is too long. [82/80] Open
flash[:notice] = "Your Pawn has been promoted to Queen. Long may she reign."
- Exclude checks
Use %i
or %I
for an array of symbols. Open
before_action :require_game_player, only: [:update, :create, :destroy]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Trailing whitespace detected. Open
Pusher.trigger('channel', 'trigger_refresh', { message: 'Piece Moved!' })
- Exclude checks
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
flash[:alert] = "Sorry, you are not part of this game."
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"