Galooshi/import-js

View on GitHub
lib/findExports.js

Summary

Maintainability
D
2 days
Test Coverage
A
98%

File findExports.js has 354 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import fs from 'fs';
import path from 'path';

import requireRelative from 'require-relative';

Severity: Minor
Found in lib/findExports.js - About 4 hrs to fix

    Function findCommonJSExports has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    function findCommonJSExports(
      node,
      { definedNames, absolutePathToFile, aliasesForExports },
    ) {
      if (node.type !== 'ExpressionStatement') {
    Severity: Minor
    Found in lib/findExports.js - About 2 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 findExports has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export default function findExports(data, absolutePathToFile) {
      if (/\.json$/.test(absolutePathToFile)) {
        return {
          named: Object.keys(JSON.parse(data)),
          typed: [],
    Severity: Minor
    Found in lib/findExports.js - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

        if (
          node.expression.type === 'CallExpression' &&
          node.expression.callee.type === 'MemberExpression' &&
          node.expression.callee.object.name === 'Object' &&
          node.expression.callee.property.name === 'defineProperty' &&
      Severity: Critical
      Found in lib/findExports.js - About 1 hr to fix

        Function resolveNestedNamedExports has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function resolveNestedNamedExports(node, absolutePathToFile) {
          if (node.type === 'ConditionalExpression') {
            // Potential ternary-style export - we pick the first one
            // module.exports = foo ? require('a') : require('b');
            return resolveNestedNamedExports(node.consequent, absolutePathToFile);
        Severity: Minor
        Found in lib/findExports.js - About 1 hr to fix

          Function findDefinedNames has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          function findDefinedNames(node, definedNames) {
            if (node.type === 'ExpressionStatement') {
              const { left, right } = node.expression;
              if (left && right) {
                if (left.object) {
          Severity: Minor
          Found in lib/findExports.js - About 45 mins 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

          Consider simplifying this complex logical expression.
          Open

            if (
              node.expression.type === 'CallExpression' &&
              node.expression.callee.type === 'MemberExpression' &&
              aliasesForExports.has(node.expression.callee.object.name) &&
              node.expression.callee.property.name === 'use' &&
          Severity: Major
          Found in lib/findExports.js - About 40 mins to fix

            Function findESNamedExports has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            function findESNamedExports(node, { absolutePathToFile }) {
              if (node.type === 'ExportAllDeclaration') {
                // Recurse the file referenced by the declaration
                // eslint-disable-next-line no-use-before-define
                return resolveNestedNamedExports(node, absolutePathToFile);
            Severity: Minor
            Found in lib/findExports.js - About 35 mins 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 too many return statements within this function.
            Open

                  return definedNames[right.name] || [];
            Severity: Major
            Found in lib/findExports.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return left.object.name === 'module' && left.property.name === 'exports';
              Severity: Major
              Found in lib/findExports.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return [];
                Severity: Major
                Found in lib/findExports.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return false;
                  Severity: Major
                  Found in lib/findExports.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return result;
                    Severity: Major
                    Found in lib/findExports.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return nestedNamed;
                      Severity: Major
                      Found in lib/findExports.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return [left.property.name];
                        Severity: Major
                        Found in lib/findExports.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return [left.property.name];
                          Severity: Major
                          Found in lib/findExports.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return right.properties.map(({ key }) => key.name).filter(Boolean);
                            Severity: Major
                            Found in lib/findExports.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                  return result;
                              Severity: Major
                              Found in lib/findExports.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                    return [node.declaration.id.name];
                                Severity: Major
                                Found in lib/findExports.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                    return [];
                                  Severity: Major
                                  Found in lib/findExports.js - About 30 mins to fix

                                    There are no issues that match your filters.

                                    Category
                                    Status