TooAngel/screeps

View on GitHub

Showing 594 of 594 total issues

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

Creep.prototype.withdrawRuin = function(onlyEnergy) {
  onlyEnergy = onlyEnergy || false;
  let returnValue = false;
  // FIND_RUINS and get them empty first
  const ruins = this.pos.findInRange(FIND_RUINS, 1);
Severity: Major
Found in src/prototype_creep_resources.js and 1 other location - About 4 hrs to fix
src/prototype_creep_resources.js on lines 127..140

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

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 prototype_creep_startup_tasks.js has 349 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

Creep.execute = function(creep, methods) {
  for (const method of methods) {
    if (method(creep)) {
Severity: Minor
Found in src/prototype_creep_startup_tasks.js - About 4 hrs to fix

    File role_mineral.js has 346 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    
    /*
     * mineral manages the mineral distributions
     *
    Severity: Minor
    Found in src/role_mineral.js - About 4 hrs to fix

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

      function getContainer(creep) {
        if (!creep.data.container) {
          const structures = creep.pos.findInRange(FIND_STRUCTURES, 0, {filter: {structureType: STRUCTURE_CONTAINER}});
          if (structures.length === 0) {
            return;
      Severity: Major
      Found in src/role_sourcer.js and 2 other locations - About 4 hrs to fix
      src/role_sourcer.js on lines 167..176
      src/role_storagefiller.js on lines 49..58

      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

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

      function getTower(creep) {
        if (!creep.data.tower) {
          const structures = creep.pos.findInRange(FIND_MY_STRUCTURES, 1, {filter: {structureType: STRUCTURE_TOWER}});
          if (structures.length === 0) {
            return;
      Severity: Major
      Found in src/role_storagefiller.js and 2 other locations - About 4 hrs to fix
      src/role_sourcer.js on lines 150..159
      src/role_sourcer.js on lines 167..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 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

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

      function getContainerConstructionSite(creep) {
        if (!creep.data.containerConstructionSite) {
          const constructionSites = creep.pos.findInRange(FIND_CONSTRUCTION_SITES, 0, {filter: {structureType: STRUCTURE_CONTAINER}});
          if (constructionSites.length === 0) {
            return;
      Severity: Major
      Found in src/role_sourcer.js and 2 other locations - About 4 hrs to fix
      src/role_sourcer.js on lines 150..159
      src/role_storagefiller.js on lines 49..58

      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

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

      function setStateGetEnergyFromTerminal(creep) {
        if (creep.room.terminal.store.energy < config.terminal.maxEnergyAmount) {
          return false;
        }
        creep.data.state = {
      Severity: Major
      Found in src/role_mineral.js and 1 other location - About 4 hrs to fix
      src/role_mineral.js on lines 246..257

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

      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

      function setStateFillTerminalEnergy(creep) {
        if (creep.room.terminal.store.energy > config.terminal.minEnergyAmount) {
          return false;
        }
        creep.data.state = {
      Severity: Major
      Found in src/role_mineral.js and 1 other location - About 4 hrs to fix
      src/role_mineral.js on lines 265..276

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

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

      Room.prototype.sellByOwnOrders = function(resource, sellAmount) {
        const avgBuyPrice = brain.getMarketOrderAverage(ORDER_BUY, resource);
        const avgSellPrice = brain.getMarketOrderAverage(ORDER_SELL, resource);
        const mySellPrice = Math.max((avgBuyPrice || 1) * config.market.sellOrderPriceMultiplicand, config.market.minSellPrice);
        if (!avgSellPrice || mySellPrice <= avgSellPrice) {
      Severity: Minor
      Found in src/prototype_room_market.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function updateCostMatrixFromPositions has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

      function updateCostMatrixFromPositions(room, costMatrix) {
        for (const positionType of Object.keys(room.data.positions)) {
          if (positionType === 'pathEndLevel' || positionType === 'version') {
            continue;
          }
      Severity: Minor
      Found in src/prototype_room_costmatrix.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function showCreeps has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        showCreeps() {
          for (const room of _.values(Game.rooms)) {
            if (!room.isMy()) {
              continue;
            }
      Severity: Minor
      Found in src/visualizer.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function preMove has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

      roles.carry.preMove = function(creep, directions) {
        if (!validateDirections(creep, directions)) {
          return false;
        }
      
      
      Severity: Minor
      Found in src/role_carry.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

      Room.prototype.orderMinerals = function() {
        if (this.executeEveryTicks(20)) {
          const room = this;
      
          for (const mineral of baseMinerals) {
      Severity: Minor
      Found in src/prototype_room_mineral.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

      Room.prototype.sellByOthersOrders = function(sellAmount, resource, force) {
        const sortByEnergyCostAndPrice = (order) => Game.market.calcTransactionCost(sellAmount, this.name, order.roomName) +
        -order.price * sellAmount / config.market.energyCreditEquivalent;
        if (Memory.orders[ORDER_BUY][resource]) {
          const orders = _.sortBy(Memory.orders[ORDER_BUY][resource].orders, sortByEnergyCostAndPrice);
      Severity: Minor
      Found in src/prototype_room_market.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function preMoveExtractorSourcer has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      Creep.prototype.preMoveExtractorSourcer = function(directions) {
        this.pickupEnergy();
      
        // Sourcer keeper handling
        if (!this.room.controller) {
      Severity: Minor
      Found in src/prototype_creep_move.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      File config.js has 300 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      'use strict';
      
      global.brain = {
        stats: {},
        main: {},
      Severity: Minor
      Found in src/config.js - About 3 hrs to fix

        File role_carry.js has 296 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        'use strict';
        
        /*
         * carry gets energy and brings it to the storage
         *
        Severity: Minor
        Found in src/role_carry.js - About 3 hrs to fix

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

          Room.prototype.buildRampartsAroundSpawns = function() {
            // Build ramparts around the spawn if wallThickness > 1
            // TODO this is not used for a long time and the spawn positions should
            // be taken from `memory.positions.spawn`
            if (config.layout.wallThickness > 1) {
          Severity: Minor
          Found in src/prototype_room_basebuilder.js - About 3 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function preMove has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

          roles.squadheal.preMove = function(creep, directions) {
            creep.creepLog('preMove');
            if (creep.hits < creep.hitsMax) {
              creep.creepLog('preMove heal');
              creep.selfHeal();
          Severity: Minor
          Found in src/role_squadheal.js - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function handleSquadManager has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports.handleSquadManager = function() {
            if (Object.keys(Memory.squads).length > 0) {
              debugLog('brain', 'brain.handleSquadManager squads: ${Object.keys(Memory.squads).length}');
            }
            for (const squadIndex of Object.keys(Memory.squads)) {
          Severity: Minor
          Found in src/brain_squadmanager.js - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Severity
          Category
          Status
          Source
          Language