How to delete all unused variables in WebStorm?
Asked Answered
C

2

6

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');
Cleodell answered 31/5, 2017 at 10:44 Comment(5)
That notation has nothing to do with ES5, it is CommonJS. What do you mean by "for es6 imports"? Do you want to replace them with the ES6 module syntax?Edholm
If you have Eslint correctly configured which includes no-unused-* you can easily using the fix command: blog.jetbrains.com/webstorm/2016/08/using-external-toolsLeffler
@Leffler that's a good idea. thanks.Cleodell
@Edholm No, I want to delete imports which aren't used. I have updated my question.Cleodell
no-unused-vars rule are not fixeble eslint.org/docs/rulesCleodell
D
9

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

Doss answered 31/5, 2017 at 12:55 Comment(0)
S
0

You can remove all unused imports in current file using

Ctrl + Alt + O

Sanskrit answered 31/5, 2024 at 15:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.