Search code examples
javascriptphpstormwebstorm

How to delete all unused variables in WebStorm?


How to delete all unused variables in a project in WebStorm or other editor?

I have a lot of unused CommonJS imports like this. I'd like to remove them from my project.

var ReactDOM = require('react-dom');

Solution

  • You can remove all unused variable in current file using quickfix:

    • hit Alt+Enter on unused variable, hit Right
    • Choose 'Fix all 'Unused JavaScript/ActionScript local symbol' problems in file'

    enter image description here

    If fixing the problem for each file individually is not an option for you, try using ESLint auto-fix per @Hitmands suggestion