TooAngel/screeps

View on GitHub
src/prototype_room_init.js

Summary

Maintainability
F
3 days
Test Coverage

File prototype_room_init.js has 441 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

// TODO this does not need to be on the Room object
Room.prototype.setPosition = function(type, pos, value = config.layout.structureAvoid, positionType = 'structure', firstStructure = false) {
  this.debugLog('baseBuilding', `Increasing ${pos} ${type} ${positionType} with ${value}`);
Severity: Minor
Found in src/prototype_room_init.js - About 6 hrs to fix

    Function setLabs has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.setLabs = function(allPaths) {
      let lab1Pos;
      let lab2Pos;
      let pathI;
      let path;
    Severity: Minor
    Found in src/prototype_room_init.js - About 4 hrs 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

    Function costMatrixPathCrossings has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.costMatrixPathCrossings = function(exits) {
      return () => {
        for (const startDir in exits) {
          if (!startDir) {
            continue;
    Severity: Minor
    Found in src/prototype_room_init.js - About 2 hrs 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

    Function setup has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.setup = function() {
      this.debugLog('baseBuilding', `Setup`);
      if (this.memory.setup) {
        if (this.memory.setup.completed) {
          throw new Error('Setup called, while it was already completed');
    Severity: Minor
    Found in src/prototype_room_init.js - About 1 hr 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

    Function setLabs has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Room.prototype.setLabs = function(allPaths) {
      let lab1Pos;
      let lab2Pos;
      let pathI;
      let path;
    Severity: Minor
    Found in src/prototype_room_init.js - About 1 hr to fix

      Function setup has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Room.prototype.setup = function() {
        this.debugLog('baseBuilding', `Setup`);
        if (this.memory.setup) {
          if (this.memory.setup.completed) {
            throw new Error('Setup called, while it was already completed');
      Severity: Minor
      Found in src/prototype_room_init.js - About 1 hr to fix

        Function setStructures has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        Room.prototype.setStructures = function(path) {
          for (let pathI = 0; pathI < path.length; pathI++) {
            const pathPos = new RoomPosition(path[pathI].x, path[pathI].y, this.name);
            const structurePosIterator = pathPos.findNearPosition();
            for (const structurePos of structurePosIterator) {
        Severity: Minor
        Found in src/prototype_room_init.js - About 1 hr 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

        Function checkForSurroundingWalls has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        const checkForSurroundingWalls = function(pos, valueAdd) {
          for (let x = -1; x < 2; x++) {
            for (let y = -1; y < 2; y++) {
              if (pos.x + x >= 0 && pos.y + y >= 0 && pos.x + x < 50 && pos.y + y < 50) {
                const wall = new RoomPosition(pos.x + x, pos.y + y, pos.roomName);
        Severity: Minor
        Found in src/prototype_room_init.js - About 1 hr 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

        Function costMatrixPathCrossings has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Room.prototype.costMatrixPathCrossings = function(exits) {
          return () => {
            for (const startDir in exits) {
              if (!startDir) {
                continue;
        Severity: Minor
        Found in src/prototype_room_init.js - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                    if (this.data.positions.structure.lab.length < CONTROLLER_STRUCTURES.lab[8]) {
                      this.setPosition(STRUCTURE_LAB, pos);
                    }
          Severity: Major
          Found in src/prototype_room_init.js - About 45 mins to fix

            Function setPosition has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            Room.prototype.setPosition = function(type, pos, value = config.layout.structureAvoid, positionType = 'structure', firstStructure = false) {
            Severity: Minor
            Found in src/prototype_room_init.js - About 35 mins to fix

              Avoid too many return statements within this function.
              Open

                  return true;
              Severity: Major
              Found in src/prototype_room_init.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return false;
                Severity: Major
                Found in src/prototype_room_init.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                    return false;
                  Severity: Major
                  Found in src/prototype_room_init.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return false;
                    Severity: Major
                    Found in src/prototype_room_init.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                        return true;
                      Severity: Major
                      Found in src/prototype_room_init.js - About 30 mins to fix

                        Function checkPositions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        Room.prototype.checkPositions = function() {
                          for (const type of [STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LINK, STRUCTURE_OBSERVER, STRUCTURE_NUKER, STRUCTURE_FACTORY]) {
                            if ((this.data.positions.structure[type] || []).length < CONTROLLER_STRUCTURES[type][8]) {
                              let output = 'Structures not found:\n';
                              for (const type of Object.keys(this.data.positions.structure)) {
                        Severity: Minor
                        Found in src/prototype_room_init.js - 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

                        Function getPathLength has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function getPathLength(pathObject) {
                          let lastPos;
                          let value = 0;
                          for (const pos of pathObject.path) {
                            let valueAdd = 0;
                        Severity: Minor
                        Found in src/prototype_room_init.js - 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

                        Similar blocks of code found in 4 locations. Consider refactoring.
                        Open

                          this.debugLog('baseBuilding', `Upgrader position ${upgraderPos} costMatrix value after path ${this.data.costMatrix.get(upgraderPos.x, upgraderPos.y)}`);
                        Severity: Major
                        Found in src/prototype_room_init.js and 3 other locations - About 45 mins to fix
                        src/prototype_room_init.js on lines 76..76
                        src/prototype_room_init.js on lines 80..80
                        src/prototype_room_init.js on lines 136..136

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 50.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 4 locations. Consider refactoring.
                        Open

                            this.debugLog('baseBuilding', `Upgrader position ${upgraderPos} costMatrix value after setFillerArea ${this.data.costMatrix.get(upgraderPos.x, upgraderPos.y)}`);
                        Severity: Major
                        Found in src/prototype_room_init.js and 3 other locations - About 45 mins to fix
                        src/prototype_room_init.js on lines 66..66
                        src/prototype_room_init.js on lines 76..76
                        src/prototype_room_init.js on lines 80..80

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 50.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 4 locations. Consider refactoring.
                        Open

                          this.debugLog('baseBuilding', `Filler position ${fillerPos} costMatrix value before path ${this.data.costMatrix.get(fillerPos.x, fillerPos.y)}`);
                        Severity: Major
                        Found in src/prototype_room_init.js and 3 other locations - About 45 mins to fix
                        src/prototype_room_init.js on lines 66..66
                        src/prototype_room_init.js on lines 80..80
                        src/prototype_room_init.js on lines 136..136

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 50.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 4 locations. Consider refactoring.
                        Open

                          this.debugLog('baseBuilding', `Filler position ${fillerPos} costMatrix value after path ${this.data.costMatrix.get(fillerPos.x, fillerPos.y)}`);
                        Severity: Major
                        Found in src/prototype_room_init.js and 3 other locations - About 45 mins to fix
                        src/prototype_room_init.js on lines 66..66
                        src/prototype_room_init.js on lines 76..76
                        src/prototype_room_init.js on lines 136..136

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 50.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status