Search code examples
visual-studio-codedenodeno-fmt

How to format on save with the Deno VSCode extension?


I am using the vscode-deno extension and eventhough I turned on deno.enable, deno.lint and deno.unstable in my vscode settings, it does not format my code on save, which I suppose is the expected behavior.

I instead used the RunOnSave extension to hack my way into running a deno fmt on file save, but I was wondering if there was a way to do that with the Deno extension alone?

My .vscode/settings.json:

{
  "deno.enable": true,
  "deno.lint": true,
  "deno.unstable": true,
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.ts$",
        "cmd": "deno fmt ${file}"
      }
    ]
  }
}

Solution

  • Found it, I have to turn on formatting on save and specifying the Deno extension as the default formatter

    {
      "deno.enable": true,
      "editor.formatOnSave": true,
      "editor.defaultFormatter": "denoland.vscode-deno"
    }