jeffijoe/awilix

View on GitHub

Showing 80 of 80 total issues

File container.test.ts has 821 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { throws } from 'smid'
import * as util from 'util'
import { createContainer, AwilixContainer } from '../container'
import { Lifetime } from '../lifetime'
import { AwilixResolutionError } from '../errors'
Severity: Major
Found in src/__tests__/container.test.ts - About 1 day to fix

    Function createContainerInternal has 282 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function createContainerInternal<
      T extends object = any,
      U extends object = any,
    >(
      options: ContainerOptions,
    Severity: Major
    Found in src/container.ts - About 1 day to fix

      Function createTokenizer has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
      Open

      export function createTokenizer(source: string) {
        const end = source.length
        let pos: number = 0
        let type: TokenType = 'EOF'
        let value: string = ''
      Severity: Minor
      Found in src/function-tokenizer.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 createContainerInternal has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
      Open

      function createContainerInternal<
        T extends object = any,
        U extends object = any,
      >(
        options: ContainerOptions,
      Severity: Minor
      Found in src/container.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

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

          it('supports scoped lifetime', () => {
            const container = createContainer()
            let scopedCounter = 1
            container.register({
              scoped: asFunction(() => scopedCounter++).scoped(),
      Severity: Major
      Found in src/__tests__/container.test.ts and 2 other locations - About 7 hrs to fix
      src/__tests__/container.test.ts on lines 230..244
      src/__tests__/container.test.ts on lines 246..260

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

      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

          it('caches singletons regardless of scope', () => {
            const container = createContainer()
            let singletonCounter = 1
            container.register({
              singleton: asFunction(() => singletonCounter++).singleton(),
      Severity: Major
      Found in src/__tests__/container.test.ts and 2 other locations - About 7 hrs to fix
      src/__tests__/container.test.ts on lines 214..228
      src/__tests__/container.test.ts on lines 246..260

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

      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

          it('resolves transients regardless of scope', () => {
            const container = createContainer()
            let transientCounter = 1
            container.register({
              transient: asFunction(() => transientCounter++).transient(),
      Severity: Major
      Found in src/__tests__/container.test.ts and 2 other locations - About 7 hrs to fix
      src/__tests__/container.test.ts on lines 214..228
      src/__tests__/container.test.ts on lines 230..244

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

      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 createTokenizer has 157 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function createTokenizer(source: string) {
        const end = source.length
        let pos: number = 0
        let type: TokenType = 'EOF'
        let value: string = ''
      Severity: Major
      Found in src/function-tokenizer.ts - About 6 hrs to fix

        File load-modules.test.ts has 420 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import * as path from 'path'
        import { loadModules, LoadModulesOptions } from '../load-modules'
        import { createContainer } from '../container'
        import { Lifetime } from '../lifetime'
        import { InjectionMode } from '../injection-mode'
        Severity: Minor
        Found in src/__tests__/load-modules.test.ts - About 6 hrs to fix

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

              it('throws an AwilixResolutionError with a resolution path when resolving an unregistered dependency', () => {
                const container = createContainer()
                container.register({
                  first: asFunction((cradle: any) => cradle.second),
                  second: asFunction((cradle: any) => cradle.third),
          Severity: Major
          Found in src/__tests__/container.test.ts and 1 other location - About 5 hrs to fix
          src/__tests__/container.test.ts on lines 419..429

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

          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

              it('throws an AwilixResolutionError when there are cyclic dependencies', () => {
                const container = createContainer()
                container.register({
                  first: asFunction((cradle: any) => cradle.second),
                  second: asFunction((cradle: any) => cradle.third),
          Severity: Major
          Found in src/__tests__/container.test.ts and 1 other location - About 5 hrs to fix
          src/__tests__/container.test.ts on lines 165..175

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

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

          import * as util from 'util'
          import {
            AwilixRegistrationError,
            AwilixResolutionError,
            AwilixTypeError,
          Severity: Minor
          Found in src/container.ts - About 4 hrs to fix

            Function parseParameterList has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
            Open

            export function parseParameterList(source: string): Array<Parameter> | null {
              const { next: _next, done } = createTokenizer(source)
              const params: Array<Parameter> = []
            
              let t: Token = null!
            Severity: Minor
            Found in src/param-parser.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

                it('supports transient lifetime', () => {
                  const container = createContainer()
                  let counter = 1
                  container.register({
                    hehe: asFunction(() => counter++).transient(),
            Severity: Major
            Found in src/__tests__/container.test.ts and 1 other location - About 3 hrs to fix
            src/__tests__/container.test.ts on lines 203..212

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

            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

                it('supports singleton lifetime', () => {
                  const container = createContainer()
                  let counter = 1
                  container.register({
                    hehe: asFunction(() => counter++).singleton(),
            Severity: Major
            Found in src/__tests__/container.test.ts and 1 other location - About 3 hrs to fix
            src/__tests__/container.test.ts on lines 192..201

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

            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 resolve has 90 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              function resolve(name: string | symbol, resolveOpts?: ResolveOptions): any {
                resolveOpts = resolveOpts || {}
            
                try {
                  // Grab the registration by name.
            Severity: Major
            Found in src/container.ts - About 3 hrs to fix

              Function parseParameterList has 85 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function parseParameterList(source: string): Array<Parameter> | null {
                const { next: _next, done } = createTokenizer(source)
                const params: Array<Parameter> = []
              
                let t: Token = null!
              Severity: Major
              Found in src/param-parser.ts - About 3 hrs to fix

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

                    it('resolves single dependency as cradle', () => {
                      container.register({
                        testClass: asClass(TestClass),
                      })
                      const reg = asClass(NeedsCradle).proxy()
                Severity: Major
                Found in src/__tests__/resolvers.test.ts and 1 other location - About 3 hrs to fix
                src/__tests__/resolvers.test.ts on lines 123..131

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

                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

                    it('resolves dependencies manually', () => {
                      container.register({
                        testClass: asClass(TestClass),
                      })
                      const withDepsReg = asClass(WithDeps).classic()
                Severity: Major
                Found in src/__tests__/resolvers.test.ts and 1 other location - About 3 hrs to fix
                src/__tests__/resolvers.test.ts on lines 133..141

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

                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 deps = {
                      container,
                      listModules: jest.fn(() => [
                        { name: 'test', path: 'test.js', opts: { lifetime: Lifetime.SCOPED } },
                        { name: 'test2', path: 'test2.js', opts: null },
                Severity: Major
                Found in src/__tests__/load-modules.test.ts and 1 other location - About 3 hrs to fix
                src/__tests__/load-modules.test.ts on lines 365..376

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

                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