Mirroar/hivemind

View on GitHub

Showing 1,348 of 1,349 total issues

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

    getSource(creep: MineBuilderCreep): Source {
        const sourcePosition = decodePosition(creep.memory.source);
        return creep.room.find(FIND_SOURCES, {
            filter: source => source.pos.x === sourcePosition.x && source.pos.y === sourcePosition.y,
        })[0];
Severity: Major
Found in src/role/builder.mines.ts and 1 other location - About 3 hrs to fix
src/role/hauler.relay.ts on lines 429..434

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

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

File intershard.ts has 318 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import cache from 'utils/cache';
import hivemind from 'hivemind';
import interShard from 'intershard';
import NavMesh from 'utils/nav-mesh';
import Process from 'process/process';
Severity: Minor
Found in src/process/strategy/intershard.ts - About 3 hrs to fix

    Function addClearingTerminalResourceOptions has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        addClearingTerminalResourceOptions(options: StorageSourceTask[], context: ResourceSourceContext) {
            const storage = this.room.storage;
            const terminal = this.room.terminal;
    
            // Clear out overfull terminal.
    Severity: Minor
    Found in src/dispatcher/resource-source/storage.ts - 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 addMilitaryAttackOptions has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        addMilitaryAttackOptions(creep: BrawlerCreep, options: MilitaryTargetOption[]) {
            const enemies = creep.room.find(FIND_HOSTILE_CREEPS);
            const targetPosition = decodePosition(creep.memory.target);
    
            if (enemies && enemies.length > 0) {
    Severity: Minor
    Found in src/role/brawler.ts - 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 deleteTilesLeadingToDeadEnds has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        deleteTilesLeadingToDeadEnds(roomName: string, minCut: Array<{x: number; y: number}>) {
            // Get terrain and set all cut-tiles as unwalkable.
            const roomTerrain = generateRoomTerrainArray(roomName);
            for (const tile of minCut) {
                roomTerrain[tile.x][tile.y] = UNWALKABLE;
    Severity: Minor
    Found in src/utils/mincut.ts - 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 generateRoomTerrainArray has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    function generateRoomTerrainArray(roomName: string, bounds?: MinCutRect) {
        if (!bounds) bounds = {x1: 0, y1: 0, x2: 49, y2: 49};
    
        // Create two dimensional array of room tiles.
        const roomArray = Array.from({length: 50}).fill(0).map(() => Array.from({length: 50}).fill(UNWALKABLE)) as number[][];
    Severity: Minor
    Found in src/utils/mincut.ts - 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 placeRamparts has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        placeRamparts(): StepResult {
            // Make sure the controller can't directly be reached by enemies.
            const roomIntel = getRoomIntel(this.roomName);
            const safety = roomIntel.calculateAdjacentRoomSafety();
    
    
    Severity: Minor
    Found in src/room/planner/variation-builder.ts - 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 runTick has 88 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        runTick() {
            this.useMemoryFromHeap();
    
            hivemind.segmentMemory.manage();
    
    
    Severity: Major
    Found in src/main.ts - About 3 hrs to fix

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

                  if (!withdrawn && creep.room.memory.controllerContainer) {
                      const controllerContainer = Game.getObjectById<StructureContainer>(creep.room.memory.controllerContainer);
                      if (controllerContainer && controllerContainer.store.energy > 50 && creep.pos.getRangeTo(controllerContainer) <= 1 && creep.withdraw(controllerContainer, RESOURCE_ENERGY) === OK) {
                          withdrawn = true;
                      }
      Severity: Major
      Found in src/role/upgrader.ts and 1 other location - About 3 hrs to fix
      src/role/upgrader.ts on lines 118..123

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

      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 (creep.room.memory.controllerLink) {
                      const controllerLink = Game.getObjectById<StructureLink>(creep.room.memory.controllerLink);
                      if (controllerLink && controllerLink.store[RESOURCE_ENERGY] > 50 && creep.pos.getRangeTo(controllerLink) <= 1 && creep.withdraw(controllerLink, RESOURCE_ENERGY) === OK) {
                          withdrawn = true;
                      }
      Severity: Major
      Found in src/role/upgrader.ts and 1 other location - About 3 hrs to fix
      src/role/upgrader.ts on lines 125..130

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

      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

          getCreepBody(room: Room): BodyPartConstant[] {
              return (new BodyBuilder())
                  .setWeights({[CARRY]: 1})
                  .setMovementMode(MOVEMENT_MODE_ROAD)
                  .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
      Severity: Major
      Found in src/spawn-role/hauler.power.ts and 1 other location - About 3 hrs to fix
      src/spawn-role/dismantler.ts on lines 119..125

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

      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

          getCreepBody(room: Room): BodyPartConstant[] {
              return (new BodyBuilder())
                  .setWeights({[WORK]: 1})
                  .setMovementMode(MOVEMENT_MODE_ROAD)
                  .setEnergyLimit(Math.min(room.energyCapacityAvailable, Math.max(room.energyCapacityAvailable * 0.9, room.energyAvailable)))
      Severity: Major
      Found in src/spawn-role/dismantler.ts and 1 other location - About 3 hrs to fix
      src/spawn-role/hauler.power.ts on lines 64..70

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

      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

      Function manageBlockingCreeps has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

      Creep.prototype.manageBlockingCreeps = function (this: Creep | PowerCreep) {
          const path = this.getCachedPath();
          if (typeof this.memory.cachedPath.position === 'undefined' || this.memory.cachedPath.position === null) {
              for (const pos of path) {
                  // @todo Look for the _furthest_ position that is in range 1.
      Severity: Minor
      Found in src/prototype/creep.movement.ts - 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 render has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

      PathFinder.CostMatrix.prototype.render = function (this: CostMatrix, roomName?: string, asVisual?: boolean): string {
          const terrain = roomName && Game.map.getRoomTerrain(roomName);
          const visual = roomName && asVisual && Game.rooms[roomName]?.visual;
      
          let output = '<table style="display: inline-block">';
      Severity: Minor
      Found in src/prototype/cost-matrix.ts - 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 ensureBoostsHaveLabAssigned has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          private ensureBoostsHaveLabAssigned(boosts: Partial<Record<ResourceConstant, number>>) {
              const roomLabs = this.getAllLabs();
      
              for (const resourceType in boosts) {
                  const assignedLab = _.find(roomLabs, lab => this.memory.labs[lab.id] === resourceType);
      Severity: Minor
      Found in src/boost-manager.ts - 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

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

                          Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnTotalTicks'] = (Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnTotalTicks'] || 0) + spawn.heapMemory.ticks;
      Severity: Major
      Found in src/process/rooms/owned/spawns.ts and 2 other locations - About 3 hrs to fix
      src/process/rooms/owned/spawns.ts on lines 89..89
      src/process/rooms/owned/spawns.ts on lines 90..90

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

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

                          Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnWaiting'] = (Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnWaiting'] || 0) + spawn.heapMemory.waiting;
      Severity: Major
      Found in src/process/rooms/owned/spawns.ts and 2 other locations - About 3 hrs to fix
      src/process/rooms/owned/spawns.ts on lines 89..89
      src/process/rooms/owned/spawns.ts on lines 92..92

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

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

                          Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnSpawning'] = (Memory.roomStats[spawn.room.name]['RCL' + spawn.room.controller.level + 'SpawnSpawning'] || 0) + spawn.heapMemory.spawning;
      Severity: Major
      Found in src/process/rooms/owned/spawns.ts and 2 other locations - About 3 hrs to fix
      src/process/rooms/owned/spawns.ts on lines 90..90
      src/process/rooms/owned/spawns.ts on lines 92..92

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

      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

      Function run has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          run() {
              const operationName = 'room:' + this.room.name;
              let operation = Game.operationsByType.room[operationName];
              if (!operation) {
                  operation = new RoomOperation(operationName);
      Severity: Major
      Found in src/process/rooms/owned.ts - About 3 hrs to fix

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

            {
                label: '🏗️',
                resources: [
                    {color: '#346046', resourceType: RESOURCE_LEMERGIUM_BAR, height: 2, scale: 2 / 5, label: 'L🪨'},
                    {color: '#70F0A9', resourceType: RESOURCE_LEMERGIUM, height: 2, scale: 2},
        Severity: Major
        Found in src/report/resources.ts and 3 other locations - About 3 hrs to fix
        src/report/resources.ts on lines 24..33
        src/report/resources.ts on lines 64..73
        src/report/resources.ts on lines 84..93

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

        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

        Severity
        Category
        Status
        Source
        Language