deps/npm/lib/install.js

Summary

Maintainability
F
1 wk
Test Coverage

File install.js has 896 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// npm install <pkg> <pkg> <pkg>
//
// See doc/install.md for more description

// Managing contexts...
Severity: Major
Found in deps/npm/lib/install.js - About 2 days to fix

    Function install has 105 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function install (args, cb_) {
      var hasArguments = !!args.length
    
      function cb (er, installed) {
        if (er) return cb_(er)
    Severity: Major
    Found in deps/npm/lib/install.js - About 4 hrs to fix

      Function targetResolver has 97 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function targetResolver (where, context, deps, devDeps) {
        var alreadyInstalledManually = []
          , resolveLeft = 0
          , nm = path.resolve(where, "node_modules")
          , parent = context.parent
      Severity: Major
      Found in deps/npm/lib/install.js - About 3 hrs to fix

        Function targetResolver has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

        function targetResolver (where, context, deps, devDeps) {
          var alreadyInstalledManually = []
            , resolveLeft = 0
            , nm = path.resolve(where, "node_modules")
            , parent = context.parent
        Severity: Minor
        Found in deps/npm/lib/install.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 installMany has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function installMany (what, where, context, cb) {
          // readDependencies takes care of figuring out whether the list of
          // dependencies we'll iterate below comes from an existing shrinkwrap from a
          // parent level, a new shrinkwrap at this level, or package.json at this
          // level, as well as which shrinkwrap (if any) our dependencies should use.
        Severity: Major
        Found in deps/npm/lib/install.js - About 2 hrs to fix

          Function save has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function save (where, installed, tree, pretty, hasArguments, cb) {
            if (!hasArguments ||
                !npm.config.get("save") &&
                !npm.config.get("save-dev") &&
                !npm.config.get("save-optional") ||
          Severity: Major
          Found in deps/npm/lib/install.js - About 2 hrs to fix

            Function write has 68 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function write (target, targetFolder, context, cb_) {
              var up = npm.config.get("unsafe-perm")
                , user = up ? null : npm.config.get("user")
                , group = up ? null : npm.config.get("group")
                , family = context.family
            Severity: Major
            Found in deps/npm/lib/install.js - About 2 hrs to fix

              Function readDependencies has 67 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function readDependencies (context, where, opts, cb) {
                var wrap = context ? context.wrap : null
              
                var jsonPath = path.resolve(where, 'package.json')
                log.verbose('readDependencies', 'loading dependencies from', jsonPath)
              Severity: Major
              Found in deps/npm/lib/install.js - About 2 hrs to fix

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

                function findPeerInvalid_ (packageMap, fpiList) {
                  if (fpiList.indexOf(packageMap) !== -1)
                    return undefined
                
                  fpiList.push(packageMap)
                Severity: Minor
                Found in deps/npm/lib/install.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 resolver has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  return function resolver (what, cb) {
                    if (resolveLeft) return setTimeout(function () {
                      resolver(what, cb)
                    }, to++)
                
                
                Severity: Major
                Found in deps/npm/lib/install.js - About 2 hrs to fix

                  Function andBuildResolvedTree has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        function andBuildResolvedTree (er, current) {
                          if (er) return cb(er)
                  
                          // each target will be a data object corresponding
                          // to a package, folder, or whatever that is in the cache now.
                  Severity: Minor
                  Found in deps/npm/lib/install.js - About 2 hrs to fix

                    Function installOne_ has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function installOne_ (target, where, context, cb_) {
                      var nm = path.resolve(where, "node_modules")
                        , targetFolder = path.resolve(nm, target.name)
                        , prettyWhere = path.relative(process.cwd(), where)
                        , parent = context.parent
                    Severity: Minor
                    Found in deps/npm/lib/install.js - About 1 hr to fix

                      Function prettify has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function prettify (tree, installed) {
                        function red (set, kv) {
                          set[kv[0]] = kv[1]
                          return set
                        }
                      Severity: Minor
                      Found in deps/npm/lib/install.js - About 1 hr to fix

                        Function X has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            , function X (er) {
                              if (er) return cb(er)
                        
                              // before continuing to installing dependencies, check for a shrinkwrap.
                              var opt = { dev: npm.config.get("dev") }
                        Severity: Minor
                        Found in deps/npm/lib/install.js - About 1 hr to fix

                          Function completion has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          install.completion = function (opts, cb) {
                            // install can complete to a folder with a package.json, or any package.
                            // if it has a slash, then it's gotta be a folder
                            // if it starts with https?://, then just give up, because it's a url
                            if (/^https?:\/\//.test(opts.partialWord)) {
                          Severity: Minor
                          Found in deps/npm/lib/install.js - About 1 hr to fix

                            Function installManyTop_ has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function installManyTop_ (what, where, context, cb) {
                              var nm = path.resolve(where, "node_modules")
                            
                              fs.readdir(nm, function (er, pkgs) {
                                if (er) return installMany(what, where, context, cb)
                            Severity: Minor
                            Found in deps/npm/lib/install.js - About 1 hr to fix

                              Function readdir has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                function readdir(name) {
                                  resolveLeft++
                                  fs.readdir(name, function (er, inst) {
                                    if (er) return resolveLeft--
                              
                              
                              Severity: Minor
                              Found in deps/npm/lib/install.js - About 1 hr to fix

                                Function write has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function write (target, targetFolder, context, cb_) {
                                  var up = npm.config.get("unsafe-perm")
                                    , user = up ? null : npm.config.get("user")
                                    , group = up ? null : npm.config.get("group")
                                    , family = context.family
                                Severity: Minor
                                Found in deps/npm/lib/install.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

                                Function localLink has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function localLink (target, where, context, cb) {
                                  log.verbose("localLink", target._id)
                                  var jsonPath = path.resolve(npm.globalDir, target.name , 'package.json')
                                  var parent = context.parent
                                
                                
                                Severity: Minor
                                Found in deps/npm/lib/install.js - About 1 hr to fix

                                  Function save has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  function save (where, installed, tree, pretty, hasArguments, cb) {
                                  Severity: Minor
                                  Found in deps/npm/lib/install.js - About 45 mins to fix

                                    Consider simplifying this complex logical expression.
                                    Open

                                          if (!er &&
                                              data &&
                                              !context.explicit &&
                                              context.family[data.name] === data.version &&
                                              !npm.config.get("force") &&
                                    Severity: Major
                                    Found in deps/npm/lib/install.js - About 40 mins to fix

                                      Function prepareForInstallMany has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                      function prepareForInstallMany (packageData, depsKey, bundled, wrap, family) {
                                      Severity: Minor
                                      Found in deps/npm/lib/install.js - About 35 mins to fix

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

                                        install.completion = function (opts, cb) {
                                          // install can complete to a folder with a package.json, or any package.
                                          // if it has a slash, then it's gotta be a folder
                                          // if it starts with https?://, then just give up, because it's a url
                                          if (/^https?:\/\//.test(opts.partialWord)) {
                                        Severity: Minor
                                        Found in deps/npm/lib/install.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

                                        There are no issues that match your filters.

                                        Category
                                        Status