Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
complexity-report
Advanced tools
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.
sudo npm install -g complexity-report
cr [options] <file...>
-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
(beyond which, will cause the process to fail when exiting).-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.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.
var cr = require('complexity-report');
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
which may contain properties that modify
cyclomatic complexity calculation.
The following options are available:
logicalor
: Boolean indicating whether operator ||
should be considered a source of cyclomatic complexity,
defaults to true
.switchcase
: Boolean indicating whether switch
statements
should be considered a source of cyclomatic complexity,
defaults to true
.forin
: Boolean indicating whether for
...in
loops
should be considered a source of cyclomatic complexity,
defaults to false
.trycatch
: Boolean indicating whether catch
clauses
should be considered a source of cyclomatic complexity,
defaults to false
.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.
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, please raise an issue or, even better, implement it and submit a pull request! :)
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
.
The unit tests are in test/complexityReport.js
. You can run them with the
command npm test
or jake test
.
FAQs
Software complexity analysis for JavaScript projects
The npm package complexity-report receives a total of 2,254 weekly downloads. As such, complexity-report popularity was classified as popular.
We found that complexity-report demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.