New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

complexity-report

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complexity-report - npm Package Compare versions

Comparing version 0.10.2 to 0.10.3

26

Jakefile.js

@@ -17,3 +17,3 @@ /*jshint nomen:false */

task('test', function () {
runTask(test, 'Testing...');
runCommand('test', 'Testing...');
}, {

@@ -25,3 +25,3 @@ async: true

task('lint', function () {
runTask(lint, 'Linting...');
runCommand('lint', 'Linting...');
}, {

@@ -33,3 +33,3 @@ async: true

task('prepare', function () {
runTask(prepare, 'Preparing the build environment...');
runCommand('prepare', 'Preparing the build environment...');
}, {

@@ -39,21 +39,5 @@ async: true

function runTask (operation, message) {
function runCommand (command, message) {
console.log(message);
operation();
}
function test () {
runCommand(commands.test);
}
function lint () {
runCommand(commands.lint);
}
function prepare () {
runCommand(commands.prepare);
}
function runCommand (command) {
exec(command, { cwd: __dirname }, function (error, stdout, stderr) {
exec(commands[command], { cwd: __dirname }, function (error, stdout, stderr) {
console.log(stdout);

@@ -60,0 +44,0 @@ console.log(stderr);

10

package.json
{
"name": "complexity-report",
"version": "0.10.2",
"version": "0.10.3",
"author": "Phil Booth <pmbooth@gmail.com>",

@@ -33,3 +33,3 @@ "description": "A tool for reporting code complexity metrics in JavaScript projects.",

"dependencies": {
"check-types": "0.3.x",
"check-types": "0.6.x",
"esprima": "1.0.x",

@@ -40,5 +40,5 @@ "commander": "1.1.x"

"jake": "0.5.x",
"jshint": "0.9.x",
"mocha": "1.8.x",
"chai": "1.4.x"
"jshint": "1.1.x",
"mocha": "1.9.x",
"chai": "1.6.x"
},

@@ -45,0 +45,0 @@ "license": "MIT",

@@ -9,2 +9,3 @@ # complexityReport.js

* lines of code;
* number of parameters;
* cyclomatic complexity;

@@ -100,3 +101,5 @@ * Halstead metrics;

a second attempt will be made to load the module
without the subdirectory prefix.
without the subdirectory prefix,
more easily enabling the use of
custom formats if they are required.
Adding new formats is really easy;

@@ -103,0 +106,0 @@ each format module must export a function `format`,

#!/usr/bin/env node
/*globals require, process, console, setTimeout */
/*globals require, process, console, setImmediate */

@@ -162,3 +162,3 @@ 'use strict';

if (isOpenFileLimitReached()) {
runOnNextTick(function () {
setImmediate(function () {
conditionallyReadFile(filePath);

@@ -195,6 +195,2 @@ });

function runOnNextTick (fn) {
setTimeout(fn, 0);
}
function error (functionName, err) {

@@ -201,0 +197,0 @@ fail('Fatal error [' + functionName + ']: ' + err.message);

@@ -67,3 +67,3 @@ /**

return {
aggregate: createFunctionReport(undefined, lines),
aggregate: createFunctionReport(undefined, lines, 0),
functions: []

@@ -73,3 +73,3 @@ };

function createFunctionReport (name, lines) {
function createFunctionReport (name, lines, params) {
return {

@@ -84,3 +84,4 @@ name: name,

cyclomatic: 1,
halstead: createInitialHalsteadState()
halstead: createInitialHalsteadState(),
params: params
}

@@ -106,9 +107,7 @@ };

function processTree (tree, assignedName, currentReport) {
var i;
check.verifyArray(tree, 'Invalid syntax tree');
for (i = 0; i < tree.length; i += 1) {
processNode(tree[i], assignedName, currentReport);
}
tree.forEach(function (node) {
processNode(node, assignedName, currentReport);
});
}

@@ -180,19 +179,18 @@

function processHalsteadMetric (node, metric, currentReport) {
var syntax = syntaxes[node.type], i, identifier;
var syntax = syntaxes[node.type];
if (check.isArray(syntax[metric])) {
for (i = 0; i < syntax[metric].length; i += 1) {
if (check.isFunction(syntax[metric][i].identifier)) {
identifier = syntax[metric][i].identifier(node);
syntax[metric].forEach(function (s) {
var identifier;
if (check.isFunction(s.identifier)) {
identifier = s.identifier(node);
} else {
identifier = syntax[metric][i].identifier;
identifier = s.identifier;
}
if (
check.isFunction(syntax[metric][i].filter) === false ||
syntax[metric][i].filter(node) === true
) {
if (check.isFunction(s.filter) === false || s.filter(node) === true) {
halsteadItemEncountered(currentReport, metric, identifier);
}
}
});
}

@@ -243,5 +241,6 @@ }

function processChildrenInNewScope (node, assignedName) {
var newReport = createFunctionReport(safeName(node.id, assignedName), node.loc);
var newReport = createFunctionReport(safeName(node.id, assignedName), node.loc, node.params.length);
report.functions.push(newReport);
report.aggregate.complexity.params += node.params.length;

@@ -252,12 +251,12 @@ processChildren(node, newReport);

function processChildren (node, currentReport) {
var syntax = syntaxes[node.type], i;
var syntax = syntaxes[node.type];
if (check.isArray(syntax.children)) {
for (i = 0; i < syntax.children.length; i += 1) {
syntax.children.forEach(function (child) {
processChild(
node[syntax.children[i]],
node[child],
check.isFunction(syntax.assignableName) ? syntax.assignableName(node) : '',
currentReport
);
}
});
}

@@ -274,3 +273,3 @@ }

sums = [ 0, 0, 0 ],
sums = [ 0, 0, 0, 0 ],

@@ -280,3 +279,4 @@ indices = {

complexity: 1,
effort: 2
effort: 2,
params: 3
};

@@ -306,2 +306,4 @@

);
report.params = averages[indices.params];
}

@@ -339,2 +341,3 @@

sums[indices.effort] += data.halstead.effort;
sums[indices.params] += data.params;
}

@@ -341,0 +344,0 @@

@@ -19,7 +19,8 @@ /*globals exports */

return [
'##',
'## ',
report.module,
'\n\n',
'* Maintainability index: ', report.maintainability, '\n',
'* Aggregate cyclomatic complexity: ', report.aggregate.complexity.cyclomatic,
'* Aggregate cyclomatic complexity: ', report.aggregate.complexity.cyclomatic, '\n',
'* Mean parameter count: ', report.params,
formatFunctions(report.functions)

@@ -41,12 +42,13 @@ ].join('');

return [
' * Function: **', report.name.replace('<', '&lt;'), '**\n',
' * Line No.: ', report.line, '\n',
' * Physical SLOC: ', report.complexity.sloc.physical, '\n',
' * Logical SLOC: ', report.complexity.sloc.logical, '\n',
' * Cyclomatic complexity: ', report.complexity.cyclomatic, '\n',
' * Halstead difficulty: ', report.complexity.halstead.difficulty, '\n',
' * Halstead volume: ', report.complexity.halstead.volume, '\n',
' * Halstead effort: ', report.complexity.halstead.effort
'* Function: **', report.name.replace('<', '&lt;'), '**\n',
' * Line No.: ', report.line, '\n',
' * Physical SLOC: ', report.complexity.sloc.physical, '\n',
' * Logical SLOC: ', report.complexity.sloc.logical, '\n',
' * Parameter count: ', report.complexity.params, '\n',
' * Cyclomatic complexity: ', report.complexity.cyclomatic, '\n',
' * Halstead difficulty: ', report.complexity.halstead.difficulty, '\n',
' * Halstead volume: ', report.complexity.halstead.volume, '\n',
' * Halstead effort: ', report.complexity.halstead.effort
].join('');
}

@@ -22,3 +22,4 @@ /*globals exports */

' Maintainability index: ', report.maintainability, '\n',
' Aggregate cyclomatic complexity: ', report.aggregate.complexity.cyclomatic,
' Aggregate cyclomatic complexity: ', report.aggregate.complexity.cyclomatic, '\n',
' Mean parameter count: ', report.params,
formatFunctions(report.functions)

@@ -44,2 +45,3 @@ ].join('');

' Logical SLOC: ', report.complexity.sloc.logical, '\n',
' Parameter count: ', report.complexity.params, '\n',
' Cyclomatic complexity: ', report.complexity.cyclomatic, '\n',

@@ -46,0 +48,0 @@ ' Halstead difficulty: ', report.complexity.halstead.difficulty, '\n',

@@ -35,3 +35,3 @@ /*globals exports */

var i, functions = '', nextIndentation = incrementIndentation(indentation);
for (i = 0; i < report.functions.length; i += 1) {

@@ -72,2 +72,3 @@ functions += formatFunction(nextIndentation, report.functions[i]);

formatSlocComplexity(nextIndentation, data.sloc) +
formatParameterComplexity(nextIndentation, data.params) +
formatCyclomaticComplexity(nextIndentation, data.cyclomatic) +

@@ -90,2 +91,6 @@ formatHalsteadComplexity(nextIndentation, data.halstead)

function formatParameterComplexity (indentation, data) {
return createElement(indentation, 'parameters', false, data);
}
function formatCyclomaticComplexity (indentation, data) {

@@ -92,0 +97,0 @@ return createElement(indentation, 'cyclomatic', false, data);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc