LoginSignup
21
23

VSCodeでJavaScript / TypeScirptの未使用import文を自動で削除する

Last updated at Posted at 2024-04-13

コードを書いてる途中、使わなくなったimport文をいちいち手動で消すのは面倒ですよね。それを自動で削除する方法をご紹介します。VSCodeに以下の設定をするだけです。

settings.json
{
  "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit"
  }
}

こうするとファイル保存時に未使用のimport文を削除し、さらにimport文の順番を並べ替えてくれます。順番はimport元のファイルパスをアルファベット順に並べているようですね。


指定できるキーはexplicit以外にもありますので、詳しくはドキュメントをご覧ください。


最後まで読んでいただき、ありがとうございました!

21
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
23