Mirroar/hivemind

View on GitHub

Showing 1,365 of 1,365 total issues

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

    execute(task: LabSourceTask, context: ResourceSourceContext) {
        const creep = context.creep;
        const target = Game.getObjectById(task.target);

        creep.whenInRange(1, target, () => {
Severity: Major
Found in src/dispatcher/resource-source/lab.ts and 1 other location - About 7 hrs to fix
src/dispatcher/resource-source/structure.ts on lines 38..54

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

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

    execute(task: WorkerCreepDestinationTask, context: ResourceDestinationContext) {
        const creep = context.creep;
        const target = Game.getObjectById(task.target);
        creep.whenInRange(1, target, () => {
            if (task.amount) {
Severity: Major
Found in src/dispatcher/resource-destination/worker-creep.ts and 1 other location - About 7 hrs to fix
src/dispatcher/resource-destination/structure.ts on lines 37..51

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

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

    execute(task: TaskType, context: ResourceDestinationContext) {
        const creep = context.creep;
        const target = Game.getObjectById(task.target);

        creep.whenInRange(1, target, () => {
Severity: Major
Found in src/dispatcher/resource-destination/structure.ts and 1 other location - About 7 hrs to fix
src/dispatcher/resource-destination/worker-creep.ts on lines 80..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 177.

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 brawler.ts has 459 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global PathFinder RoomPosition StructureController ATTACK SYSTEM_USERNAME
STRUCTURE_CONTROLLER STRUCTURE_STORAGE STRUCTURE_SPAWN STRUCTURE_TOWER HEAL
LOOK_STRUCTURES FIND_STRUCTURES FIND_MY_CREEPS CREEP_LIFE_TIME CLAIM
FIND_HOSTILE_STRUCTURES OK STRUCTURE_TERMINAL STRUCTURE_INVADER_CORE
ERR_BUSY ERR_NOT_OWNER ERR_TIRED RANGED_ATTACK FIND_HOSTILE_CREEPS */
Severity: Minor
Found in src/role/brawler.ts - About 7 hrs to fix

    File expand.ts has 456 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* global PathFinder Room RoomPosition CREEP_LIFE_TIME FIND_MY_CREEPS
    TERRAIN_MASK_WALL STRUCTURE_ROAD FIND_CONSTRUCTION_SITES STRUCTURE_RAMPART */
    
    import cache from 'utils/cache';
    import Process from 'process/process';
    Severity: Minor
    Found in src/process/strategy/expand.ts - About 6 hrs to fix

      Function getOntoCachedPath has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

      Creep.prototype.getOntoCachedPath = function (this: Creep | PowerCreep) {
          const creep = this;
          const target = this.pos.findClosestByRange(this.getCachedPath(), {
              filter: pos => {
                  // Try to move to a position on the path that is in the current room.
      Severity: Minor
      Found in src/prototype/creep.movement.ts - About 6 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 getConnectingPaths has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

          getConnectingPaths(regions: RegionInfo[], roomName: string): Record<number, Record<number, number>> {
              const paths: Record<number, Record<number, number>> = {};
              const costMatrix = getCostMatrix(roomName, {ignoreMilitary: true});
      
              for (const region of regions) {
      Severity: Minor
      Found in src/utils/nav-mesh.ts - About 6 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 manageStructures has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

          manageStructures() {
              if (_.size(Game.spawns) === 1 && _.sample(Game.spawns).room.name === this.room.name && this.room.controller.level < 4) {
                  // In our first room, getting more extensions is pretty important for
                  // spawning bigger creeps asap.
                  this.manageExtensions();
      Severity: Minor
      Found in src/room/room-manager.ts - About 6 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 manageTowers has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
      Open

          manageTowers() {
              const towers = _.filter(this.room.myStructuresByType[STRUCTURE_TOWER], s => s.energy > 0);
      
              if (towers.length === 0) return;
      
      
      Severity: Minor
      Found in src/process/rooms/owned/defense.ts - About 6 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

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

              if (path[0].roomName === this.pos.roomName) {
                  this.move(this.pos.getDirectionTo(path[0]));
      
                  const creep = path[0].lookFor(LOOK_CREEPS)[0];
                  if (creep) container.get('TrafficManager').setBlockingCreep(this, creep);
      Severity: Major
      Found in src/prototype/creep.movement.ts and 1 other location - About 6 hrs to fix
      src/prototype/creep.movement.ts on lines 384..394

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

      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

                  if (path[0].roomName === this.pos.roomName) {
                      this.move(this.pos.getDirectionTo(path[0]));
      
                      const creep = path[0].lookFor(LOOK_CREEPS)[0];
                      if (creep) container.get('TrafficManager').setBlockingCreep(this, creep);
      Severity: Major
      Found in src/prototype/creep.movement.ts and 1 other location - About 6 hrs to fix
      src/prototype/creep.movement.ts on lines 437..447

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

      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 checkClaimPath has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          checkClaimPath() {
              const info = this.memory.currentTarget;
              if (!info) return;
      
              const room = Game.rooms[info.roomName];
      Severity: Minor
      Found in src/process/strategy/expand.ts - About 6 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

      File operator.ts has 421 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /* global RoomPosition OK POWER_INFO PWR_GENERATE_OPS PWR_REGEN_SOURCE
      PWR_OPERATE_STORAGE PWR_OPERATE_SPAWN RESOURCE_OPS STORAGE_CAPACITY
      STRUCTURE_SPAWN PWR_OPERATE_EXTENSION RESOURCE_ENERGY
      PWR_REGEN_MINERAL POWER_CREEP_LIFE_TIME PWR_OPERATE_TOWER */
      
      
      Severity: Minor
      Found in src/role/power-creep/operator.ts - About 6 hrs to fix

        File remote-mining.ts has 421 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        /* global MOVE CLAIM BODYPART_COST CONTROLLER_RESERVE_MAX RESOURCE_ENERGY */
        
        import BodyBuilder from 'creep/body-builder';
        import hivemind from 'hivemind';
        import settings from 'settings-manager';
        Severity: Minor
        Found in src/spawn-role/remote-mining.ts - About 6 hrs to fix

          Function calculateRoomPath has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
          Open

          Room.prototype.calculateRoomPath = function (targetRoom: string, options) {
              const roomName = this.name;
          
              if (!options) options = {};
          
          
          Severity: Minor
          Found in src/prototype/room.pathfinding.ts - About 6 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 getResourceLevelCutoffs has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
          Open

          Room.prototype.getResourceLevelCutoffs = function (this: Room, resourceType: ResourceConstant): ResourceLevelCuttoffs {
              if (resourceType === RESOURCE_ENERGY) {
                  // Defending rooms need energy to defend.
                  if (this.defense.getEnemyStrength() >= ENEMY_STRENGTH_NORMAL) return [1_000_000, 100_000, 50_000];
          
          
          Severity: Minor
          Found in src/prototype/room.resources.ts - About 6 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

          File trade.ts has 413 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          /* global RESOURCES_ALL RESOURCE_ENERGY RESOURCE_POWER OK RESOURCE_OPS
          ORDER_BUY ORDER_SELL PIXEL STORAGE_CAPACITY INTERSHARD_RESOURCES
          REACTION_TIME */
          
          import cache from 'utils/cache';
          Severity: Minor
          Found in src/process/trade.ts - About 5 hrs to fix

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

            Object.defineProperty(Source.prototype, 'harvesters', {
                /**
                 * Gets a source's assigned harvesters.
                 *
                 * @return {Creep[]}
            Severity: Major
            Found in src/manager.source.ts and 1 other location - About 5 hrs to fix
            src/manager.source.ts on lines 48..69

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

            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

            Object.defineProperty(Mineral.prototype, 'harvesters', {
                /**
                 * Gets a mineral's assigned harvesters.
                 *
                 * @return {Creep[]}
            Severity: Major
            Found in src/manager.source.ts and 1 other location - About 5 hrs to fix
            src/manager.source.ts on lines 24..45

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

            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

                isValid(task: LabSourceTask, context: ResourceSourceContext) {
                    if (!task.resourceType) return false;
                    const structure = Game.getObjectById(task.target);
                    if (!structure) return false;
                    if (structure.store.getUsedCapacity(task.resourceType) === 0) return false;
            Severity: Major
            Found in src/dispatcher/resource-source/lab.ts and 1 other location - About 5 hrs to fix
            src/dispatcher/resource-source/structure.ts on lines 27..36

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

            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