TheCorrespondingSquares/chess-app

View on GitHub
app/models/game.rb

Summary

Maintainability
A
0 mins
Test Coverage

Method has too many lines. [16/10]
Open

  def stalemate?(color)
    results_in_check = []

    friendly_pieces(color).each do |piece|
      start_x = piece.x_pos
Severity: Minor
Found in app/models/game.rb by rubocop

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 stalemate? is too high. [17.72/15]
Open

  def stalemate?(color)
    results_in_check = []

    friendly_pieces(color).each do |piece|
      start_x = piece.x_pos
Severity: Minor
Found in app/models/game.rb by rubocop

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 populate_board!
    # ------ Black pieces ----------
    8.times do |i|
      Pawn.create(color: 'Black', game_id: self.id, x_pos: i, y_pos: 6, icon:"♟")
    end
Severity: Minor
Found in app/models/game.rb by rubocop

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.

Space missing after colon.
Open

      Pawn.create(color: 'Black', game_id: self.id, x_pos: i, y_pos: 6, icon:"♟")
Severity: Minor
Found in app/models/game.rb by rubocop

Checks for colon (:) not followed by some kind of space. N.B. this cop does not handle spaces after a ternary operator, which are instead handled by Layout/SpaceAroundOperators.

Example:

# bad
def f(a:, b:2); {a:3}; end

# good
def f(a:, b: 2); {a: 3}; end

Trailing whitespace detected.
Open

  
Severity: Minor
Found in app/models/game.rb by rubocop

Trailing whitespace detected.
Open

      
Severity: Minor
Found in app/models/game.rb by rubocop

Line is too long. [86/80]
Open

  scope :available, -> { where('white_player_id is NULL OR black_player_id is NULL') }
Severity: Minor
Found in app/models/game.rb by rubocop

Line is too long. [85/80]
Open

      Piece.create(name: piece, color: 'Black', game_id: self.id, x_pos: i, y_pos: 7)
Severity: Minor
Found in app/models/game.rb by rubocop

Missing space after #.
Open

  #def pawns_can_promote?
Severity: Minor
Found in app/models/game.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Trailing whitespace detected.
Open

          raise ActiveRecord::Rollback          
Severity: Minor
Found in app/models/game.rb by rubocop

Redundant self detected.
Open

      Piece.create(name: piece, color: 'Black', game_id: self.id, x_pos: i, y_pos: 7)
Severity: Minor
Found in app/models/game.rb by rubocop

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

Missing space after #.
Open

  #white player goes first
Severity: Minor
Found in app/models/game.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Trailing whitespace detected.
Open

  end 
Severity: Minor
Found in app/models/game.rb by rubocop

Missing space after #.
Open

  #end
Severity: Minor
Found in app/models/game.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Tab detected.
Open

      CheckMate.new(self, color).call
Severity: Minor
Found in app/models/game.rb by rubocop

Line is too long. [88/80]
Open

      Pawn.create(color: 'White', game_id: self.id, x_pos: i, y_pos: 1, icon: "♙")
Severity: Minor
Found in app/models/game.rb by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  belongs_to :white_player, class_name: "User", optional: true
Severity: Minor
Found in app/models/game.rb by rubocop

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"

Extra empty line detected at class body end.
Open


end
Severity: Minor
Found in app/models/game.rb by rubocop

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

Use 2 (not 1) spaces for indentation.
Open

      CheckMate.new(self, color).call
Severity: Minor
Found in app/models/game.rb by rubocop

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

Trailing whitespace detected.
Open

        
Severity: Minor
Found in app/models/game.rb by rubocop

Redundant return detected.
Open

    return pieces.where(color: color).where(captured: false)
Severity: Minor
Found in app/models/game.rb by rubocop

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.

Redundant self detected.
Open

    white_goes_first || self.turn.even?
Severity: Minor
Found in app/models/game.rb by rubocop

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

Missing space after #.
Open

  #for later use to attach pawn-promotion to UI
Severity: Minor
Found in app/models/game.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      Pawn.create(color: 'Black', game_id: self.id, x_pos: i, y_pos: 6, icon:"♟")
Severity: Minor
Found in app/models/game.rb by rubocop

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 self detected.
Open

      Pawn.create(color: 'Black', game_id: self.id, x_pos: i, y_pos: 6, icon:"♟")
Severity: Minor
Found in app/models/game.rb by rubocop

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      Pawn.create(color: 'White', game_id: self.id, x_pos: i, y_pos: 1, icon: "♙")
Severity: Minor
Found in app/models/game.rb by rubocop

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"

Line is too long. [87/80]
Open

      Pawn.create(color: 'Black', game_id: self.id, x_pos: i, y_pos: 6, icon:"♟")
Severity: Minor
Found in app/models/game.rb by rubocop

Missing top-level class documentation comment.
Open

class Game < ApplicationRecord
Severity: Minor
Found in app/models/game.rb by rubocop

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

Use self.turn.zero? instead of self.turn == 0.
Open

    self.turn == 0
Severity: Minor
Found in app/models/game.rb by rubocop

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

Trailing whitespace detected.
Open

        piece.transaction do   
Severity: Minor
Found in app/models/game.rb by rubocop

Line is too long. [85/80]
Open

      Piece.create(name: piece, color: 'White', game_id: self.id, x_pos: i, y_pos: 0)
Severity: Minor
Found in app/models/game.rb by rubocop

Redundant self detected.
Open

      Pawn.create(color: 'White', game_id: self.id, x_pos: i, y_pos: 1, icon: "&#9817;")
Severity: Minor
Found in app/models/game.rb by rubocop

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

Missing space after #.
Open

  #makes sure both present to start game
Severity: Minor
Found in app/models/game.rb by rubocop

This cop checks whether comments have a leading space after the # denoting the start of the comment. The leading space is not required for some RDoc special syntax, like #++, #--, #:nodoc, =begin- and =end comments, "shebang" directives, or rackup options.

Example:

# bad
#Some comment

# good
# Some comment

%w-literals should be delimited by [ and ].
Open

    %w(Rook Knight Bishop Queen King Bishop Knight Rook)
Severity: Minor
Found in app/models/game.rb by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Redundant self detected.
Open

      Piece.create(name: piece, color: 'White', game_id: self.id, x_pos: i, y_pos: 0)
Severity: Minor
Found in app/models/game.rb by rubocop

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  belongs_to :black_player, class_name: "User", optional: true
Severity: Minor
Found in app/models/game.rb by rubocop

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 self detected.
Open

    self.turn == 0
Severity: Minor
Found in app/models/game.rb by rubocop

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

  
Severity: Minor
Found in app/models/game.rb by rubocop

There are no issues that match your filters.

Category
Status