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

A tool for reporting code complexity metrics in JavaScript projects.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
decreased by-5.74%
Maintainers
1
Weekly downloads
 
Created
Source

complexityReport.js

A tool for reporting code complexity metrics in JavaScript projects (still in development).

The metrics are calculated by walking syntax trees generated by the Esprima parser.

Build status

Installation

npm install complexity-report

Usage

From the command line

cr [options] <file...>
Options
  • -o <file>: Specify an output file for the report.
  • -f <format: Specify an output format for the report.
  • -t <threshold>: Specify the per-function complexity threshold.
  • -l: Disregads operator || as a source of cyclomatic complexity.
  • -s: Disegards switch statements as a source of cyclomatic complexity.
  • -i: Treats for...in loops as a source of cyclomatic complexity.
  • -c: Treats catch clauses as a source of cyclomatic complexity.
Output formats

These are loaded with require from the src/formats subdirectory. Adding new formats is easy, each module must export a function format that takes a report object as its only argument and returns a string representation of the report. See src/formats/plain.js for an example format.

From code

Loading the library
var cr = require('complexity-report');
Calling the library
var report = cr.run(source, options);

The argument source must be a string containing the source code that is to be analysed. The argument options is an optional object that can be used to modify the default settings for cyclomatic complexity calculation. The following options are available:

  • logicalor: Disregads operator || as a source of cyclomatic complexity.
  • switchcase: Disegards switch statements as a source of cyclomatic complexity.
  • forin: Treats for...in loops as a source of cyclomatic complexity.
  • trycatch: Treats catch clauses as a source of cyclomatic complexity.

The returned report is an object that contains properties detailing the complexity of each function from the source code. There is also an aggregate complexity score for the source in its entirety.

Development

Roadmap

The current plan is to add Halstead complexity measures and then just focus on improving the calculations by throwing more and more test cases together. If you think there's anything else I should look at, raise an issue or, even better, implement it and submit a pull request! :)

Dependencies

The build environment relies on Node.js, NPM, Jake, JSHint, Mocha, Chai and UglifyJS. Assuming that you already have Node.js and NPM set up, you just need to run npm install to install all of the dependencies as listed in package.json.

Unit tests

The unit tests are in test/complexityReport.js. You can run them with the command npm test or jake test.

Keywords

FAQs

Package last updated on 28 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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