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');
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');
Share
Improve this question
edited May 31, 2017 at 13:31
Stanislav Mayorov
asked May 31, 2017 at 10:44
Stanislav MayorovStanislav Mayorov
4,4725 gold badges26 silver badges47 bronze badges
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? – str Commented May 31, 2017 at 10:49
-
3
If you have Eslint correctly configured which includes
no-unused-*
you can easily using the fix mand: blog.jetbrains./webstorm/2016/08/using-external-tools – Hitmands Commented May 31, 2017 at 11:05 - @Hitmands that's a good idea. thanks. – Stanislav Mayorov Commented May 31, 2017 at 11:10
- @str No, I want to delete imports which aren't used. I have updated my question. – Stanislav Mayorov Commented May 31, 2017 at 11:15
-
1
no-unused-vars
rule are not fixeble eslint/docs/rules – Stanislav Mayorov Commented Jul 8, 2017 at 19:28
2 Answers
Reset to default 9You can remove all unused variable in current file using quickfix:
- hit
Alt+Enter
on unused variable, hitRight
- Choose 'Fix all 'Unused JavaScript/ActionScript local symbol' problems in file'
If fixing the problem for each file individually is not an option for you, try using ESLint auto-fix per @Hitmands suggestion
You can remove all unused imports in current file using
Ctrl + Alt + O