Assignment Branch Condition size for is_able_to_escape_check? is too high. [19.65/15] Open
def is_able_to_escape_check?
((x_pos - 1)..(x_pos + 1)).each do |x|
next if x_out_of_range?(x)
((y_pos - 1 )..(y_pos + 1)).each do |y|
next if y_out_of_range?(y)
- 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 is_able_to_escape_check?
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def is_able_to_escape_check?
((x_pos - 1)..(x_pos + 1)).each do |x|
next if x_out_of_range?(x)
((y_pos - 1 )..(y_pos + 1)).each do |y|
next if y_out_of_range?(y)
- 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
Space inside parentheses detected. Open
((y_pos - 1 )..(y_pos + 1)).each do |y|
- Read upRead up
- Exclude checks
Checks for spaces inside ordinary round parentheses.
Example:
# bad
f( 3)
g = (a + 3 )
# good
f(3)
g = (a + 3)
Inconsistent indentation detected. Open
def icon
# if color == "White"
# '♔'
# else
# '♚'
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Use 2 (not 0) spaces for indentation. Open
after_create :icon
- 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
Inconsistent indentation detected. Open
def valid_move?(to_x, to_y)
return false if friendly_piece_on_square?(to_x, to_y)
horizontal_move_one_square_only?(to_x, to_y) || vertical_move_one_square_only?(to_x, to_y) || diagonal_move_one_square?(to_x, to_y)
end
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Inconsistent indentation detected. Open
def is_able_to_escape_check?
((x_pos - 1)..(x_pos + 1)).each do |x|
next if x_out_of_range?(x)
((y_pos - 1 )..(y_pos + 1)).each do |y|
next if y_out_of_range?(y)
- Read upRead up
- Exclude checks
This cops checks for inconsistent indentation.
Example:
class A
def test
puts 'hello'
puts 'world'
end
end
Missing top-level class documentation comment. Open
class King < Piece
- 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
Redundant self
detected. Open
if !is_on_square?(x, y) && valid_move?(x, y) && !game.possible_check?(self.color, x, y)
- Read upRead up
- Exclude checks
This cop checks for redundant uses of self
.
The usage of self
is only needed when:
Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.
Calling an attribute writer to prevent an local variable assignment.
Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.
Note we allow uses of self
with operators because it would be awkward
otherwise.
Example:
# bad
def foo(bar)
self.baz
end
# good
def foo(bar)
self.bar # Resolves name clash with the argument.
end
def foo
bar = 1
self.bar # Resolves name clash with the local variable.
end
def foo
%w[x y z].select do |bar|
self.bar == bar # Resolves name clash with argument of the block.
end
end
Trailing whitespace detected. Open
- Exclude checks
Line is too long. [135/80] Open
horizontal_move_one_square_only?(to_x, to_y) || vertical_move_one_square_only?(to_x, to_y) || diagonal_move_one_square?(to_x, to_y)
- Exclude checks
Final newline missing. Open
end
- Exclude checks
Extra empty line detected at class body end. Open
end
- Read upRead up
- Exclude checks
This cops checks if empty lines around the bodies of classes match the configuration.
Example: EnforcedStyle: empty_lines
# good
class Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
class Foo
class Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
class Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
class Foo
def bar
# ...
end
end
Rename is_able_to_escape_check?
to able_to_escape_check?
. Open
def is_able_to_escape_check?
- 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. [95/80] Open
if !is_on_square?(x, y) && valid_move?(x, y) && !game.possible_check?(self.color, x, y)
- Exclude checks