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

complan

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complan - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

reports/jhudson8/smocks/master/complexity-report.html

52

lib/generateReport.js

@@ -7,6 +7,11 @@ 'use strict'

module.exports = function (path, reportsPath, gitUrl) {
var complexityReport = {}
const jsonReport = JSON.parse(Fse.readFileSync(path, 'utf-8'))
let complexityReport = generateJsonReport(jsonReport, gitUrl, reportsPath)
generateHtmlReport(jsonReport, gitUrl, reportsPath)
Fse.removeSync(Path.join(process.cwd(), 'cc.json'))
return complexityReport
}
function generateJsonReport (jsonReport, gitUrl, reportsPath) {
let complexityReport = {}
complexityReport.cyclomatic = +(jsonReport.cyclomatic.toFixed(2))

@@ -27,5 +32,44 @@ complexityReport.loc = +(jsonReport.loc.toFixed(2))

Fse.writeFileSync(Path.join(reportsPath, 'complexity-report.json'), JSON.stringify(complexityReport, null, 3))
console.log('Successfully wrote report at: ' + Path.join(reportsPath, 'complexity-report.json'))
Fse.removeSync(Path.join(process.cwd(), 'cc.json'))
console.log('Successfully wrote JSON and HTML reports under ' + reportsPath)
return complexityReport
}
function generateHtmlReport (jsonReport, gitUrl, reportsPath) {
let complexityReport = {}
complexityReport.cyclomatic = +(jsonReport.cyclomatic.toFixed(2))
complexityReport.loc = +(jsonReport.loc.toFixed(2))
complexityReport.maintainability = +(jsonReport.maintainability.toFixed(2))
complexityReport.report = []
jsonReport.reports.forEach(function (report) {
let rep = {}
rep.path = Util.getGitPath(gitUrl, report.path)
rep.localPath = Util.getFileName(gitUrl, report.path)
rep.cyclomatic = +(report.cyclomatic.toFixed(2))
rep.loc = report.aggregate.sloc.physical
rep.avglocPerMethod = +(report.loc.toFixed(2))
rep.maintainability = +(report.maintainability.toFixed(2))
complexityReport.report.push(rep)
})
let html = '<html><body><table border=\'1\'>'
html += '<tr bgcolor="#DCDCDC">' +
'<th>Path</th>' +
'<th>Cyclomatic<br> Complexity</th>' +
'<th>Lines Of<br> Code</th>' +
'<th>Avg LOC<br> Per Method</th>' +
'<th>Maintainability</th></tr>'
complexityReport.report.forEach(function (report) {
html += '<tr bgcolor=\'#F8F8FF\'>'
html += ('<td><a href=' + report.path + '>' + report.localPath + '</a></td>')
html += ('<td>' + report.cyclomatic + '</td>')
html += ('<td>' + report.loc + '</td>')
html += ('<td>' + report.avglocPerMethod + '</td>')
html += ('<td>' + report.maintainability + '</td>')
html += ('<tr>')
})
html += '</table></body>'
Fse.writeFileSync(Path.join(reportsPath, 'complexity-report.html'), html)
}

13

lib/util.js

@@ -30,4 +30,3 @@ 'use strict'

getGitPath: function (gitUrl, localPath) {
const pathToReplace = Path.join(process.cwd(), 'clonedrepos', GitUrlParse(gitUrl).pathname)
const fileName = localPath.replace(pathToReplace, '')
const fileName = this.getFileName(gitUrl, localPath)
const git = GitUrlParse(gitUrl)

@@ -37,6 +36,12 @@ const hash = (git.hash === '' ? 'master' : git.hash)

const lastIndexOfGit = pathname.lastIndexOf('.git')
pathname = pathname.slice(0, lastIndexOfGit)
if (lastIndexOfGit > 0) {
pathname = pathname.slice(0, lastIndexOfGit)
}
return 'https://' + git.resource + pathname + '/blob/' + hash + fileName
},
return 'https://' + git.resource + pathname + '/blob/' + hash + fileName
getFileName: function (gitUrl, localPath) {
const pathToReplace = Path.join(process.cwd(), 'clonedrepos', GitUrlParse(gitUrl).pathname)
return localPath.replace(pathToReplace, '')
}
}
{
"name": "complan",
"version": "1.0.7",
"version": "1.0.8",
"description": "COMPLexity ANalyzer Tool For Javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -44,5 +44,5 @@ # Complan

```
The above command will generate complexity report under a directory named ```pranavparikh/complan``` in your current directory.
The above command will generate complexity report (JSON and HTML files) under a directory named ```pranavparikh/complan``` in your current directory.
The tool will locally clone the repository from git (Git has to be installed as a pre-requisite) , compute complexity and output it in a form of JSON report.
The tool will locally clone the repository from git (Git has to be installed as a pre-requisite) , compute complexity and output it in a form of JSON & HTML reports.

@@ -54,2 +54,3 @@ ### Command-line options

-g, --gitUrl <path> specify the http url or the git url of the repository
-c, --gitCheckout Branch / tag / checkout of the git project (Defaults to master)
```

@@ -56,0 +57,0 @@ ## License

Sorry, the diff of this file is not supported yet

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