Skip to content

Commit

Permalink
Merge pull request #3 from ConsenSys/fix/nsloc_metric
Browse files Browse the repository at this point in the history
fix nSLOC not displaying sloc but all source lines
  • Loading branch information
tintinweb authored Jan 5, 2021
2 parents 02f7754 + 984de55 commit f8a28d7
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 24 deletions.
125 changes: 106 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-code-metrics",
"version": "0.0.13",
"version": "0.0.14",
"description": "Solidity Code Metrics",
"main": "src/index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/ConsenSys/solidity-metrics#readme",
"dependencies": {
"@solidity-parser/parser": "^0.8.2",
"@solidity-parser/parser": "^0.11.0",
"sloc": "^0.2.1",
"solidity-doppelganger": "0.0.4",
"surya": "^0.4.1"
Expand Down
22 changes: 19 additions & 3 deletions src/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,26 @@ This section lists files that are in scope for the metrics report.
Source Units Analyzed: **\`${this.seenFiles.length}\`**<br>
Source Units in Scope: **\`${this.metrics.length}\`** (**${Math.round(this.metrics.length/this.seenFiles.length * 100)}%**)
| Type | File | Logic Contracts | Interfaces | Lines | nSLOC | Comment Lines | Complex. Score | Capabilities |
| Type | File | Logic Contracts | Interfaces | Lines | nLines | nSLOC | Comment Lines | Complex. Score | Capabilities |
|========|=================|============|=======|=======|===============|==============|
${this.metrics.map(m => `| ${m.metrics.num.contracts ? "๐Ÿ“" : ""}${m.metrics.num.libraries ? "๐Ÿ“š" : ""}${m.metrics.num.interfaces ? "๐Ÿ”" : ""}${m.metrics.num.abstract ? "๐ŸŽจ" : ""} | ${m.filename.replace(this.basePath, "")} | ${(m.metrics.num.contracts + m.metrics.num.libraries + m.metrics.num.abstract) || "****"} | ${m.metrics.num.interfaces || "****"} | ${m.metrics.sloc.total || "****"} | ${m.metrics.nsloc.total || "****"} | ${m.metrics.sloc.comment || "****"} | ${m.metrics.complexity.perceivedNaiveScore || "****"} | **${m.metrics.capabilities.assembly ? "<abbr title='Uses Assembly'>๐Ÿ–ฅ</abbr>":""}${m.metrics.capabilities.experimental.length ? "<abbr title='Experimental Features'>๐Ÿงช</abbr>":""}${m.metrics.capabilities.canReceiveFunds ? "<abbr title='Payable Functions'>๐Ÿ’ฐ</abbr>":""}${m.metrics.capabilities.destroyable ? "<abbr title='Destroyable Contract'>๐Ÿ’ฃ</abbr>":""}${m.metrics.capabilities.explicitValueTransfer ? "<abbr title='Initiates ETH Value Transfer'>๐Ÿ“ค</abbr>":""}${m.metrics.capabilities.lowLevelCall ? "<abbr title='Performs Low-Level Calls'>โšก</abbr>":""}${m.metrics.capabilities.delegateCall ? "<abbr title='DelegateCall'>๐Ÿ‘ฅ</abbr>":""}${m.metrics.capabilities.hashFuncs ? "<abbr title='Uses Hash-Functions'>๐Ÿงฎ</abbr>":""}${m.metrics.capabilities.ecrecover ? "<abbr title='Handles Signatures: ecrecover'>๐Ÿ”–</abbr>":""}${m.metrics.capabilities.deploysContract ? "<abbr title='create/create2'>๐ŸŒ€</abbr>":""}${(doppelGanger !== undefined) && pathToDoppelganger && pathToDoppelganger[m.filename.replace(this.basePath, "")] ? "<abbr title='doppelganger("+pathToDoppelganger[m.filename.replace(this.basePath, "")].map(r => r.target.name).join(", ")+")'>๐Ÿ”†</abbr>":""}** |`).join("\n")}
| ${totals.totals.num.contracts ? "๐Ÿ“" : ""}${totals.totals.num.libraries ? "๐Ÿ“š" : ""}${totals.totals.num.interfaces ? "๐Ÿ”" : ""}${totals.totals.num.abstract ? "๐ŸŽจ" : ""} | **Totals** | **${(totals.totals.num.contracts + totals.totals.num.libraries + totals.totals.num.abstract) || ""}** | **${totals.totals.num.interfaces || ""}** | **${totals.totals.sloc.total}** | **${totals.totals.nsloc.total}** | **${totals.totals.sloc.comment}** | **${totals.totals.complexity.perceivedNaiveScore}** | **${totals.totals.capabilities.assembly ? "<abbr title='Uses Assembly'>๐Ÿ–ฅ</abbr>":""}${totals.totals.capabilities.experimental.length ? "<abbr title='Experimental Features'>๐Ÿงช</abbr>":""}${totals.totals.capabilities.canReceiveFunds ? "<abbr title='Payable Functions'>๐Ÿ’ฐ</abbr>":""}${totals.totals.capabilities.destroyable ? "<abbr title='Destroyable Contract'>๐Ÿ’ฃ</abbr>":""}${totals.totals.capabilities.explicitValueTransfer ? "<abbr title='Initiates ETH Value Transfer'>๐Ÿ“ค</abbr>":""}${totals.totals.capabilities.lowLevelCall ? "<abbr title='Performs Low-Level Calls'>โšก</abbr>":""}${totals.totals.capabilities.delegateCall ? "<abbr title='DelegateCall'>๐Ÿ‘ฅ</abbr>":""}${totals.totals.capabilities.hashFuncs ? "<abbr title='Uses Hash-Functions'>๐Ÿงฎ</abbr>":""}${totals.totals.capabilities.ecrecover ? "<abbr title='Handles Signatures: ecrecover'>๐Ÿ”–</abbr>":""}${totals.totals.capabilities.deploysContract ? "<abbr title='create/create2'>๐ŸŒ€</abbr>":""}${(doppelGanger !== undefined) && pathToDoppelganger && Object.keys(pathToDoppelganger).length ? "<abbr title='doppelganger'>๐Ÿ”†</abbr>":""}** |
${this.metrics.map(m => `| ${m.metrics.num.contracts ? "๐Ÿ“" : ""}${m.metrics.num.libraries ? "๐Ÿ“š" : ""}${m.metrics.num.interfaces ? "๐Ÿ”" : ""}${m.metrics.num.abstract ? "๐ŸŽจ" : ""} | ${m.filename.replace(this.basePath, "")} | ${(m.metrics.num.contracts + m.metrics.num.libraries + m.metrics.num.abstract) || "****"} | ${m.metrics.num.interfaces || "****"} | ${m.metrics.sloc.total || "****"} | ${m.metrics.nsloc.total || "****"} | ${m.metrics.nsloc.source || "****"} | ${m.metrics.sloc.comment || "****"} | ${m.metrics.complexity.perceivedNaiveScore || "****"} | **${m.metrics.capabilities.assembly ? "<abbr title='Uses Assembly'>๐Ÿ–ฅ</abbr>":""}${m.metrics.capabilities.experimental.length ? "<abbr title='Experimental Features'>๐Ÿงช</abbr>":""}${m.metrics.capabilities.canReceiveFunds ? "<abbr title='Payable Functions'>๐Ÿ’ฐ</abbr>":""}${m.metrics.capabilities.destroyable ? "<abbr title='Destroyable Contract'>๐Ÿ’ฃ</abbr>":""}${m.metrics.capabilities.explicitValueTransfer ? "<abbr title='Initiates ETH Value Transfer'>๐Ÿ“ค</abbr>":""}${m.metrics.capabilities.lowLevelCall ? "<abbr title='Performs Low-Level Calls'>โšก</abbr>":""}${m.metrics.capabilities.delegateCall ? "<abbr title='DelegateCall'>๐Ÿ‘ฅ</abbr>":""}${m.metrics.capabilities.hashFuncs ? "<abbr title='Uses Hash-Functions'>๐Ÿงฎ</abbr>":""}${m.metrics.capabilities.ecrecover ? "<abbr title='Handles Signatures: ecrecover'>๐Ÿ”–</abbr>":""}${m.metrics.capabilities.deploysContract ? "<abbr title='create/create2'>๐ŸŒ€</abbr>":""}${(doppelGanger !== undefined) && pathToDoppelganger && pathToDoppelganger[m.filename.replace(this.basePath, "")] ? "<abbr title='doppelganger("+pathToDoppelganger[m.filename.replace(this.basePath, "")].map(r => r.target.name).join(", ")+")'>๐Ÿ”†</abbr>":""}** |`).join("\n")}
| ${totals.totals.num.contracts ? "๐Ÿ“" : ""}${totals.totals.num.libraries ? "๐Ÿ“š" : ""}${totals.totals.num.interfaces ? "๐Ÿ”" : ""}${totals.totals.num.abstract ? "๐ŸŽจ" : ""} | **Totals** | **${(totals.totals.num.contracts + totals.totals.num.libraries + totals.totals.num.abstract) || ""}** | **${totals.totals.num.interfaces || ""}** | **${totals.totals.sloc.total}** | **${totals.totals.nsloc.total}** | **${totals.totals.nsloc.source}** | **${totals.totals.sloc.comment}** | **${totals.totals.complexity.perceivedNaiveScore}** | **${totals.totals.capabilities.assembly ? "<abbr title='Uses Assembly'>๐Ÿ–ฅ</abbr>":""}${totals.totals.capabilities.experimental.length ? "<abbr title='Experimental Features'>๐Ÿงช</abbr>":""}${totals.totals.capabilities.canReceiveFunds ? "<abbr title='Payable Functions'>๐Ÿ’ฐ</abbr>":""}${totals.totals.capabilities.destroyable ? "<abbr title='Destroyable Contract'>๐Ÿ’ฃ</abbr>":""}${totals.totals.capabilities.explicitValueTransfer ? "<abbr title='Initiates ETH Value Transfer'>๐Ÿ“ค</abbr>":""}${totals.totals.capabilities.lowLevelCall ? "<abbr title='Performs Low-Level Calls'>โšก</abbr>":""}${totals.totals.capabilities.delegateCall ? "<abbr title='DelegateCall'>๐Ÿ‘ฅ</abbr>":""}${totals.totals.capabilities.hashFuncs ? "<abbr title='Uses Hash-Functions'>๐Ÿงฎ</abbr>":""}${totals.totals.capabilities.ecrecover ? "<abbr title='Handles Signatures: ecrecover'>๐Ÿ”–</abbr>":""}${totals.totals.capabilities.deploysContract ? "<abbr title='create/create2'>๐ŸŒ€</abbr>":""}${(doppelGanger !== undefined) && pathToDoppelganger && Object.keys(pathToDoppelganger).length ? "<abbr title='doppelganger'>๐Ÿ”†</abbr>":""}** |
<sub>
Legend: <a onclick="toggleVisibility('table-legend', this)">[โž•]</a>
<div id="table-legend" style="display:none">
<ul>
<li> <b>Lines</b>: total lines of the source unit </li>
<li> <b>nLines</b>: normalized lines of the source unit (e.g. normalizes functions spanning multiple lines) </li>
<li> <b>nSLOC</b>: normalized source lines of code (only source-code lines; no comments, no blank lines) </li>
<li> <b>Comment Lines</b>: lines containing single or block comments </li>
<li> <b>Complexity Score</b>: a custom complexity score derived from code statements that are known to introduce code complexity (branches, loops, calls, external interfaces, ...) </li>
</ul>
</div>
</sub>
#### <span id=t-out-of-scope>Out of Scope</span>
Expand Down

0 comments on commit f8a28d7

Please sign in to comment.