ssube/textual-engine

View on GitHub

Showing 107 of 123 total issues

File LocalState.ts has 656 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable max-lines */
import { doesExist, InvalidArgumentError, isNone, mustDefault, mustExist, mustFind } from '@apextoaster/js-utils';
import { Container, Inject, Logger } from 'noicejs';

import { NotInitializedError } from '../../error/NotInitializedError.js';
Severity: Major
Found in src/service/state/LocalState.ts - About 1 day to fix

    Function populateRoom has a Cognitive Complexity of 60 (exceeds 6 allowed). Consider refactoring.
    Open

      public async populateRoom(firstRoom: Room, searchRooms: Array<Room>, max: number): Promise<Array<Room>> {
        if (max <= 0) {
          return [];
        }
    
    
    Severity: Minor
    Found in src/util/entity/EntityGenerator.ts - About 1 day 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 step has a Cognitive Complexity of 40 (exceeds 6 allowed). Consider refactoring.
    Open

      public async step(): Promise<StepResult> {
        if (isNone(this.state)) {
          throw new NotInitializedError('state has not been initialized');
        }
    
    
    Severity: Minor
    Found in src/service/state/LocalState.ts - About 5 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 EntityGenerator.ts has 394 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { doesExist, mergeMap, mustExist, setOrPush } from '@apextoaster/js-utils';
    import { Inject, Logger } from 'noicejs';
    
    import { equipItems, isDestPortal, zeroStep } from './index.js';
    import { WorldEntityType } from '../../model/entity/index.js';
    Severity: Minor
    Found in src/util/entity/EntityGenerator.ts - About 5 hrs to fix

      Function findMatching has a Cognitive Complexity of 32 (exceeds 6 allowed). Consider refactoring.
      Open

      export function findMatching<TType extends WorldEntityType>(rooms: ReadonlyArray<ReadonlyRoom>, search: SearchFilter<TType>): Array<Immutable<EntityForType<TType>>> {
        const matchers = mustDefault(search.matchers, createStrictMatcher<TType>());
        const results: Array<EntityForType<TType>> = [];
      
        for (const room of rooms) {
      Severity: Minor
      Found in src/util/entity/find.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 findContainer has a Cognitive Complexity of 28 (exceeds 6 allowed). Consider refactoring.
      Open

      export function findContainer<TType extends ActorType | RoomType>(state: WorldState, search: SearchFilter<TType>): Array<Actor | Room> {
        const matchers = mustDefault(search.matchers, createStrictMatcher<TType>());
        const results = new Set<Actor | Room>();
      
        for (const room of state.rooms) {
      Severity: Minor
      Found in src/util/entity/find.ts - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Function step has 96 lines of code (exceeds 30 allowed). Consider refactoring.
      Open

        public async step(): Promise<StepResult> {
          if (isNone(this.state)) {
            throw new NotInitializedError('state has not been initialized');
          }
      
      
      Severity: Major
      Found in src/service/state/LocalState.ts - About 3 hrs to fix

        Function populateRoom has 94 lines of code (exceeds 30 allowed). Consider refactoring.
        Open

          public async populateRoom(firstRoom: Room, searchRooms: Array<Room>, max: number): Promise<Array<Room>> {
            if (max <= 0) {
              return [];
            }
        
        
        Severity: Major
        Found in src/util/entity/EntityGenerator.ts - About 3 hrs to fix

          LocalStateService has 25 functions (exceeds 20 allowed). Consider refactoring.
          Open

          @Inject(
            INJECT_COUNTER,
            INJECT_EVENT,
            INJECT_LOGGER,
            INJECT_RANDOM,
          Severity: Minor
          Found in src/service/state/LocalState.ts - About 2 hrs to fix

            File TestPlayerActor.ts has 273 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import { expect } from 'chai';
            import { BaseOptions } from 'noicejs';
            
            import { makeCommand, makeCommandIndex } from '../../../src/model/Command.js';
            import { INJECT_EVENT, INJECT_LOCALE } from '../../../src/module/index.js';
            Severity: Minor
            Found in test/service/actor/TestPlayerActor.ts - About 2 hrs to fix

              StateEntityGenerator has 21 functions (exceeds 20 allowed). Consider refactoring.
              Open

              @Inject(INJECT_COUNTER, INJECT_LOGGER, INJECT_RANDOM, INJECT_TEMPLATE)
              export class StateEntityGenerator {
                protected counter: Counter;
                protected logger: Logger;
                protected random: RandomService;
              Severity: Minor
              Found in src/util/entity/EntityGenerator.ts - About 2 hrs to fix

                Function main has 55 lines of code (exceeds 30 allowed). Consider refactoring.
                Open

                export async function main(args: Array<string>): Promise<number> {
                  // parse args
                  const arg = parseArgs(args);
                
                  // load config and create logger
                Severity: Major
                Found in src/main.ts - About 2 hrs to fix

                  Function onJoin has 51 lines of code (exceeds 30 allowed). Consider refactoring.
                  Open

                    public async onJoin(event: ActorJoinEvent): Promise<void> {
                      const generator = mustExist(this.generator);
                      const state = mustExist(this.state);
                      const world = mustExist(this.world);
                  
                  
                  Severity: Major
                  Found in src/service/state/LocalState.ts - About 1 hr to fix

                    Function create has 50 lines of code (exceeds 30 allowed). Consider refactoring.
                    Open

                      public async create(config: ConfigServices): Promise<void> {
                        for (const state of config.states) {
                          if (this.services.has(state.name)) {
                            throw new InvalidArgumentError('state service already exists');
                          }
                    Severity: Minor
                    Found in src/util/service/ServiceManager.ts - About 1 hr to fix

                      Function create has a Cognitive Complexity of 15 (exceeds 6 allowed). Consider refactoring.
                      Open

                        public async create(config: ConfigServices): Promise<void> {
                          for (const state of config.states) {
                            if (this.services.has(state.name)) {
                              throw new InvalidArgumentError('state service already exists');
                            }
                      Severity: Minor
                      Found in src/util/service/ServiceManager.ts - About 1 hr 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 VerbActorMove has 46 lines of code (exceeds 30 allowed). Consider refactoring.
                      Open

                      export async function VerbActorMove(this: ScriptTarget, context: ScriptContext): Promise<void> {
                        const actor = assertActor(this);
                      
                        // find the new room
                        const command = mustExist(context.command);
                      Severity: Minor
                      Found in src/script/verb/actor/ActorMove.ts - About 1 hr to fix

                        Function VerbActorPush has 45 lines of code (exceeds 30 allowed). Consider refactoring.
                        Open

                        export async function VerbActorPush(this: ScriptTarget, context: ScriptContext): Promise<void> {
                          assertActor(this);
                        
                          const command = mustExist(context.command);
                        
                        
                        Severity: Minor
                        Found in src/script/verb/actor/ActorPush.ts - About 1 hr to fix

                          Function moveRoom has 44 lines of code (exceeds 30 allowed). Consider refactoring.
                          Open

                            public async moveRoom(transfer: RoomTransfer, context: ScriptContext): Promise<void> {
                              const { source, target } = transfer;
                          
                              if (!isRoom(source)) {
                                throw new InvalidArgumentError('source entity must be a room');
                          Severity: Minor
                          Found in src/util/entity/EntityTransfer.ts - About 1 hr to fix

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

                                  const world: WorldTemplate = {
                                    ...TEST_WORLD,
                                    templates: {
                                      actors: [{
                                        base: {
                            Severity: Major
                            Found in test/service/state/TestLocalState.ts and 1 other location - About 1 hr to fix
                            test/service/state/TestLocalState.ts on lines 959..997

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

                            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

                                  const world: WorldTemplate = {
                                    ...TEST_WORLD,
                                    templates: {
                                      actors: [{
                                        base: {
                            Severity: Major
                            Found in test/service/state/TestLocalState.ts and 1 other location - About 1 hr to fix
                            test/service/state/TestLocalState.ts on lines 757..795

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

                            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