TooAngel/screeps

View on GitHub
src/prototype_room_external.js

Summary

Maintainability
F
5 days
Test Coverage

File prototype_room_external.js has 610 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

const {getMyRoomWithinRange, findMyRoomsSortByDistance} = require('./helper_findMyRooms');
const {addToReputation, initPlayer, addRoomToPlayer} = require('./diplomacy');
const {haveActiveQuest} = require('./quests_player');
Severity: Major
Found in src/prototype_room_external.js - About 1 day to fix

    Function checkBlockedPath has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    Room.prototype.checkBlockedPath = function() {
      for (const pathName of Object.keys(this.getMemoryPaths())) {
        const path = this.getMemoryPath(pathName) || {};
        for (const pos of path) {
          const roomPos = new RoomPosition(pos.x, pos.y, this.name);
    Severity: Minor
    Found in src/prototype_room_external.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 harvestCommodities has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Room.prototype.harvestCommodities = function() {
      if (config.commodities.disabled) {
        return false;
      }
      if (!Memory.commodities) {
    Severity: Major
    Found in src/prototype_room_external.js - About 2 hrs to fix

      Function checkBlocked has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      Room.prototype.checkBlocked = function() {
        const exits = Game.map.describeExits(this.name);
        const callerRoom = this;
        const roomCallback = (roomName) => {
          const room = Game.rooms[roomName] || callerRoom;
      Severity: Minor
      Found in src/prototype_room_external.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 spawnCreepsForReservation has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      function spawnCreepsForReservation(reservationCandidate) {
        for (const roomName of findMyRoomsSortByDistance(reservationCandidate.name)) {
          const room = Game.rooms[roomName];
          if (!room) {
            continue;
      Severity: Minor
      Found in src/prototype_room_external.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 checkBlocked has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Room.prototype.checkBlocked = function() {
        const exits = Game.map.describeExits(this.name);
        const callerRoom = this;
        const roomCallback = (roomName) => {
          const room = Game.rooms[roomName] || callerRoom;
      Severity: Minor
      Found in src/prototype_room_external.js - About 1 hr to fix

        Function checkForQuest has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Room.prototype.checkForQuest = function() {
          if (!isQuestValid(this)) {
            return;
          }
          const data = getQuestData(this);
        Severity: Minor
        Found in src/prototype_room_external.js - About 1 hr to fix

          Function spawnPowerCreeps has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function spawnPowerCreeps(room, baseRoomName) {
            room.log('--------------> Start power harvesting in: ' + room.name + ' from ' + baseRoomName + ' <----------------');
            Game.notify('Start power harvesting in: ' + room.name + ' from ' + baseRoomName);
            Memory.rooms[baseRoomName].queue.push({
              role: 'powerattacker',
          Severity: Minor
          Found in src/prototype_room_external.js - About 1 hr to fix

            Function harvestPower has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            Room.prototype.harvestPower = function() {
              if (config.power.disabled) {
                return false;
              }
            
            
            Severity: Minor
            Found in src/prototype_room_external.js - About 1 hr to fix

              Function spawnCreepsForReservation has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function spawnCreepsForReservation(reservationCandidate) {
                for (const roomName of findMyRoomsSortByDistance(reservationCandidate.name)) {
                  const room = Game.rooms[roomName];
                  if (!room) {
                    continue;
              Severity: Minor
              Found in src/prototype_room_external.js - About 1 hr to fix

                Function checkBlockedPath has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                Room.prototype.checkBlockedPath = function() {
                  for (const pathName of Object.keys(this.getMemoryPaths())) {
                    const path = this.getMemoryPath(pathName) || {};
                    for (const pos of path) {
                      const roomPos = new RoomPosition(pos.x, pos.y, this.name);
                Severity: Minor
                Found in src/prototype_room_external.js - About 1 hr to fix

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

                  Room.prototype.harvestCommodities = function() {
                    if (config.commodities.disabled) {
                      return false;
                    }
                    if (!Memory.commodities) {
                  Severity: Minor
                  Found in src/prototype_room_external.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 checkForQuest has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  Room.prototype.checkForQuest = function() {
                    if (!isQuestValid(this)) {
                      return;
                    }
                    const data = getQuestData(this);
                  Severity: Minor
                  Found in src/prototype_room_external.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

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

                  Room.prototype.harvestPower = function() {
                    if (config.power.disabled) {
                      return false;
                    }
                  
                  
                  Severity: Minor
                  Found in src/prototype_room_external.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 isRouteValidForReservedRoom has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function isRouteValidForReservedRoom(room, route) {
                    // Only allow pathing through owned rooms or already reserved rooms.
                    for (const routeEntry of route) {
                      const routeRoomName = routeEntry.room;
                      if (!Game.rooms[routeRoomName]) {
                  Severity: Minor
                  Found in src/prototype_room_external.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 checkAndSpawnReserver has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  Room.prototype.checkAndSpawnReserver = function() {
                    if (!this.data.reservation) {
                      // TODO Check the closest room and set reservation
                      this.log('No reservation');
                      console.log(new Error().stack);
                  Severity: Minor
                  Found in src/prototype_room_external.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 this.handleUnreservedRoom();
                  Severity: Major
                  Found in src/prototype_room_external.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

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

                      Avoid too many return statements within this function.
                      Open

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

                        Avoid too many return statements within this function.
                        Open

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

                          Avoid too many return statements within this function.
                          Open

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

                            Avoid too many return statements within this function.
                            Open

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

                              Avoid too many return statements within this function.
                              Open

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

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

                                function getQuestData(room) {
                                  const sign = room.controller.sign;
                                  let data;
                                  try {
                                    data = JSON.parse(sign.text);
                                Severity: Minor
                                Found in src/prototype_room_external.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 checkSourcer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                Room.prototype.checkSourcer = function() {
                                  const sources = this.findSources();
                                  const sourcers = this.findSourcer();
                                
                                  for (const source of sources) {
                                Severity: Minor
                                Found in src/prototype_room_external.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

                                Identical blocks of code found in 2 locations. Consider refactoring.
                                Open

                                  Memory.rooms[baseRoomName].queue.push({
                                    role: 'carry',
                                    routing: {
                                      targetRoom: this.name,
                                      targetId: deposits[0].id,
                                Severity: Major
                                Found in src/prototype_room_external.js and 1 other location - About 1 hr to fix
                                src/prototype_room_external.js on lines 313..319

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

                                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

                                Identical blocks of code found in 2 locations. Consider refactoring.
                                Open

                                  Memory.rooms[baseRoomName].queue.push({
                                    role: 'carry',
                                    routing: {
                                      targetRoom: this.name,
                                      targetId: deposits[0].id,
                                Severity: Major
                                Found in src/prototype_room_external.js and 1 other location - About 1 hr to fix
                                src/prototype_room_external.js on lines 306..312

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

                                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 2 locations. Consider refactoring.
                                Open

                                  } else if (baseRoom.getEnergyCapacityAvailable() >= BODYPART_COST.claim + BODYPART_COST.move) {
                                    this.debugLog('reserver', `Spawning reserver from ${baseRoom.name}`);
                                    baseRoom.checkRoleToSpawn('reserver', 1, this.controller.id, this.name, 1);
                                  }
                                Severity: Major
                                Found in src/prototype_room_external.js and 1 other location - About 1 hr to fix
                                src/prototype_room_external.js on lines 490..496

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

                                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 2 locations. Consider refactoring.
                                Open

                                  if (baseRoom.getEnergyCapacityAvailable() >= 2 * (BODYPART_COST.claim + BODYPART_COST.move)) {
                                    this.debugLog('reserver', `Spawning reserver from ${baseRoom.name}`);
                                    baseRoom.checkRoleToSpawn('reserver', 1, this.controller.id, this.name, 2);
                                  } else if (baseRoom.getEnergyCapacityAvailable() >= BODYPART_COST.claim + BODYPART_COST.move) {
                                    this.debugLog('reserver', `Spawning reserver from ${baseRoom.name}`);
                                Severity: Major
                                Found in src/prototype_room_external.js and 1 other location - About 1 hr to fix
                                src/prototype_room_external.js on lines 493..496

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

                                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 2 locations. Consider refactoring.
                                Open

                                  if (reservedRoom.controller.reservation.username !== Memory.username) {
                                    reservedRoom.debugLog('reserver', `reservedRoom ${reservedRoom.name} is reserved by ${reservedRoom.controller.reservation.username}, not reserving a new room`);
                                    return false;
                                  }
                                Severity: Minor
                                Found in src/prototype_room_external.js and 1 other location - About 40 mins to fix
                                src/prototype_room_external.js on lines 690..693

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

                                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 2 locations. Consider refactoring.
                                Open

                                  if (reservedRoom.controller.reservation.ticksToEnd < 2000) {
                                    reservedRoom.debugLog('reserver', `reservedRoom ${reservedRoom.name} reservation not long enough ${reservedRoom.controller.reservation.ticksToEnd} < 2000`);
                                    return false;
                                  }
                                Severity: Minor
                                Found in src/prototype_room_external.js and 1 other location - About 40 mins to fix
                                src/prototype_room_external.js on lines 694..697

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

                                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