TheCorrespondingSquares/chess-app

View on GitHub
app/models/pawn.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Class has too many lines. [106/100]
Open

class Pawn < Piece

  def icon
    '&#9823;'
  end
Severity: Minor
Found in app/models/pawn.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class Pawn has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class Pawn < Piece

  def icon
    '&#9823;'
  end
Severity: Minor
Found in app/models/pawn.rb - About 2 hrs to fix

    Method pawn_first_move? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def pawn_first_move?(to_y)
        if is_white?
          self.y_pos == 1 ? to_y < 4 : vertical_move_one_square?(to_y)
        else
          self.y_pos == 6 ? to_y > 3 : vertical_move_one_square?(to_y)
    Severity: Minor
    Found in app/models/pawn.rb - About 25 mins to fix

    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 normalcase for variable numbers.
    Open

        y_down_1 = @opponent_pawn.y_pos - 1
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    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

    Redundant return detected.
    Open

        return opponent_pawn_exists?(x, y)
    Severity: Minor
    Found in app/models/pawn.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.

    Trailing whitespace detected.
    Open

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

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

        @opponent_pawn = game.pieces.find_by(x_pos: x, y_pos: y, name: "Pawn", color: opposite_color)
    Severity: Minor
    Found in app/models/pawn.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"

    Trailing whitespace detected.
    Open

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

    Line is too long. [86/80]
    Open

        opposite_is_on_square?(color, to_x, to_y) && diagonal_move_one_square?(to_x, to_y)
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    Redundant self detected.
    Open

          self.y_pos == 1 ? to_y < 4 : vertical_move_one_square?(to_y)
    Severity: Minor
    Found in app/models/pawn.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/pawn.rb by rubocop

    Extra empty line detected at class body end.
    Open

    
    end
    Severity: Minor
    Found in app/models/pawn.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

    Trailing whitespace detected.
    Open

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

    Trailing whitespace detected.
    Open

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

    Redundant self detected.
    Open

        y = self.y_pos
    Severity: Minor
    Found in app/models/pawn.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 top-level class documentation comment.
    Open

    class Pawn < Piece
    Severity: Minor
    Found in app/models/pawn.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

    Redundant self detected.
    Open

        x = self.x_pos + 1
    Severity: Minor
    Found in app/models/pawn.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

    Extra empty line detected at class body beginning.
    Open

    
      def icon
    Severity: Minor
    Found in app/models/pawn.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

    Final newline missing.
    Open

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

    Redundant self detected.
    Open

        opposite_color = "Black" if self.color == "White"
    Severity: Minor
    Found in app/models/pawn.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

    Redundant self detected.
    Open

        y = self.y_pos
    Severity: Minor
    Found in app/models/pawn.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

        opposite_color = "Black" if self.color == "White"
    Severity: Minor
    Found in app/models/pawn.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"

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

        opposite_color = "White" if self.color == "Black"
    Severity: Minor
    Found in app/models/pawn.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 return detected.
    Open

        return opponent_pawn_exists?(x, y)
    Severity: Minor
    Found in app/models/pawn.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

        x = self.x_pos - 1
    Severity: Minor
    Found in app/models/pawn.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/pawn.rb by rubocop

    Line is too long. [84/80]
    Open

        pawn_move_forward?(to_y) && !is_on_square?(to_x, to_y) && pawn_first_move?(to_y)
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    Redundant self detected.
    Open

          self.y_pos == 6 ? to_y > 3 : vertical_move_one_square?(to_y)
    Severity: Minor
    Found in app/models/pawn.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

        opposite_color = "White" if self.color == "Black"
    Severity: Minor
    Found in app/models/pawn.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"

    Trailing whitespace detected.
    Open

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

    Use normalcase for variable numbers.
    Open

        y_up_1 = @opponent_pawn.y_pos + 1
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    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 y_pos.zero? instead of y_pos == 0.
    Open

        y_pos == 0 && is_black?
    Severity: Minor
    Found in app/models/pawn.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

    Redundant self detected.
    Open

        opposite_color = "White" if self.color == "Black"
    Severity: Minor
    Found in app/models/pawn.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

        opposite_color = "Black" if self.color == "White"
    Severity: Minor
    Found in app/models/pawn.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"

    Trailing whitespace detected.
    Open

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

    Line is too long. [104/80]
    Open

          (pawn_move_vertical?(to_x, to_y) && vertical_move_only?(to_x, to_y)) || can_enpassant?(to_x, to_y)
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    Line is too long. [97/80]
    Open

        @opponent_pawn = game.pieces.find_by(x_pos: x, y_pos: y, name: "Pawn", color: opposite_color)
    Severity: Minor
    Found in app/models/pawn.rb by rubocop

    There are no issues that match your filters.

    Category
    Status