deps/npm/lib/view.js

Summary

Maintainability
D
2 days
Test Coverage

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

function search (data, fields, version, title) {
  var field
    , tail = fields
  while (!field && fields.length) field = tail.shift()
  fields = [field].concat(tail)
Severity: Minor
Found in deps/npm/lib/view.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

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

// npm view [pkg [pkg ...]]

module.exports = view
view.usage = "npm view pkg[@version] [<field>[.subfield]...]"

Severity: Minor
Found in deps/npm/lib/view.js - About 2 hrs to fix

    Function cleanup has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    function cleanup (data) {
      if (Array.isArray(data)) {
        if (data.length === 1) {
          data = data[0]
        } else {
    Severity: Minor
    Found in deps/npm/lib/view.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 search has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function search (data, fields, version, title) {
      var field
        , tail = fields
      while (!field && fields.length) field = tail.shift()
      fields = [field].concat(tail)
    Severity: Minor
    Found in deps/npm/lib/view.js - About 1 hr to fix

      Function fetchAndRead has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function fetchAndRead (nv, args, silent, cb) {
        // get the data about this package
        var name = nv.name
          , version = nv.rawSpec || npm.config.get("tag")
      
      
      Severity: Minor
      Found in deps/npm/lib/view.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

          if (keys.length <= 3
              && data.name
              && (keys.length === 1
                  || keys.length === 3 && data.email && data.url
                  || keys.length === 2 && (data.email || data.url))) {
        Severity: Critical
        Found in deps/npm/lib/view.js - About 1 hr to fix

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

          view.completion = function (opts, cb) {
            if (opts.conf.argv.remain.length <= 2) {
              // FIXME: there used to be registry completion here, but it stopped making
              // sense somewhere around 50,000 packages on the registry
              return cb()
          Severity: Minor
          Found in deps/npm/lib/view.js - About 1 hr to fix

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

            function cleanup (data) {
              if (Array.isArray(data)) {
                if (data.length === 1) {
                  data = data[0]
                } else {
            Severity: Minor
            Found in deps/npm/lib/view.js - About 1 hr to fix

              Avoid too many return statements within this function.
              Open

                    return new Error("Not an object: "+data)
              Severity: Major
              Found in deps/npm/lib/view.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  return o
                Severity: Major
                Found in deps/npm/lib/view.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return search(data, tail, version, title)
                  Severity: Major
                  Found in deps/npm/lib/view.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      if (!data.hasOwnProperty(field)) return undefined
                    Severity: Major
                    Found in deps/npm/lib/view.js - About 30 mins to fix

                      Function view has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function view (args, silent, cb) {
                        if (typeof cb !== "function") cb = silent, silent = false
                      
                        if (!args.length) args = ["."]
                      
                      
                      Severity: Minor
                      Found in deps/npm/lib/view.js - About 25 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