1

I have a very large Nodejs application. There is a lot of unused dead code. I have been looking for a solution for this, but Im not able to find the proper tool.

I see there are many tools to check dead pieces of code or unreachable code in the own file (like https://www.npmjs.com/package/babel-plugin-minify-dead-code-elimination or ESLint). What I need is to cover examples like following one, that is most of my code: functions that are exported but never used from outside.

usefulFunctions.js

let self = {

  // This function is used from outside
  usedFunction: () => {
    console.log('This function is used from external file')
  },

  // This function is not used, but still exported. I need to detect it
  unusedFunction: () => {
    console.log('This function is not used')
  },
}

module.exports = self

app.js

const usefulFunctions= require('./usefulFunctions')

usefulFunctions.usedFunction()

What Ive tried:

Rashomon
  • 5,962
  • 4
  • 29
  • 67
  • I tried to find a solution with open source solutions but, after trying WebStorm, seems the only solution for this. – Rashomon Jan 18 '19 at 13:16
  • 1
    The problem with this is that CommonJS modules aren't well-suited for static analysis. It's usual practice to specify module name programmatically, such modules cannot be analyzed. In order to determine whether a piece of code is really used, it should be transformed to contain assertions. This is actually what code coverage does. Very large application isn't feasible without tests. Since unused code cannot physically get a coverage, this is how it can be determined. – Estus Flask Jan 18 '19 at 14:26

0 Answers0