jeffijoe/awilix

View on GitHub

Showing 80 of 80 total issues

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

    const deps = {
      container,
      listModules: jest.fn(() => [
        {
          name: 'test',
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 339..346

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

File param-parser.test.ts has 284 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { parseParameterList } from '../param-parser'

describe('parseParameterList', () => {
  it('returns an empty array when invalid input is given', () => {
    expect(parseParameterList('')).toEqual([])
Severity: Minor
Found in src/__tests__/param-parser.test.ts - About 2 hrs to fix

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

        class KeysTest {
          nonexistentProp: PropertyDescriptor | undefined
          testProp: PropertyDescriptor | undefined
          constructor(cradle: any) {
            this.testProp = Object.getOwnPropertyDescriptor(cradle, 'test')
    Severity: Major
    Found in src/__tests__/container.test.ts and 1 other location - About 2 hrs to fix
    src/__tests__/container.test.ts on lines 867..877

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

    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

        class KeysTest {
          nonexistentProp: PropertyDescriptor | undefined
          testProp: PropertyDescriptor | undefined
          constructor(cradle: any) {
            this.testProp = Object.getOwnPropertyDescriptor(cradle, 'test')
    Severity: Major
    Found in src/__tests__/container.test.ts and 1 other location - About 2 hrs to fix
    src/__tests__/container.test.ts on lines 842..852

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

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

    import { AwilixContainer, FunctionReturning, ResolveOptions } from './container'
    import { AwilixTypeError } from './errors'
    import { InjectionMode, InjectionModeType } from './injection-mode'
    import { Lifetime, LifetimeType } from './lifetime'
    import { Parameter, parseParameterList } from './param-parser'
    Severity: Minor
    Found in src/resolvers.ts - About 2 hrs to fix

      Function advance has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function advance() {
          value = ''
          type = 'EOF'
          // eslint-disable-next-line no-constant-condition
          while (true) {
      Severity: Major
      Found in src/function-tokenizer.ts - About 2 hrs to fix

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

                container.register({
                  scoped: asFunction((cradle: any) => cradle.val, {
                    lifetime: Lifetime.SCOPED,
                  }),
                  singleton: asFunction((cradle: any) => cradle.val, {
        Severity: Major
        Found in src/__tests__/container.test.ts and 1 other location - About 2 hrs to fix
        src/__tests__/container.test.ts on lines 738..745

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

        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

                container.register({
                  scoped: asFunction((cradle: any) => cradle.singleton, {
                    lifetime: Lifetime.SCOPED,
                  }),
                  singleton: asFunction((cradle: any) => cradle.val, {
        Severity: Major
        Found in src/__tests__/container.test.ts and 1 other location - About 2 hrs to fix
        src/__tests__/container.test.ts on lines 703..710

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

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

        function createInjectorProxy<T extends object>(
          container: AwilixContainer<T>,
          injector: InjectorFunction,
        ) {
          const locals = injector(container) as any
        Severity: Minor
        Found in src/resolvers.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

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

            const container = createContainer().register({
              test: asClass(Test, { injector }),
              testClassic: asClass(TestClassic, {
                injector,
                injectionMode: InjectionMode.CLASSIC,
        Severity: Major
        Found in src/__tests__/local-injections.test.ts and 1 other location - About 1 hr to fix
        src/__tests__/local-injections.test.ts on lines 64..71

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

        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 container = createContainer().register({
              test: asFunction(makeTest, { injector }),
              testClassic: asFunction(makeCLassicTest, {
                injector,
                injectionMode: InjectionMode.CLASSIC,
        Severity: Major
        Found in src/__tests__/local-injections.test.ts and 1 other location - About 1 hr to fix
        src/__tests__/local-injections.test.ts on lines 45..52

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

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

        function registerDescriptor<ESM extends boolean = false>(
          container: AwilixContainer,
          opts: LoadModulesOptions<ESM>,
          moduleDescriptor: LoadedModuleDescriptor & { value: any },
        ) {
        Severity: Minor
        Found in src/load-modules.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 createInjectorProxy has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function createInjectorProxy<T extends object>(
          container: AwilixContainer<T>,
          injector: InjectorFunction,
        ) {
          const locals = injector(container) as any
        Severity: Minor
        Found in src/resolvers.ts - About 1 hr to fix

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

            it('handles dots in module names', () => {
              const result = listModules('*.{ts,js}', { cwd: __dirname })
              expect(result.find((x) => x.name === 'container.test')).toBeDefined()
            })
          Severity: Major
          Found in src/__tests__/list-modules.test.ts and 2 other locations - About 1 hr to fix
          src/__tests__/list-modules.test.ts on lines 4..7
          src/__tests__/list-modules.test.ts on lines 9..12

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

          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('can find the modules in lib', () => {
              const result = listModules('../*.ts', { cwd: __dirname })
              expect(result.some((x) => x.name === 'container')).toBeTruthy()
            })
          Severity: Major
          Found in src/__tests__/list-modules.test.ts and 2 other locations - About 1 hr to fix
          src/__tests__/list-modules.test.ts on lines 9..12
          src/__tests__/list-modules.test.ts on lines 19..22

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

          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('replaces Windows path separators with Posix path separators', () => {
              const result = listModules('..\\*.ts', { cwd: __dirname })
              expect(result.some((x) => x.name === 'container')).toBeTruthy()
            })
          Severity: Major
          Found in src/__tests__/list-modules.test.ts and 2 other locations - About 1 hr to fix
          src/__tests__/list-modules.test.ts on lines 4..7
          src/__tests__/list-modules.test.ts on lines 19..22

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

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

          function generateResolve(fn: Function, dependencyParseTarget?: Function) {
            // If the function used for dependency parsing is falsy, use the supplied function
            if (!dependencyParseTarget) {
              dependencyParseTarget = fn
            }
          Severity: Minor
          Found in src/resolvers.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 parseLoadedModule has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function parseLoadedModule(
            loaded: any,
            m: ModuleDescriptor,
          ): Array<LoadedModuleDescriptor> {
            const items: Array<LoadedModuleDescriptor> = []
          Severity: Minor
          Found in src/load-modules.ts - About 1 hr to fix

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

              it('supports weird formatting', () => {
                expect(
                  parseParameterList(`function(  dep1    \n,\r\n  dep2 = 123 \r\n) {}`),
                ).toEqual([
                  { name: 'dep1', optional: false },
            Severity: Major
            Found in src/__tests__/param-parser.test.ts and 2 other locations - About 1 hr to fix
            src/__tests__/param-parser.test.ts on lines 56..69
            src/__tests__/param-parser.test.ts on lines 186..191

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

            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('supports regular functions with default params', () => {
                expect(
                  parseParameterList(
                    `function hello(
                      dep1 = 'frick off ricky',
            Severity: Major
            Found in src/__tests__/param-parser.test.ts and 2 other locations - About 1 hr to fix
            src/__tests__/param-parser.test.ts on lines 186..191
            src/__tests__/param-parser.test.ts on lines 193..200

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

            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