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)
- Read upRead up
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]...]"
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 {
- Read upRead up
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)
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")
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))) {
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()
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 {
Avoid too many return
statements within this function. Open
return new Error("Not an object: "+data)
Avoid too many return
statements within this function. Open
return o
Avoid too many return
statements within this function. Open
return search(data, tail, version, title)
Avoid too many return
statements within this function. Open
if (!data.hasOwnProperty(field)) return undefined
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 = ["."]
- Read upRead up
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"