Function findPath
has a Cognitive Complexity of 80 (exceeds 5 allowed). Consider refactoring. Open
findPath(startPos: RoomPosition, endPos: RoomPosition, options?: {maxPathLength?: number; allowDanger?: boolean; maxCpu?: number}): {
path?: RoomPosition[];
length?: number;
incomplete: boolean;
} {
- Read upRead up
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 nav-mesh.ts
has 618 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* global PathFinder Room RoomPosition LEFT RIGHT TOP BOTTOM
TERRAIN_MASK_WALL STRUCTURE_KEEPER_LAIR */
import cache from 'utils/cache';
import hivemind from 'hivemind';
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) {
- Read upRead up
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 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;
} {
Function getRegions
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
getRegions(exits: ExitInfo[]): RegionInfo[] {
this.exitLookup = {};
for (const exit of exits) {
this.exitLookup[exit.id] = exit;
}
- Read upRead up
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 getRegions
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
getRegions(exits: ExitInfo[]): RegionInfo[] {
this.exitLookup = {};
for (const exit of exits) {
this.exitLookup[exit.id] = exit;
}
NavMesh
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
export default class NavMesh {
memory: NavMemory;
terrain: RoomTerrain;
costMatrix: CostMatrix;
exitLookup: Record<number, ExitInfo>;
Function getAdjacentRoom
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
getAdjacentRoom(roomName: string, exitId: number): string {
// @todo Use RoomIntel.getExits() or Game.map.describeExits() instead.
const parts = /(\w)(\d+)(\w)(\d+)/.exec(roomName);
const dir = Math.floor(exitId / 20);
- Read upRead up
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 collectExitGroups
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
collectExitGroups(roomName: string, dir: DirectionConstant, vertical: boolean, offset: number): ExitInfo[] {
const exits: ExitInfo[] = [];
const isAvailable = this.isAvailableExitDirection(roomName, dir);
let groupId = 1;
let currentStart: number = null;
- Read upRead up
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 generateForRoom
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
generateForRoom(roomName: string) {
// Mesh doesn't need to be updated very often.
// @todo Allow forcing update for when we dismantle a structure.
if (
this.memory.rooms[roomName]?.paths
Function addConnectingPathsForRegion
has 38 lines of code (exceeds 25 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) {
Function getAdjacentRoom
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
getAdjacentRoom(roomName: string, exitId: number): string {
// @todo Use RoomIntel.getExits() or Game.map.describeExits() instead.
const parts = /(\w)(\d+)(\w)(\d+)/.exec(roomName);
const dir = Math.floor(exitId / 20);
Function getPortals
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
getPortals(roomName: string) {
const portals: Record<string, {
targetRoom: string;
positions: RoomPosition[];
totalX: number;
Function calculateCostMultiplier
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
calculateCostMultiplier(roomName: string, allowDanger: boolean): number {
let costMultiplier = 1;
if (hivemind.segmentMemory.isReady()) {
const roomIntel = getRoomIntel(roomName);
if (roomIntel.isOwned()) {
- Read upRead up
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 collectExitGroups
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
collectExitGroups(roomName: string, dir: DirectionConstant, vertical: boolean, offset: number): ExitInfo[] {
const exits: ExitInfo[] = [];
const isAvailable = this.isAvailableExitDirection(roomName, dir);
let groupId = 1;
let currentStart: number = null;
Function generateForRoom
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
generateForRoom(roomName: string) {
// Mesh doesn't need to be updated very often.
// @todo Allow forcing update for when we dismantle a structure.
if (
this.memory.rooms[roomName]?.paths
- Read upRead up
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 getPortals
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
getPortals(roomName: string) {
const portals: Record<string, {
targetRoom: string;
positions: RoomPosition[];
totalX: number;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
Avoid too many return
statements within this function. Open
return parts[1] + parts[2] + 'S0';
Avoid too many return
statements within this function. Open
return 'E0' + parts[3] + parts[4];
Avoid too many return
statements within this function. Open
return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
Avoid too many return
statements within this function. Open
return parts[1] + (Number.parseInt(parts[2], 10) - 1) + parts[3] + parts[4];
Avoid too many return
statements within this function. Open
return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) - 1);
Avoid too many return
statements within this function. Open
return 'W0' + parts[3] + parts[4];
Avoid too many return
statements within this function. Open
return parts[1] + (Number.parseInt(parts[2], 10) - 1) + parts[3] + parts[4];
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 0:
// Exit is due north.
if (parts[3] === 'N') {
return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
}
- Read upRead up
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 143.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 2:
// Exit is due south.
if (parts[3] === 'S') {
return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
}
- Read upRead up
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 143.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 1:
// Exit is due east.
if (parts[1] === 'E') {
return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
}
- Read upRead up
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 140.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
default:
// Exit is due west.
if (parts[1] === 'W') {
return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
}
- Read upRead up
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 140.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76