tulir/fifteen

View on GitHub

Showing 3 of 3 total issues

Consider simplifying this complex logical expression.
Open

    if (x < 1 || y < 1 || x > puzzle.n || y > puzzle.n) ||
        !((x == puzzle.blank.X && (y == puzzle.blank.Y-1 || y == puzzle.blank.Y+1)) ||
            (y == puzzle.blank.Y && (x == puzzle.blank.X-1 || x == puzzle.blank.X+1))) {
Severity: Critical
Found in fifteen/puzzle.go - About 2 hrs to fix

    Function ParsePuzzle has 7 return statements (exceeds 4 allowed).
    Open

    func ParsePuzzle(input string) (*Puzzle, error) {
        rows := strings.Split(strings.TrimSpace(input), "\n")
        puzzle, err := NewPuzzle(len(rows))
        if err != nil {
            return nil, err
    Severity: Major
    Found in fifteen/parser.go - About 45 mins to fix

      Function renderGrid has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
      Open

      func renderGrid(screen tcell.Screen, size int) {
          cellSize := util.Digits(size*size) + 1
          right := size * cellSize
          bottom := size * 2
          width, height := screen.Size()
      Severity: Minor
      Found in render.go - About 45 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

      Severity
      Category
      Status
      Source
      Language