Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

solidity-code-metrics

ConsenSys839MIT0.0.28

Solidity Code Metrics

solidity, code, metrics, complexity, risk, capabilities

readme

get in touch with Consensys Diligence
[ 🌐 📩 🔥 ]

Solidity Code Metrics

🌐 npm install solidity-code-metrics

The number-crunching enginge behind 📊tintinweb.solidity-metrics.

vscode-solidity-metrics3

Example

CLI

To use the CLI from the compiled sources you can do:

node ./src/cli.js <path to solidity file(s)>

It is however more useful to install solidity-metrics globally and call it from any directory:

npm install -g solidity-code-metrics
solidity-code-metrics myfile1.sol myfile2.sol

By default, the cli outputs to the console, you can however store the output in a file rather easily (both markdown and html are supported):

solidity-code-metrics myfile.sol > metrics.md
solidity-code-metrics myfile.sol --html > metrics.html

Library


const {SolidityMetricsContainer} = require('solidity-metrics');

let options = {
    basePath:"",
    inputFileGlobExclusions:undefined,
    inputFileGlob: undefined,
    inputFileGlobLimit: undefined,
    debug:false,
    repoInfo: {
        branch: undefined,
        commit: undefined,
        remote: undefined
    }    
}

let metrics = new SolidityMetricsContainer("metricsContainerName", options);


// analyze files
metrics.analyze(path_to_solidity_file);
// ...
metrics.analyze(path_to_solidity_file_N);

// output
console.log(metrics.totals());
metrics.generateReportMarkdown().then(text => console.log(text));
// or let text = await metrics.generateReportMarkdown();

changelog

Change Log

All notable changes to "solidity-code-metrics" will be documented in this file.

v0.0.27

  • new: fix exception when scoping non logic contracts - #20
  • update: dependencies

v0.0.26

  • new: show deployable contracts - #19
  • new: users can provide a scope file - #17

v0.0.23

  • fixes: crhome rendering issues - #10
  • fixes: invalid table markdown - #7
  • update: dependencies

v0.0.22

  • new: CLI glob resolve provided paths
  • update: dependencies

v0.0.21

  • new: CLI option --html - generates a standalone html report (default markdown)

v0.0.20

  • new: added solidity-code-metrics command
  • new: updated solidity-parser, solidity-doppelganger

v0.0.19

  • new: metrics for tryCatch and unchecked blocks

v0.0.18

  • update: updated solidity doppelganger/regenerate patterns

v0.0.17

  • update: solidity parser to 0.13.2

v0.0.16

  • update: doppelganger to 0.0.5 (updating parser)
  • new: metric: external dependencies - lists all external imports.
    • imports may be an indicator of the capabilities and code-patterns used in a contract system.

image

v0.0.15

  • update: surya to 0.4.2

v0.0.14

  • fix: IMPORTANT nSLOC metric in the table displayed all normalized source lines (including comments, blank lines) instead of normalized source code lines only. This has been changed with this release. nSLOC now displays normalized source-code lines (no comments, blank lines). The new column nLines now displays the value that was formerly displayed for nSLOC. - #3

v0.0.13

  • fix: add option to disable solidity doppelganger (e.g. for in-browser use of solidity-metrics) - #2

v0.0.12

  • new: support abstract contracts

v0.0.11

  • update: solidity-doppelganger to v0.0.4

v0.0.8 - v0.0.10

  • updated: surya, solidity parser
  • new: solidity-doppelganger detection

v0.0.7

  • updated: surya to 0.4.1-dev.2

v0.0.6

  • new: support for solidity 0.6.x
  • updated: surya to 0.4.0 #49
  • updated: solidity-parser-diligence to community maintained @solidity-parser/parser #53

v0.0.1 - 0.0.4

  • first alpha