1

Someone in my team uses vim, but the rest of us use VSCode's default formatter (i.e. vscode.typescript-language-features). I'd like to add a git precommit hook or something that invokes the formatter without opening up the app.

See also:

rioV8
  • 24,506
  • 3
  • 32
  • 49
Luke Miles
  • 941
  • 9
  • 19

2 Answers2

1

There is a great git hooks tool called Husky and its documentation can be found here.

Here is an example of it inside of a package.json file that uses pretty-quick to execute prettier whenever a git pre-commit is executed.

"husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged"
    }
  },
....

I find this method far superior to running prettier on every file save.

Dharman
  • 30,962
  • 25
  • 85
  • 135
A Webb
  • 633
  • 1
  • 8
  • 16
  • Do you know how to set it up with vscode's default formatter instead of prettier? – Luke Miles Jun 24 '21 at 19:41
  • I do not, however I would recommend using prettier because you can configure each project with different rules. While I assume that VS-Code's default formatter uses a global format for projects of the same type. – A Webb Jun 24 '21 at 20:06
1

As of July 2021, it seems vscode does not provide any way to run its formatter outside of the app itself

Luke Miles
  • 941
  • 9
  • 19