Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
0.2.0 : show most used files
Browse files Browse the repository at this point in the history
  • Loading branch information
jehy committed May 10, 2019
1 parent edc705f commit 488742c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@
[![Known Vulnerabilities](https://snyk.io/test/github/jehy/require-analyse/badge.svg)](https://snyk.io/test/github/jehy/require-analyse)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/jehyrus)

Simple analyse of requires to find unused code.
Simple analyse of requires to find unused (dead) and most used code.

### Installation

Expand Down
15 changes: 14 additions & 1 deletion lib.js
Expand Up @@ -91,7 +91,11 @@ function analyse(argv) {
possiblePathes.forEach((possiblePath)=>{
const found = filePathes.find(({path: filePath2})=> filePath2 === possiblePath);
if (found) {
found.used = true;
if (!found.used) {
found.used = 1;
} else {
found.used++;
}
}
});
});
Expand All @@ -102,6 +106,15 @@ function analyse(argv) {
.map(({path: filePath2})=>filePath2);
// eslint-disable-next-line no-console
console.log(`\n\nNon used files (${nonUsed.length}):\n\n${nonUsed.join('\n')}`);
const mostUsed = filePathes
.filter(({used, path: filePath2})=>used && !ignoreFiles.some(ignoreFile=>filePath2.includes(ignoreFile)))
.sort((a, b)=>b.used - a.used)
.map(el=>({used: el.used, path: el.path}))
.slice(0, 20);
// eslint-disable-next-line no-console
console.log('\n\nMost used files:');
// eslint-disable-next-line no-console
console.log(mostUsed.map(el=>`${el.path} ${el.used}`).join('\n'));
}

module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -3,9 +3,12 @@
"bin": {
"analyse": "bin/analyse.js"
},
"version": "0.1.0",
"version": "0.2.0",
"description": "Analyse requires in node projects to detect dead code",
"keywords": ["require", "analyse"],
"keywords": [
"require",
"analyse"
],
"main": "lib.js",
"scripts": {
"test": "mocha --use_strict --exit",
Expand Down Expand Up @@ -40,6 +43,6 @@
"eslint-plugin-standard": "^4.0.0",
"istanbul": "~0.4.5",
"mocha": "^6.1.4",
"nyc": "^14.0.0"
"nyc": "^14.1.1"
}
}

0 comments on commit 488742c

Please sign in to comment.