Mirroar/hivemind

View on GitHub

Showing 1,361 of 1,362 total issues

Function moveUsingNavMesh has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

Creep.prototype.moveUsingNavMesh = function (this: Creep | PowerCreep, targetPos, options) {
    if (!hivemind.segmentMemory.isReady()) return OK;

    if (!options) options = {};

Severity: Minor
Found in src/prototype/creep.movement.ts - 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 addConnectingPathsForRegion has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    addConnectingPathsForRegion(region: RegionInfo, paths: Record<number, Record<number, number>>, roomName: string, costMatrix: CostMatrix) {
        const centerXR = region.center % 50;
        const centerYR = Math.floor(region.center / 50);

        for (const exitId of region.exits) {
Severity: Minor
Found in src/utils/nav-mesh.ts - 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 addHarvesterOptionForPosition has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    addHarvesterOptionForPosition(room: Room, position: RoomPosition, options: RemoteMiningSpawnOption[]) {
        const targetPos = encodePosition(position);
        const operation = Game.operationsByType.mining['mine:' + position.roomName];

        // Don't spawn if enemies are in the room.
Severity: Minor
Found in src/spawn-role/remote-mining.ts - 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

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

        for (const lab of this.structuresByType[STRUCTURE_LAB] || []) {
            if (this.roomPlanner.isPlannedLocation(lab.pos, 'lab')) continue;
            if (
                !this.roomPlanner.isPlannedLocation(lab.pos, 'road')
                && !this.roomPlanner.isPlannedLocation(lab.pos, 'spawn')
Severity: Major
Found in src/room/room-manager.ts and 1 other location - About 4 hrs to fix
src/room/room-manager.ts on lines 183..193

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

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

        for (const lab of this.structuresByType[STRUCTURE_LINK] || []) {
            if (this.roomPlanner.isPlannedLocation(lab.pos, 'link')) continue;
            if (
                !this.roomPlanner.isPlannedLocation(lab.pos, 'road')
                && !this.roomPlanner.isPlannedLocation(lab.pos, 'spawn')
Severity: Major
Found in src/room/room-manager.ts and 1 other location - About 4 hrs to fix
src/room/room-manager.ts on lines 171..181

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

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

/* global FIND_DROPPED_RESOURCES RESOURCE_ENERGY OK LOOK_CONSTRUCTION_SITES
ERR_NO_PATH ERR_NOT_IN_RANGE STRUCTURE_CONTAINER STRUCTURE_ROAD
FIND_MY_CONSTRUCTION_SITES LOOK_STRUCTURES MAX_CONSTRUCTION_SITES */

// @todo Collect energy if it's lying on the path.
Severity: Minor
Found in src/role/hauler.relay.ts - About 4 hrs to fix

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

            _.each(orders, order => {
                if (order.amount < 100) return;
                const transactionCost = isIntershardResource(resourceType) ? 0 : Game.market.calcTransactionCost(1000, roomName, order.roomName);
                const credits = 1000 * order.price;
                const score = credits - (0.3 * transactionCost);
    Severity: Major
    Found in src/process/trade.ts and 1 other location - About 4 hrs to fix
    src/process/trade.ts on lines 538..548

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

    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

            _.each(orders, order => {
                if (order.amount < 100) return;
                const transactionCost = isIntershardResource(resourceType) ? 0 : Game.market.calcTransactionCost(1000, roomName, order.roomName);
                const credits = 1000 * order.price;
                const score = credits + (0.3 * transactionCost);
    Severity: Major
    Found in src/process/trade.ts and 1 other location - About 4 hrs to fix
    src/process/trade.ts on lines 506..516

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

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

        run(creep: PowerHaulerCreep) {
            if (!creep.memory.isReturning && (creep.store.getFreeCapacity() === 0 || (creep.store.power || 0) > creep.store.getCapacity() / 10)) {
                // Return home.
                creep.memory.isReturning = true;
                return;
    Severity: Minor
    Found in src/role/power/hauler.ts - 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 getResourceLevelCutoffs has a Cognitive Complexity of 31 (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 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 followCachedPath has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    Creep.prototype.followCachedPath = function (this: Creep | PowerCreep) {
        drawCreepMovement(this);
    
        container.get('TrafficManager').setMoving(this);
        this.heapMemory._moveBlocked = false;
    Severity: Minor
    Found in src/prototype/creep.movement.ts - 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 createNavigationMatrix has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        createNavigationMatrix(): CostMatrix {
            const matrix = new PathFinder.CostMatrix();
            const terrain = new Room.Terrain(this.roomName);
    
            for (const locationType of this.getPositionTypes()) {
    Severity: Minor
    Found in src/room/planner/room-plan.ts - 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

    File builder.remote.ts has 354 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* global RoomPosition FIND_SOURCES FIND_STRUCTURES STRUCTURE_SPAWN
    FIND_MY_STRUCTURES RESOURCE_ENERGY ERR_NOT_IN_RANGE STRUCTURE_RAMPART
    FIND_MY_CONSTRUCTION_SITES STRUCTURE_TOWER FIND_DROPPED_RESOURCES
    STRUCTURE_CONTAINER FIND_SOURCES_ACTIVE */
    
    
    Severity: Minor
    Found in src/role/builder.remote.ts - About 4 hrs to fix

      Function findPath has 111 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          findPath(startPos: RoomPosition, endPos: RoomPosition, options?: {maxPathLength?: number; allowDanger?: boolean; maxCpu?: number}): {
              path?: RoomPosition[];
              length?: number;
              incomplete: boolean;
          } {
      Severity: Major
      Found in src/utils/nav-mesh.ts - About 4 hrs to fix

        Function cleanup has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            cleanup() {
                // Periodically clean creep memory.
                if (Game.time % 16 === 7) {
                    for (const name in Memory.creeps) {
                        if (!Game.creeps[name]) {
        Severity: Minor
        Found in src/main.ts - 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 manageExtractors has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            manageExtractors() {
                const plannedLocations = this.roomPlanner.getLocations('extractor');
                if (plannedLocations.length <= CONTROLLER_STRUCTURES[STRUCTURE_EXTRACTOR][this.room.controller.level]) {
                    this.buildPlannedStructures('extractor', STRUCTURE_EXTRACTOR);
                    return;
        Severity: Minor
        Found in src/room/room-manager.ts - 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

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

            getRangedCreepBody(room: Room): BodyPartConstant[] {
                return (new BodyBuilder())
                    .setWeights({[RANGED_ATTACK]: 1})
                    .setMoveBufferRatio(0.8)
                    .setMovementMode(settings.get('constructRoadsUnderRamparts') ? MOVEMENT_MODE_ROAD : MOVEMENT_MODE_PLAINS)
        Severity: Major
        Found in src/spawn-role/room-defense.ts and 1 other location - About 4 hrs to fix
        src/spawn-role/room-defense.ts on lines 169..176

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

        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

            getAttackCreepBody(room: Room): BodyPartConstant[] {
                return (new BodyBuilder())
                    .setWeights({[ATTACK]: 1})
                    .setMoveBufferRatio(0.8)
                    .setMovementMode(settings.get('constructRoadsUnderRamparts') ? MOVEMENT_MODE_ROAD : MOVEMENT_MODE_PLAINS)
        Severity: Major
        Found in src/spawn-role/room-defense.ts and 1 other location - About 4 hrs to fix
        src/spawn-role/room-defense.ts on lines 178..185

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

        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

        RoomVariationBuilder has 34 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export default class RoomVariationBuilder extends RoomVariationBuilderBase {
            exitCenters: ExitCoords;
            roomCenter: RoomPosition;
            roomCenterEntrances: RoomPosition[];
            protected sourceInfo: Record<string, {
        Severity: Minor
        Found in src/room/planner/variation-builder.ts - About 4 hrs to fix

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

              getPath(creep: RelayHaulerCreep): RoomPosition[] | null {
                  if (!creep.operation) return null;
          
                  const paths = creep.operation.getPaths();
                  if (!paths[creep.memory.source] || !paths[creep.memory.source].accessible) return null;
          Severity: Major
          Found in src/role/hauler.relay.ts and 1 other location - About 4 hrs to fix
          src/role/builder.mines.ts on lines 135..142

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

          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