packages/babel-helper-module-imports/src/import-injector.js

Summary

Maintainability
F
4 days
Test Coverage

Function _generateImport has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring.
Open

  _generateImport(opts, importName) {
    const isDefault = importName === "default";
    const isNamed = !!importName && !isDefault;
    const isNamespace = importName === null;

Severity: Minor
Found in packages/babel-helper-module-imports/src/import-injector.js - About 2 days 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 _generateImport has 162 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  _generateImport(opts, importName) {
    const isDefault = importName === "default";
    const isNamed = !!importName && !isDefault;
    const isNamespace = importName === null;

Severity: Major
Found in packages/babel-helper-module-imports/src/import-injector.js - About 6 hrs to fix

    File import-injector.js has 256 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import assert from "assert";
    import * as t from "@babel/types";
    
    import ImportBuilder from "./import-builder";
    import isModule from "./is-module";
    Severity: Minor
    Found in packages/babel-helper-module-imports/src/import-injector.js - About 2 hrs to fix

      Function _applyDefaults has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        _applyDefaults(importedSource, opts, isInit = false) {
          const optsList = [];
          if (typeof importedSource === "string") {
            optsList.push({ importedSource });
            optsList.push(opts);
      Severity: Minor
      Found in packages/babel-helper-module-imports/src/import-injector.js - 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

      Avoid deeply nested control flow statements.
      Open

            if (isDefault && ensureLiveReference) {
              throw new Error("No live reference for commonjs default");
            }
      Severity: Major
      Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                if (isNamespace) {
                  builder.default(name || importedSource);
                } else if (isDefault || isNamed) {
                  builder.default(importedSource).read(name);
                }
        Severity: Major
        Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                  if (isNamespace) {
                    builder.namespace(name || importedSource);
                  } else if (isDefault || isNamed) {
                    builder.named(name, importName);
                  }
          Severity: Major
          Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    } else if (isNamed) {
                      builder.default(es6Default).read(importName);
                    }
            Severity: Major
            Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if (ensureLiveReference) {
                          builder
                            .default(es6Default)
                            .var(name || importedSource)
                            .defaultInterop()
              Severity: Major
              Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                      } else if (isModuleForBabel) {
                        // import * as namespace from ''; namespace
                        // import def from ''; def
                        // import { named } from ''; named
                        // Note: These lookups will break if the module has no __esModule set,
                Severity: Major
                Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if (isNamespace) {
                            builder.var(name || importedSource).wildcardInterop();
                          } else if ((isDefault || isNamed) && ensureLiveReference) {
                            if (isDefault) {
                              name = name !== "default" ? name : importedSource;
                  Severity: Major
                  Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                          if (isModuleForNode) {
                            // import namespace from ''; namespace
                            // import def from ''; def;
                            // import namespace from ''; namespace.named
                            builder.import();
                    Severity: Major
                    Found in packages/babel-helper-module-imports/src/import-injector.js - About 45 mins to fix

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

                              } else if (isNamed) {
                                if (ensureLiveReference) {
                                  builder.var(importedSource).read(name);
                                } else {
                                  builder.var(name).prop(importName);
                      Severity: Minor
                      Found in packages/babel-helper-module-imports/src/import-injector.js and 1 other location - About 55 mins to fix
                      packages/babel-helper-module-imports/src/import-injector.js on lines 335..341

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

                      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

                              } else if (isDefault || isNamed) {
                                if (ensureLiveReference) {
                                  builder.var(importedSource).read(name);
                                } else {
                                  builder.prop(importName).var(name);
                      Severity: Minor
                      Found in packages/babel-helper-module-imports/src/import-injector.js and 1 other location - About 55 mins to fix
                      packages/babel-helper-module-imports/src/import-injector.js on lines 386..392

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

                      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

                              if (isNamespace) {
                                builder.namespace(name || importedSource);
                              } else if (isDefault || isNamed) {
                                builder.named(name, importName);
                              }
                      Severity: Minor
                      Found in packages/babel-helper-module-imports/src/import-injector.js and 2 other locations - About 35 mins to fix
                      packages/babel-helper-module-imports/src/import-injector.js on lines 233..237
                      packages/babel-helper-module-imports/src/import-injector.js on lines 276..280

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

                      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

                            if (isNamespace) {
                              builder.namespace(nameHint || importedSource);
                            } else if (isDefault || isNamed) {
                              builder.named(name, importName);
                            }
                      Severity: Minor
                      Found in packages/babel-helper-module-imports/src/import-injector.js and 2 other locations - About 35 mins to fix
                      packages/babel-helper-module-imports/src/import-injector.js on lines 276..280
                      packages/babel-helper-module-imports/src/import-injector.js on lines 322..326

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

                      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

                              if (isNamespace) {
                                builder.namespace(name || importedSource);
                              } else if (isDefault || isNamed) {
                                builder.named(name, importName);
                              }
                      Severity: Minor
                      Found in packages/babel-helper-module-imports/src/import-injector.js and 2 other locations - About 35 mins to fix
                      packages/babel-helper-module-imports/src/import-injector.js on lines 233..237
                      packages/babel-helper-module-imports/src/import-injector.js on lines 322..326

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

                      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

                      There are no issues that match your filters.

                      Category
                      Status