TooAngel/screeps

View on GitHub
src/prototype_room_basebuilder.js

Summary

Maintainability
F
4 days
Test Coverage

File prototype_room_basebuilder.js has 352 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

/**
 * posIsIn position is in array
 *
Severity: Minor
Found in src/prototype_room_basebuilder.js - About 4 hrs to fix

    Function buildRampartsAroundSpawns has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.buildRampartsAroundSpawns = function() {
      // Build ramparts around the spawn if wallThickness > 1
      // TODO this is not used for a long time and the spawn positions should
      // be taken from `memory.positions.spawn`
      if (config.layout.wallThickness > 1) {
    Severity: Minor
    Found in src/prototype_room_basebuilder.js - About 3 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 setupStructure has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.setupStructure = function(structure) {
      const constructionSites = this.find(FIND_CONSTRUCTION_SITES, {filter: (object) => object.structureType === structure});
      if (setupStructureFinishPriorityStructures(structure, constructionSites)) {
        return true;
      }
    Severity: Minor
    Found in src/prototype_room_basebuilder.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 destroyStructureWall has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.destroyStructureWall = function(structure) {
      if (!structure.hits) {
        return false;
      }
      if (!this.memory.walls) {
    Severity: Minor
    Found in src/prototype_room_basebuilder.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 checkBlockers has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.checkBlockers = function() {
      if (this.controller.level === 1) {
        return false;
      }
      //  this.log('checkBlockers: ' + this.memory.controllerLevel.checkBlockersInterval + ' ' + this.controller.level + ' ' + this.memory.walls);
    Severity: Minor
    Found in src/prototype_room_basebuilder.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 setupStructure has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Room.prototype.setupStructure = function(structure) {
      const constructionSites = this.find(FIND_CONSTRUCTION_SITES, {filter: (object) => object.structureType === structure});
      if (setupStructureFinishPriorityStructures(structure, constructionSites)) {
        return true;
      }
    Severity: Minor
    Found in src/prototype_room_basebuilder.js - About 1 hr to fix

      Function checkPath has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      Room.prototype.checkPath = function() {
        //  this.log('checkPath: ' + this.memory.controllerLevel.checkPathInterval);
        const path = this.getMemoryPath('pathStart-universal');
        if (!path) {
          this.log('Skipping checkPath, routing not initialized, try remove memory');
      Severity: Minor
      Found in src/prototype_room_basebuilder.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 destroyStructureWall has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Room.prototype.destroyStructureWall = function(structure) {
        if (!structure.hits) {
          return false;
        }
        if (!this.memory.walls) {
      Severity: Minor
      Found in src/prototype_room_basebuilder.js - About 1 hr to fix

        Function checkBlockers has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Room.prototype.checkBlockers = function() {
          if (this.controller.level === 1) {
            return false;
          }
          //  this.log('checkBlockers: ' + this.memory.controllerLevel.checkBlockersInterval + ' ' + this.controller.level + ' ' + this.memory.walls);
        Severity: Minor
        Found in src/prototype_room_basebuilder.js - About 1 hr to fix

          Function destroyStructure has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Room.prototype.destroyStructure = function(structure) {
            if (structure.structureType === STRUCTURE_WALL) {
              return this.destroyStructureWall(structure);
            }
            if (structure.structureType === STRUCTURE_ROAD) {
          Severity: Minor
          Found in src/prototype_room_basebuilder.js - About 1 hr to fix

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

            Room.prototype.destroyStructure = function(structure) {
              if (structure.structureType === STRUCTURE_WALL) {
                return this.destroyStructureWall(structure);
              }
              if (structure.structureType === STRUCTURE_ROAD) {
            Severity: Minor
            Found in src/prototype_room_basebuilder.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 destroyStructureSpawn has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function destroyStructureSpawn(room, structure) {
              const spawnsCount = room.findMySpawns().length;
              if (room.memory.misplacedSpawn) {
                if (spawnsCount < config.myRoom.leastSpawnsToRebuildStructureSpawn) {
                  room.memory.misplacedSpawn = false;
            Severity: Minor
            Found in src/prototype_room_basebuilder.js - About 1 hr to fix

              Function buildStructures has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              Room.prototype.buildStructures = function() {
                if (!this.checkBuildStructureValidity()) {
                  return false;
                }
              
              
              Severity: Minor
              Found in src/prototype_room_basebuilder.js - About 55 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 destroyStructureRoad has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              Room.prototype.destroyStructureRoad = function(structure) {
                for (const pathName of Object.keys(this.getMemoryPaths())) {
                  for (const pos of this.getMemoryPath(pathName)) {
                    if (structure.pos.isEqualTo(pos.x, pos.y)) {
                      return false;
              Severity: Minor
              Found in src/prototype_room_basebuilder.js - About 55 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 destroyStructureSpawn has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function destroyStructureSpawn(room, structure) {
                const spawnsCount = room.findMySpawns().length;
                if (room.memory.misplacedSpawn) {
                  if (spawnsCount < config.myRoom.leastSpawnsToRebuildStructureSpawn) {
                    room.memory.misplacedSpawn = false;
              Severity: Minor
              Found in src/prototype_room_basebuilder.js - 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

              Avoid deeply nested control flow statements.
              Open

                        if (spawn.pos.x + x >= 0 && spawn.pos.y + y >= 0 && spawn.pos.x + x < 50 && spawn.pos.y + y < 50) {
                          const pos = new RoomPosition(spawn.pos.x + x, spawn.pos.y + y, spawn.pos.roomName);
                          this.memory.walls.ramparts.push(pos);
                          costMatrixBase.set(pos.x, pos.y, 0);
              
              
              Severity: Major
              Found in src/prototype_room_basebuilder.js - About 45 mins to fix

                Function posIsIn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                function posIsIn(pos, array) {
                  if (!array) {
                    return false;
                  }
                
                
                Severity: Minor
                Found in src/prototype_room_basebuilder.js - About 35 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 clearPosition has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                Room.prototype.clearPosition = function(pos, structure) {
                  const posStructures = pos.lookFor('structure');
                  let returnValue = false;
                  for (const posStructureIndex of Object.keys(posStructures)) {
                    const posStructure = posStructures[posStructureIndex];
                Severity: Minor
                Found in src/prototype_room_basebuilder.js - About 35 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

                Avoid too many return statements within this function.
                Open

                    return destroyStructureSpawn(this, structure);
                Severity: Major
                Found in src/prototype_room_basebuilder.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

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

                    Avoid too many return statements within this function.
                    Open

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

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

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

                            Avoid too many return statements within this function.
                            Open

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

                              Avoid too many return statements within this function.
                              Open

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

                                Avoid too many return statements within this function.
                                Open

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

                                  Avoid too many return statements within this function.
                                  Open

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

                                    Avoid too many return statements within this function.
                                    Open

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

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

                                      function setupStructureFinishPriorityStructures(structure, constructionSites) {
                                        // Only build one spawn at a time, especially for reviving
                                        if (structure === STRUCTURE_SPAWN) {
                                          if (constructionSites.length > 0) {
                                            return true;
                                      Severity: Minor
                                      Found in src/prototype_room_basebuilder.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 checkWrongStructure has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      Room.prototype.checkWrongStructure = function() {
                                        this.debugLog('baseBuilding', 'checkWrongStructure: ' + this.memory.controllerLevel.checkWrongStructureInterval);
                                        if (this.memory.underSiege && this.controller.level >= 3) {
                                          this.log('checkWrongStructure: underSiege');
                                          return false;
                                      Severity: Minor
                                      Found in src/prototype_room_basebuilder.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 2 locations. Consider refactoring.
                                      Open

                                        if (!this.memory.walls || !this.memory.walls.layer) {
                                          this.debugLog('baseBuilding', 'checkBlockers: reset walls');
                                          this.memory.walls = {
                                            exit_i: 0,
                                            ramparts: [],
                                      Severity: Major
                                      Found in src/prototype_room_basebuilder.js and 1 other location - About 1 hr to fix
                                      src/prototype_room_wallsetter.js on lines 95..106

                                      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 62.

                                      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